PHP - Elementary Php Question Sendmail And Include Phone Field???
First off, I am new to PHP, and want to learn it, but it seems very complicated. Where do I begin?
I found a script online for a contact form and I am having trouble making it work for my needs. I wanted to include a phone number field in the email message. This is what I have so far for the PHP, but it does not include the phone field in the body of the message. Everything else works fine. Apologize in advance if this message has been posted many times before. <?php $post = (!empty($_POST)) ? true : false; if($post) { include 'functions.php'; $name = stripslashes($_POST['contactname']); $email = trim($_POST['email']); $subject = "New Message from your website"; $message = stripslashes($_POST['message']); $phone = stripslashes($_POST['phone']); $error = ''; // Check name if(!$name) { $error .= 'Please enter your name.<br />'; } // Check email if(!$email) { $error .= 'Please enter an e-mail address.<br />'; } if($email && !ValidateEmail($email)) { $error .= 'Please enter a valid e-mail address.<br />'; } // Check message (length) if(!$message || strlen($message) < 15) { $error .= "Please enter your message. It should have at least 15 characters.<br />"; } if(!$error) { $mail = mail(WEBMASTER_EMAIL, $subject, $message, "From: ".$name." <".$email.">\r\n" ."Reply-To: ".$email."\r\n" ."X-Mailer: PHP/" . phpversion()); if($mail) { echo 'OK'; } } else { echo '<div class="notification_error">'.$error.'</div>'; } } ?> Similar TutorialsThis topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=310894.0 hello, i cant find this anywhere on the internet. i dont even know what to search. if you are on your phone and there is a phone number on a web page, sometimes you can click on that number and it will dial it. how can i do that? Afternoon Freaks, I'm trying to add up certain variables inside an array, and keep going around in circles. The array is the result of a mysql SELECT query. I select the contents of a database table, then extract them in php using the following code: Code: [Select] while ( $row = mysql_fetch_assoc($result)) { extract($row); } var_dump($row) outputs the following: Quote Array ( [var1] => 1193 [var2] => 799 [var3] => 805 [var4] => 0.992547 [var5] => 2010-12-20 [var6] => 20 ) Array ( [var1] => 1193 [var2] => 725 [var3] => 725 [var4] => 1 [var5] => 2010-12-20 [var6] => 20 ) Array ( [var1] => 1193 [var2] => 818 [var3] => 850 [var4] => 0.962353 [var5] => 2010-12-20 [var6] => 20 ) Array ( [var1] => 1194 [var2] => 819 [var3] => 860 [var4] => 0.952326 [var5] => 2010-12-20 [var6] => 21 ) Array ( [var1] => 1194 [var2] => 829 [var3] => 870 [var4] => 0.952874 [var5] => 2010-12-20 [var6] => 21 ) Array ( [var1] => 1194 [var2] => 831 [var3] => 870 [var4] => 0.952874 [var5] => 2010-12-20 [var6] => 21 ) What I want is to add up all the var2 values for each var1. e.g., in the case of var1=1193, this would be 799 + 725+ 818. Of course, there are nearly 2,000 var1s (each one with multiple var2s), and I want my computer to do all the work. So I'm trying to isolate each var1 so I can figure out some loop to do this operation. I've tried a bunch of funny little tricks with min(), but keep going in circles. Any ideas? Just a quick question about including php files on a page... Let's say I have my index page that is a fully functioning page with all the <html>, <body>, and <head> tags where they should be. Now I want to include another file, which also has <html>, <body>, and <head> tags. Would this cause any problems or is it ok to include the second file as is? Hi I'm in a need of help here, I need to inluded this: "http://site.com/products.php?do=groups&groupid=2" in a a tpl file. Any way that this can be done? an example would be greatly appreciate it. cheers Any help is much appreciated in advance... I have a master file located along the root path that needs to be included in subdomains. Inside the master file are includes like Code: [Select] <?php include("../bodyCopy/anyfile.php"); ?> that need to reference the /bodyCopy directory IN THE SUBDOMAIN and NOT along the root. The problem that I'm having is that the master file resides OUTSIDE of the subdomain on the root (in a '/bodyCopy' directory. How do I write the PHP include so that files included in a subdomain from outside of the subdomain (on root) search directories INSIDE the subdomain and NOT relative to the root path? Here's what I mean. I have this file sitting on the root: /home/xxxx/public_html/constructfiles/filetoinclude.php It needs to be included he /home/xxxx/public_html/SUBDOMAIN/publicfile.php Then, 'filetoinclude.php' needs to include other files that are he /home/xxxx/public_html/SUBDOMAIN/bodyCopy/otherfilestoinclude.php ...but, 'filetoinclude.php' is searching along the root path for '/home/xxxx/public_html/bodyCopy/otherfilestoinclude.php' (which does not exist), and NOT within the SUBDOMAIN for the '/home/xxxx/public_html/SUBDOMAIN/bodyCopy/otherfilestoinclude.php' like I need it to. It appears that PHP will only search along the root path of the included file and NOT the root path of the file in which an include is included. I'm confusing myself now, but I hope someone can help. Thanks, Jet - Hello person who reads this now I work a lot with <?php include("..."); ?> and I never thought beyond the html I put in there. In 1 of the include files I have the set-up of a simple vertical html/css menu and on the right next to it I have an image. However, not every page on my website needs the same image and I probably will change a lot of them frequently. Now I was wondering if (and how) I could include a piece of PHP code which does the following: If the web-url is "page1.php" show "image1.png" If the web-url is "page2.php" show "image2.png" If the web-url is "page3.php" show "image3.png" etc. This way I only have to change the "imageX.png" in 1 file. I hope you can help me. Best regards and thanks in advance! Ferdri3 I'm a little confused with the use of absolute paths in PHP. I've always used relative paths but it's becoming an issue with some of the apps I'm working with and absolute would solve the problem. The thing is, I'm getting different results in different places and I'm a little confused. With regular HTML I seem to be able to use / as the root of my site. So if I do the following... Code: [Select] <img src="/images/name.jpg" /> That works fine no matter what page it's called from in the site and no matter what directory that page is in. I need to be able to do that same thing with PHP. Now, in my custom 404 page I have the following... Code: [Select] if($AddressURL == 'http://www.domain.com/blog/files/filename.zip') { header('HTTP/1.1 301 Moved Permanently'); header('Location: /download/filename.zip'); exit(); } That actually works just fine. If I go to the /blog/files/filename.zip (which doesn't exist) in a web browser it winds up downloading the file at www.domain.com/download/filename.zip as expected. Now where I get confused is that include files don't seem to work like that with PHP. If I do this... Code: [Select] require_once('/includes/config.php'); That winds up looking for an /includes folder all the way back at the local server root, not just the web root. so it's looking for /var/includes instead of /var/www/includes and of course that doesn't end up working. So, how come the include file paths work differently than regular HTML paths or header redirects in PHP? Is there any simple way I can always refer to the SITE root no matter what server it's running from? I've tried playing with $_SERVER['DOCUMENT_ROOT'] but it only seems to return the root of the current document, not the root of the whole site. So if I use it within a php file located in /var/www/includes/test.php it considers /includes the root which is not what I want. Any information would be greatly appreciated. Thanks! How can I use an include file that has a list of links in any directory at my website without breaking those links? You can see it in action here... The links in this directory work... https://www.billelgin.com/primary-directory/ The links in this directory (being created from the same include file) do not work... https://www.billelgin.com/primary-directory/subsection-one/ Obviously the problem is the include file is being called from different directories, so it's breaking the relative path links in the include file, but what can I do to fix it? You can download the example directory structure here... https://www.billelgin.com/EXAMPLE.zip Hello, Is this a sound explanation of require and include.. Lets say i have "X" application with an index.php file. in a folder on my domain like so: www.xxx.com/Application X folder/index.php. // the index.php calls to multiple files with-in the "Application X folder" and database. What if i move the index.php to another location all together like so: http://www.xxx.com/notXsubfolder1/notXsubfolder2/notXsubfolder3/index.php //the X application index file.. and then edit the require and include links in the index.php file to paths like this (just example might not be accurate): require_once '../../../../application X Folder/include/required_file.php'; My question:?? What i want to know is: if the required_file.php has includes of its own, will it take the includes that it requires from its original folder where the Required_file.php is located? or will its paths change the the new index.php location?? . I think this is a simple question, but I'm just starting out and can't figure out how to do this exactly. I'm making a demo site for a flower shop. The structure is as such (only listing the particular files in question - once this is done, the rest will be easy) index.php -> inc_show_colors.php -> showColors.php The index is to be standard through the site, loading include files into a main content area. Clicking on a link loads inc_by_color.php (index.php -> index.php?page=by_color ) From there, one of the four colors is selected. showColors.php contains switch statements for each color. I want to load showColors.php into the main content window when a color is selected, and I need to have it work for all four colors. I'm not sure how to do this, as you can't pass a variable to an include from what I understand. What's the easiest way to go about this? Keep in mind this is an intro class and "best practices" are not necessary yet, just the simplest solution to get it working. I want each of these colors to link to another include file, which will load in its place in index.php. index.php: Code: [Select] <div id="maincontent"> <?php if (isset($_GET['page'])) { switch ($_GET['page']) { case 'by_color': include('includes/inc_by_color.php'); break; case 'by_type': include('includes/inc_by_type.php'); break; case 'by_occasion': include('includes/inc_by_occasion.php'); break; case 'view_cart': include('includes/inc_view_cart.php'); break; case 'payment_options': include('includes/inc_payment_options.php'); break; case 'home_page': default: include('includes/inc_home.php'); break; } } else include('includes/inc_home.php'); ?> </div> inc_by_color.php: The first link I tried doing in the way I thought would work, but it doesn't. It can't find the include file. The second one works, kind of - but it just loads the page by itself, not into the maincontent div in index.php. Code: [Select] <h1>Flowers Categorized by Color</h1> <div class="picdivcontainer"> <div class="picdiv"><a href="index.php?page=red"><img src="images/image.png" width="90" height="90" alt="Red Flowers" /> <p>Red</a></p></div> <div class="picdiv"><a href="showColors.php?color=white"><img src="images/image.png" width="90" height="90" alt="White Flowers" /></a> <p><a href="showColors.php?color=white">White</a></p></div> </div> and showColors.php: Code: [Select] if (isset($_GET['color'])) { switch ($_GET['color']) { case 'red': $result = mysql_query("SELECT * FROM flowers WHERE color='red'") or die(mysql_error()); while($row = mysql_fetch_array( $result )) { // Set and trim strings and show the resulting flowers from query $flowername = $row['name']; $flowerimage = $row['image']; $image_path = "images/"; $flowername = str_replace('_', ' ', $flowername); $flowername = ucwords($flowername); ?> <div class="picdiv"><p><?php echo $flowername."<br />"; $flowerimage = str_replace(' ', '_', $flowerimage); echo "<img src='images/" . $row['image'] . "' />"; ?></p></div> <?php } break; I realize that showColors.php is probably a really messy way of doing this, but I just need to get it functioning ASAP for now. I am getting an error on a form which sends an email if the form is succesfull. I think there may ne an issue with the sendmail function. I am using a hosting company and not sure if sendmail is something that has to be enabled in the .ini file. Is there any way to check without getting the hosting company involved? The PHP code sends me an email from the server, but the user input is empty or "blank". I only receive: "From: \ Email: \ Subject: \ Message: " and that's it. How do I fix my PHP and/or HTML code to receive user input from the form? Attached is my existing HTML and PHP code that doesn't send me any "user input" from the form. Thanks to anyone who can help!!
This topic has been moved to Other Web Server Software. http://www.phpfreaks.com/forums/index.php?topic=359470.0 Hi, my webhost has the mail() function disabled. However, my emails are hosted in the offices sever and can't use smtp due to the firewall blocking it. How do I setup sendmail instead of the mail(). I tried googling this but keep coming across to the mail() functions. I wrote this code and I keep getting Parse error: syntax error, unexpected $end in the last line <?php $subject = 'Registration'; $fname = $_POST['fname']; $lname = $_POST['lname']; $address = $_POST['address']; $city = $_POST['city']; $state = $_POST['state']; $zip = $_POST['zip']; $phone = $_POST['phone']; $email = $_POST['email']; $mortgage = $_POST['mortgage']; $comments = $_POST['comments']; if($fname == ""){ echo 'Please fill out a First Name'; exit(); }elseif($lname == ""){ echo 'Please fill out a Last Name'; exit(); }elseif($address == ""){ echo 'Please fill out an Address'; exit(); }elseif($city == ""){ echo 'Please fill out a City'; exit(); }elseif($state == ""){ echo 'Please fill out a State'; exit(); }elseif($zip == ""){ echo 'Please fill out your Zip Code'; exit(); }elseif($phone == "") { echo 'Please fill out a Telephone Number'; exit(); }elseif($mortgage == "") { echo 'Please fill out a Mortgage Company'; exit(); }else{ $to = 'amphit@live.com'; $mailfrom = '$email'; $header = "from: $fname $lname <$mail_from>"; $detail = "First name - $fname <br> Last Name - $lname <br> Address - $address <br> City - $city <br> State - $state <br> Zip - $zip <br> Phone - $phone <br> Email - $email <br> Mortgage - $mortgage <br> Comments - $comments"; $send_mail=mail($to,$subject,$detail,$header); if($send_mail){ echo "We've recived your contact information"; } else { echo "ERROR"; } ?> Hi. I have two select fields one called category and the other sub category. Both are in the format. <select name="category" value=" <?php $qGetCat = "SELECT * FROM club_category" ; $rGetCat = mysql_query($qGetCat); while ($Cat = mysql_fetch_assoc($rGetCat)) { ?>" /> <option value="<?php echo $Cat['categorys'];?>"><?php echo $Cat['categorys']; ?></option> <?php } ?> </select> <select name="sub_category" value=" <?php $qGetSubCat = "SELECT * FROM sub_categorys" ; $rGetSubCat = mysql_query($qGetSubCat); while ($SubCat = mysql_fetch_assoc($rGetSubCat)) { ?>" /> <option value="<?php echo $SubCat['sub_categorys'];?>"><?php echo $SubCat['sub_categorys']; ?></option> <?php } ?> </select> Now I want to make it so that when a particular category is chosen for example self defence. The sub category when clicked shows all the self defence stuff. If watersports was chosen sub category would show things like swimming. What do I need to look up to do this? At the minute there is no link the way I have coded these to fields. In the database its self there is a; category table with categoryID and category_name sub category table with sub_cat_name and categoryID I think this will work but I have never done this so its making my head hurt just thinking about it. Does anyone have any advice, tuts or scripts to do this? Thank you Hello, I am using the Pear Mail and Mail_Mime packages to send SMTP authenticated HTML formatted emails. I was successfully sending emails when I started getting the following error: sendmail: 451 Internal Error I check out the sendmail logs at /var/log/mail.log but that only says the same thing. I am running Linux-Ubuntu and sending emails from an address on a remote server (godaddy hosted). The interesting thing is that this exact same code will run to completion and fail. Any thoughts? Anyone with Pear Mail experience, is there any way to end the SMTP session, maybe that is the problem. I also think an issue might be that the server thinks my IP is sending too many emails, any way to provision against that? Thanks for any insight and please let me know if other information might be helpful to debug this. Hi guys I'm seriously stressing hard about this. I seem to have written everything properly but my contact form just won't send an e-mail and update the status on my webpage. I fill out the details on my contact form and my status text stays on "Email is sending...". I'd REALLY REALLY appreciate any help you could toss my way. Thanks a ton! sendmail.php <?php $name = @trim(stripslashes($_POST['name'])); $from = @trim(stripslashes($_POST['email'])); $subject = @trim(stripslashes($_POST['subject'])); $message = @trim(stripslashes($_POST['message'])); $to = 'myemail@gmail.com';//replace with your email $headers = array(); $headers[] = "MIME-Version: 1.0"; $headers[] = "Content-type: text/plain; charset=iso-8859-1"; $headers[] = "From: {$name} <{$from}>"; $headers[] = "Reply-To: <{$from}>"; $headers[] = "Subject: {$subject}"; $headers[] = "X-Mailer: PHP/".phpversion(); mail($to, $subject, $message, $headers); die(); ?> main.js //Contact Form var form = $('#contact-form'); form.submit(function(event){ event.preventDefault(); var form_status = $('.form-status'); $.ajax({ url: $(this).attr('action'), beforeSend: function(){ form_status.find('.form-status-content').html('<p><i class="fa fa-spinner fa-spin"></i> Email is sending...</p>').fadeIn(); } }).done(function(data){ form_status.find('.form-status-content').html('<p class="text-success">Thank you for contact us. As early as possible we will contact you</p>').delay(3000).fadeOut(); }); }); contact.html <form class="form-horizontal" id="contact-form" role="form"> <div class="form-group form-status"> <div class="col-sm-offset-2 col-sm-6"> <div class="form-status-content"> </div> </div> </div> <div class="form-group"> <div class="col-sm-offset-2 col-sm-6"> <input type="text" name="name" class="form-control input-lg" placeholder="Name" required="required"> </div> </div> <div class="form-group"> <div class="col-sm-offset-2 col-sm-6"> <input type="email" name="email" class="form-control input-lg" placeholder="Email" required="required"> </div> </div> <div class="form-group"> <div class="col-sm-offset-2 col-sm-6"> <input type="text" name="subject" class="form-control input-lg" placeholder="Subject" required="required"> </div> </div> <div class="form-group"> <div class="col-sm-offset-2 col-sm-8"> <textarea name="message" rows="6" class="form-control input-lg" placeholder="Message" required="required"> </textarea> </div> </div> <div class="form-group"> <div class="col-sm-offset-2 col-sm-8"> <button type="submit" class="btn btn-lg btn-transparent">Submit</button> </div> </div> </form> Edited February 27, 2020 by g0dtier Hi I am having a problem with the code below I am using to send a simple php email form. I am not that advanced with php but I want to add a drop down menu to a form I created and not sure how to get get the message (warning not completed) in the field - if(empty($visitortitle)) { - to accept or not to accept? This is the code in the form: <td align="left"><select name="visitortitle"> <option>Please Select</option> <option>Mr</option> <option>Mrs</option> <option>Miss</option> <option>Ms</option> <option>Dr</option> </select> This is the code I have got in the sendemail: if(empty($visitortitle)) { echo "<h2><br /><br /><br /><br />Please hit the back button and enter the title drop down box correctly<br />before you try submitting the form again.</h2>\n"; die ( '<a href="forum.html">click here go back and try again</a>' ); } How can I get this code to recognise that a <option></option> has been selected? Any help would be appreciated. Thanks Gary |