djs13 Posted April 14, 2011 Share Posted April 14, 2011 Hello! My name is DJ and I am new to PHP. Basically I designed a website with dreamweaver and on one of the pages I have a contact form. I used an internet tutorial to use php in order to finish the form. But now when someone submits their form, I don't receive an email and they just end up at a blank page. I don't understand why it's not working. Can you help me? <?php /* Subject and Email Variables */ $emailSubject = 'Sales Inquiry'; $webMaster = 'sales@endorsebro.com'; /* Gathering Data Variables */ $name = $_POST['name']; $business_name = $_POST['business_name']; $phone_number = $_POST['phone_number']; $Email = $_POST['Email']; $website = $_POST['website']; $state = $_POST['state']; $budget = $_POST['budget']; $comments = $_POST['comments']; $body = <<<EOD <br><hr><br> Name: $name <br> Business Name: $business_name <br> Phone Number: $phone_number <br> Email Address: $Email <br> Website: $website <br> State: $state <br> Budget: $budget <br> Comments: $comments <br> EOD; $headers = "From: $email\r\n"; $headers .= "Content-type: text/html\r\n"; $success = mail($webMaster, $emailSubject, $body, $headers); /* Results rendered as html */ $theResults = <<<EOD <html> <head> <title>Endorsebro</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <style type="text/css"> <!-- body { background-color: #f1f1f1; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; font-style: normal; line-height: normal; font-weight: normal; color: #666666; text-decoration: none; } --> </style> </head> <div> <div align="left">Thank you for your interest! We will be in contact soon!</div> </div> </body> </html> EOD; echo "$theResults"; ?> Thank you for your time. Quote Link to comment https://forums.phpfreaks.com/topic/233683-my-form-isnt-working/ Share on other sites More sharing options...
monkeytooth Posted April 14, 2011 Share Posted April 14, 2011 Well typically I would tell you your not making use of the mail() function. Secondly Im not a fan of the $body = EOV>>> concept.. so instead of breaking it down.. I'm just going to expedite your process.. As I have some canned code I use regularly for sites I build handy. Functions to make it work: <?php public function getRealIpAddr() { if(!empty($_SERVER['HTTP_CLIENT_IP'])) { $ip=$_SERVER['HTTP_CLIENT_IP']; } elseif(!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { $ip=$_SERVER['HTTP_X_FORWARDED_FOR']; } else { $ip=$_SERVER['REMOTE_ADDR']; }return $ip; } public function mailSomeone($toWho, $fromWho, $sysSubj, $sysMsg) { $msgTemplate = ' <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>'.$sysSubj.'</title> <style type="text/css"> background-color: #f1f1f1; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; font-style: normal; line-height: normal; font-weight: normal; color: #666666; text-decoration: none; </style> </head> <body> <table width="650" border="0" bgcolor="#FFF" id="wrapper"> <tr> <td align="center" valign="top">'.$sysMsg.'</td> </tr> </table> </body> </html>'; $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $headers .= 'Content-type: text/html; charset=us-ascii' . "\r\n"; $headers .= 'From:' .$fromWho. "\r\n"; $headers .= 'Reply-To: ' .$fromWho. "\r\n"; $headers .= '1\r\nX-MSMail-Priority: High' . "\r\n"; $headers .= 'X-Mailer: RiversHacia, LLC Mail Controller v2.0' . "\r\n"; mail($toWho, $sysSubj, $sysMsg, $headers); } ?> Concept of Useage, based off your original example. <?php if(!isset($_POST['name']))||(empty($_POST['name']))||(trim($_POST['name']) == ""){echo "Please Provide your Name.";} // just making sure something is posted with the form else{ $timeofMsg = date('m d, Y g:ia', time()); $ipOfPoster = getRealIpAddr(); $toWho = 'sales@endorsebro.com'; $fromWho = $_POST['Email']; $sysSubj = 'Sales Inquiry'; $sysMsg = " Name: $name <br> Business Name: $business_name <br> Phone Number: $phone_number <br> Email Address: $Email <br> Website: $website <br> State: $state <br> Budget: $budget <br> Comments: $comments <br> <br> <br> <br> Time/Date: timeofMsg <br> IP Posted: $ipOfPoster "; mailSomeone($toWho, $fromWho, $sysSubj, $sysMsg); } ?> enjoy, hope it helps! :-) Happy Coding Note: if your on GoDaddy for your hosting provider 1) consider switching. 2) Though I haven't had any issues with my method above with GoDaddy. GoDaddy itself has tendency sometimes to not like the mail() function. Quote Link to comment https://forums.phpfreaks.com/topic/233683-my-form-isnt-working/#findComment-1201447 Share on other sites More sharing options...
nethnet Posted April 14, 2011 Share Posted April 14, 2011 If nothing is being output to the browser, chances are there is an error occurring that is causing the script to die. Try turning on error reporting to see what exactly the issue is. Just put this line of code at the top of your page: error_reporting(-1); @monkeytooth - I've used GoDaddy to host one of my dedicated servers for about 7 years and I've never encountered any issues with mail() or other PHP problems that extended beyond a malconfiguration on my part. Quote Link to comment https://forums.phpfreaks.com/topic/233683-my-form-isnt-working/#findComment-1201457 Share on other sites More sharing options...
djs13 Posted April 14, 2011 Author Share Posted April 14, 2011 Well typically I would tell you your not making use of the mail() function. Secondly Im not a fan of the $body = EOV>>> concept.. so instead of breaking it down.. I'm just going to expedite your process.. As I have some canned code I use regularly for sites I build handy. Functions to make it work: <?php public function getRealIpAddr() { if(!empty($_SERVER['HTTP_CLIENT_IP'])) { $ip=$_SERVER['HTTP_CLIENT_IP']; } elseif(!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { $ip=$_SERVER['HTTP_X_FORWARDED_FOR']; } else { $ip=$_SERVER['REMOTE_ADDR']; }return $ip; } public function mailSomeone($toWho, $fromWho, $sysSubj, $sysMsg) { $msgTemplate = ' <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>'.$sysSubj.'</title> <style type="text/css"> background-color: #f1f1f1; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; font-style: normal; line-height: normal; font-weight: normal; color: #666666; text-decoration: none; </style> </head> <body> <table width="650" border="0" bgcolor="#FFF" id="wrapper"> <tr> <td align="center" valign="top">'.$sysMsg.'</td> </tr> </table> </body> </html>'; $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $headers .= 'Content-type: text/html; charset=us-ascii' . "\r\n"; $headers .= 'From:' .$fromWho. "\r\n"; $headers .= 'Reply-To: ' .$fromWho. "\r\n"; $headers .= '1\r\nX-MSMail-Priority: High' . "\r\n"; $headers .= 'X-Mailer: RiversHacia, LLC Mail Controller v2.0' . "\r\n"; mail($toWho, $sysSubj, $sysMsg, $headers); } ?> Concept of Useage, based off your original example. <?php if(!isset($_POST['name']))||(empty($_POST['name']))||(trim($_POST['name']) == ""){echo "Please Provide your Name.";} // just making sure something is posted with the form else{ $timeofMsg = date('m d, Y g:ia', time()); $ipOfPoster = getRealIpAddr(); $toWho = 'sales@endorsebro.com'; $fromWho = $_POST['Email']; $sysSubj = 'Sales Inquiry'; $sysMsg = " Name: $name <br> Business Name: $business_name <br> Phone Number: $phone_number <br> Email Address: $Email <br> Website: $website <br> State: $state <br> Budget: $budget <br> Comments: $comments <br> <br> <br> <br> Time/Date: timeofMsg <br> IP Posted: $ipOfPoster "; mailSomeone($toWho, $fromWho, $sysSubj, $sysMsg); } ?> enjoy, hope it helps! :-) Happy Coding Note: if your on GoDaddy for your hosting provider 1) consider switching. 2) Though I haven't had any issues with my method above with GoDaddy. GoDaddy itself has tendency sometimes to not like the mail() function. Wow, thank you for the help! I really appreciate it. I know I'm going to sound extremely inexperienced which is exactly what I am, but I have a question how to implement the code you've given me. As I said I'm using dreamweaver (I'm not sure if you're familiar with it) but basically my form is in an html document and then I wrote my php code in a seperate php document. Then made the call to action on the form to utilize the php code. But you've provided me with two php codes which has made me a bit confused. How exactly do I implement it? Again I apologize for the extremely beginner questions. Quote Link to comment https://forums.phpfreaks.com/topic/233683-my-form-isnt-working/#findComment-1201465 Share on other sites More sharing options...
monkeytooth Posted April 14, 2011 Share Posted April 14, 2011 essentially both bits of code can go in the same page. If you had a global functions file that you recycle code through then the first bit you'd put in there. But its not pertinant to its functionality to have it in a seperate file. All in all you would just need to make sure both bits are at the least in the same file. and the way I did it here is with the Concept of Useage part. Make it look for a Posted element from a form, with the name "name". So it wont trigger unless the form is posted with an element that matches that name. Of course you can change the element name in the code by changing the $_POST value to something else ie: $_POST['name'] to $_POST['email'] the part you change would be specific to the name="" part of the input your submitting from your form. Also both pieces of code can be put on the same page as the form or in a seperate page. Basicly where ever you're form action="" is pointed to you want to put it in that file. Quote Link to comment https://forums.phpfreaks.com/topic/233683-my-form-isnt-working/#findComment-1201726 Share on other sites More sharing options...
djs13 Posted April 14, 2011 Author Share Posted April 14, 2011 Thank you for clearing that up. I hate to be annoying and ask you another question, but if you don't mind I'm getting a syntax error on line 2 and 18 where it starts with "public function..." and on 58/59 where the if/else statement is. Do you know why this would be happening? <?php public function getRealIpAddr() { if(!empty($_SERVER['HTTP_CLIENT_IP'])) { $ip=$_SERVER['HTTP_CLIENT_IP']; } elseif(!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { $ip=$_SERVER['HTTP_X_FORWARDED_FOR']; } else { $ip=$_SERVER['REMOTE_ADDR']; }return $ip; } public function mailSomeone($toWho, $fromWho, $sysSubj, $sysMsg) { $msgTemplate = ' <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>'.$sysSubj.'</title> <style type="text/css"> background-color: #f1f1f1; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; font-style: normal; line-height: normal; font-weight: normal; color: #666666; text-decoration: none; </style> </head> <body> <table width="650" border="0" bgcolor="#FFF" id="wrapper"> <tr> <td align="center" valign="top">'.$sysMsg.'</td> </tr> </table> </body> </html>'; $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $headers .= 'Content-type: text/html; charset=us-ascii' . "\r\n"; $headers .= 'From:' .$fromWho. "\r\n"; $headers .= 'Reply-To: ' .$fromWho. "\r\n"; $headers .= '1\r\nX-MSMail-Priority: High' . "\r\n"; $headers .= 'X-Mailer: RiversHacia, LLC Mail Controller v2.0' . "\r\n"; mail($toWho, $sysSubj, $sysMsg, $headers); } ?> <?php if(!isset($_POST['name']))||(empty($_POST['name']))||(trim($_POST['name']) == ""){echo "Please Provide your Name.";} // just making sure something is posted with the form else{ $timeofMsg = date('m d, Y g:ia', time()); $ipOfPoster = getRealIpAddr(); $toWho = 'sales@endorsebro.com'; $fromWho = $_POST['Email']; $sysSubj = 'Sales Inquiry'; $sysMsg = " Name: $name <br> Business Name: $business_name <br> Phone Number: $phone_number <br> Email Address: $Email <br> Website: $website <br> State: $state <br> Budget: $budget <br> Comments: $comments <br> <br> <br> <br> Time/Date: timeofMsg <br> IP Posted: $ipOfPoster "; mailSomeone($toWho, $fromWho, $sysSubj, $sysMsg); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/233683-my-form-isnt-working/#findComment-1201753 Share on other sites More sharing options...
nethnet Posted April 14, 2011 Share Posted April 14, 2011 "public" is a keyword used in conjunction with class methods. Since these functions aren't part of a class, just get rid of the word "public" and it should work fine. Quote Link to comment https://forums.phpfreaks.com/topic/233683-my-form-isnt-working/#findComment-1201782 Share on other sites More sharing options...
djs13 Posted April 15, 2011 Author Share Posted April 15, 2011 Thank you that fixed my first issue. But I'm getting this error now: "Parse error: syntax error, unexpected T_BOOLEAN_OR in /homepages/9/d228392232/htdocs/Endorsebro/phpdoc.php on line 58" It's referring to the if/else statement that I have: <?php if(!isset($_POST['name']))||(empty($_POST['name']))||(trim($_POST['name']) == ""){echo "Please Provide your Name.";} // just making sure something is posted with the form else{ $timeofMsg = date('m d, Y g:ia', time()); $ipOfPoster = getRealIpAddr(); $toWho = 'sales@endorsebro.com'; $fromWho = $_POST['Email']; $sysSubj = 'Sales Inquiry'; $sysMsg = " Why is that not working? Quote Link to comment https://forums.phpfreaks.com/topic/233683-my-form-isnt-working/#findComment-1201858 Share on other sites More sharing options...
kenrbnsn Posted April 15, 2011 Share Posted April 15, 2011 You're missing the parenthesis that enclose the entire "if" condition: <?php if((!isset($_POST['name']))||(empty($_POST['name']))||(trim($_POST['name']) == "")){echo "Please Provide your Name.";} // just making sure something is posted with the form ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/233683-my-form-isnt-working/#findComment-1201876 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.