ched53 Posted March 2, 2009 Share Posted March 2, 2009 I'm having an absoloute nightmare trying to get an enquiry form to work on a website that I am designing. Firstly, let me point out I am a complete newbie with PHP so please pardon my ignorance on the subject, im a graphic designer not a programmer. The address for the page where the enquiry form is http://www.hairbykirbyblythe.co.uk/enquiries.html. So far I am at a point where clicking the submit button correctly goes to the 'Thanks for your message' page, but no email is being received at all. Can someone please tell me what is wrong with my code? This is the php on the enquiries page itself: <?php ini_set("sendmail_from", " kirby@hairbykirbyblythe.co.uk "); mail($email_to, $email_subject, $email_message, $headers, '-fkirby@hairbykiryblythe.co.uk'); ?> <?php ini_set('sendmail_from', $email_from); $email_to = "kirby@hairbykirbyblythe.co.uk"; $name =$_POST['Name']; $email_from =$_POST['email']; $email_subject = "Enquiry"; $comments = $_POST['message']; $headers = "From: $email_from .\n"; "Reply-To: $email_from .\n"; $message= "Name: ". $name . "\ntelephone: " . $telephone; "\nemail: " . $email; $sent = mail($email_to, $email_subject, $message, $headers, '-f .$email_from'); if ($sent) { header( "Location: http://www.hairbykirbyblythe.co.uk" ); } else { /* If there is an error display an error message */ echo 'There has been an error sending your enquiry. Please try later.'; } ?> And my sendmail.php file is as follows: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Untitled Document</title> </head> <body> <?php ini_set("sendmail_from", " [email]kirby@hairbykirbyblythe.co.uk[/email] "); mail($email_to, $email_subject, $email_message, $headers, '-fkirby@hairbykiryblythe.co.uk'); ?> <?php ini_set('sendmail_from', $email_from); $email_to = "kirby@hairbykirbyblythe.co.uk"; $name =$_POST['Name']; $email_from =$_POST['email']; $email_subject = "Enquiry"; $comments = $_POST['message']; $headers = "From: $email_from .\n"; "Reply-To: $email_from .\n"; $message= "Name: ". $name . "\ntelephone: " . $telephone; "\nemail: " . $email; $sent = mail($email_to, $email_subject, $message, $headers, '-f .$email_from'); if ($sent) { header( "Location: http://www.hairbykirbyblythe.co.uk/thanks.html" ); } else { /* If there is an error display an error message */ echo 'There has been an error sending your enquiry. Please try later.'; } ?> </body> </html> The host of the account is Fasthosts on a Windows home package if this helps. All help and advice would be much appreciated. I've had this issue for months now and just want to get it sorted Quote Link to comment https://forums.phpfreaks.com/topic/147583-enquiry-form-wont-send-to-email/ Share on other sites More sharing options...
gevans Posted March 2, 2009 Share Posted March 2, 2009 You're trying to run php on an html page. The html page is not getting parsed as php. Do a view source on the enquiries page and you can see all the php that was typed. Quote Link to comment https://forums.phpfreaks.com/topic/147583-enquiry-form-wont-send-to-email/#findComment-774743 Share on other sites More sharing options...
ched53 Posted March 2, 2009 Author Share Posted March 2, 2009 So do I need to remove all the HTML code from the sendmail.php file? like so??: <?php ini_set("sendmail_from", " kirby@hairbykirbyblythe.co.uk "); mail($email_to, $email_subject, $email_message, $headers, '-fkirby@hairbykiryblythe.co.uk'); ?> <?php ini_set('sendmail_from', $email_from); $email_to = "kirby@hairbykirbyblythe.co.uk"; $name =$_POST['Name']; $email_from =$_POST['email']; $email_subject = "Enquiry"; $comments = $_POST['message']; $headers = "From: $email_from .\n"; "Reply-To: $email_from .\n"; $message= "Name: ". $name . "\ntelephone: " . $telephone; "\nemail: " . $email; $sent = mail($email_to, $email_subject, $message, $headers, '-f .$email_from'); if ($sent) { header( "Location: http://www.hairbykirbyblythe.co.uk/thanks.html" ); } else { /* If there is an error display an error message */ echo 'There has been an error sending your enquiry. Please try later.'; } ?> as i said, my knowledge is next to none on this - i do apologise Quote Link to comment https://forums.phpfreaks.com/topic/147583-enquiry-form-wont-send-to-email/#findComment-774746 Share on other sites More sharing options...
gevans Posted March 2, 2009 Share Posted March 2, 2009 I haven't looked at sendmail.php yet I've looked at enquiries.html It needs to be parsed as php, so I'd start by simply renaming it to; enquiries.php You also have to change the URI's in the anchor tags to the page. Quote Link to comment https://forums.phpfreaks.com/topic/147583-enquiry-form-wont-send-to-email/#findComment-774752 Share on other sites More sharing options...
ched53 Posted March 2, 2009 Author Share Posted March 2, 2009 ok, I've renamed the file and now its looking like this ??? http://hairbykirbyblythe.co.uk/enquiries.php Quote Link to comment https://forums.phpfreaks.com/topic/147583-enquiry-form-wont-send-to-email/#findComment-774787 Share on other sites More sharing options...
Yesideez Posted March 2, 2009 Share Posted March 2, 2009 $headers = "From: $email_from .\n"; "Reply-To: $email_from .\n"; Shouldn't that be... $headers = "From: $email_from\r\nReply-To: $email_from\r\n"; Quote Link to comment https://forums.phpfreaks.com/topic/147583-enquiry-form-wont-send-to-email/#findComment-774791 Share on other sites More sharing options...
phant0m Posted March 2, 2009 Share Posted March 2, 2009 That doesn't look good, does it? Notice: Undefined variable: email_to in \\NAS43ENT\domains\h\hairbykirbyblythe.co.uk\user\htdocs\enquiries.php on line 55 Notice: Undefined variable: email_subject in \\NAS43ENT\domains\h\hairbykirbyblythe.co.uk\user\htdocs\enquiries.php on line 55 Notice: Undefined variable: email_message in \\NAS43ENT\domains\h\hairbykirbyblythe.co.uk\user\htdocs\enquiries.php on line 55 Notice: Undefined variable: headers in \\NAS43ENT\domains\h\hairbykirbyblythe.co.uk\user\htdocs\enquiries.php on line 55 Warning: mail() [function.mail]: SMTP server response: 503 5.5.2 Need Rcpt command. in \\NAS43ENT\domains\h\hairbykirbyblythe.co.uk\user\htdocs\enquiries.php on line 55 Notice: Undefined variable: email_from in \\NAS43ENT\domains\h\hairbykirbyblythe.co.uk\user\htdocs\enquiries.php on line 59 Notice: Undefined index: Name in \\NAS43ENT\domains\h\hairbykirbyblythe.co.uk\user\htdocs\enquiries.php on line 61 Notice: Undefined index: email in \\NAS43ENT\domains\h\hairbykirbyblythe.co.uk\user\htdocs\enquiries.php on line 62 Notice: Undefined index: message in \\NAS43ENT\domains\h\hairbykirbyblythe.co.uk\user\htdocs\enquiries.php on line 64 Notice: Undefined variable: telephone in \\NAS43ENT\domains\h\hairbykirbyblythe.co.uk\user\htdocs\enquiries.php on line 69 Notice: Undefined variable: email in \\NAS43ENT\domains\h\hairbykirbyblythe.co.uk\user\htdocs\enquiries.php on line 69 Warning: Cannot modify header information - headers already sent by (output started at \\NAS43ENT\domains\h\hairbykirbyblythe.co.uk\user\htdocs\enquiries.php:59) in \\NAS43ENT\domains\h\hairbykirbyblythe.co.uk\user\htdocs\enquiries.php on line 74 Well, your accessing these variables without initializing them. That might be the cause, but I can't really tell because there seems to be some code missing. <?php ini_set("sendmail_from", " kirby@hairbykirbyblythe.co.uk "); mail($email_to, $email_subject, $email_message, $headers, '-fkirby@hairbykiryblythe.co.uk'); ?> Quote Link to comment https://forums.phpfreaks.com/topic/147583-enquiry-form-wont-send-to-email/#findComment-774793 Share on other sites More sharing options...
Yesideez Posted March 2, 2009 Share Posted March 2, 2009 You've got strict mode turned on - if you don't have access to php.ini to turn it off add this at the start of the script immediately after <?php error_reporting(E_ALL ^ E_NOTICE); Quote Link to comment https://forums.phpfreaks.com/topic/147583-enquiry-form-wont-send-to-email/#findComment-774794 Share on other sites More sharing options...
premiso Posted March 2, 2009 Share Posted March 2, 2009 Or just test/define variables properly. The easy solution, put anything that requires the form to be posted inside of an if that checks if the form was posted. Quote Link to comment https://forums.phpfreaks.com/topic/147583-enquiry-form-wont-send-to-email/#findComment-774796 Share on other sites More sharing options...
phant0m Posted March 2, 2009 Share Posted March 2, 2009 You've got strict mode turned on - if you don't have access to php.ini to turn it off add this at the start of the script immediately after <?php error_reporting(E_ALL ^ E_NOTICE); but this only "cures" the symptoms Quote Link to comment https://forums.phpfreaks.com/topic/147583-enquiry-form-wont-send-to-email/#findComment-774798 Share on other sites More sharing options...
Yesideez Posted March 2, 2009 Share Posted March 2, 2009 Try this... <?php error_reporting(E_ALL ^ E_NOTICE); $email_to = "kirby@hairbykirbyblythe.co.uk"; $name =$_POST['Name']; $email_from =$_POST['email']; $email_subject = "Enquiry"; $comments = $_POST['message']; $headers ="From: $email_from\r\nReply-To: $email_from\r\n"; $message= "Name: ". $name . "\ntelephone: " . $telephone; "\nemail: " . $email; $sent = mail($email_to, $email_subject, $message, $headers); if ($sent) { header( "Location: http://www.hairbykirbyblythe.co.uk/thanks.html" ); } else { /* If there is an error display an error message */ echo 'There has been an error sending your enquiry. Please try later.'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/147583-enquiry-form-wont-send-to-email/#findComment-774799 Share on other sites More sharing options...
Yesideez Posted March 2, 2009 Share Posted March 2, 2009 You've got strict mode turned on - if you don't have access to php.ini to turn it off add this at the start of the script immediately after <?php error_reporting(E_ALL ^ E_NOTICE); but this only "cures" the symptoms There are no real serious symptoms here. All its saying is "these variables haven't been set" sort of thing. This is not serious and is nothing to worry about. The line I've specified to change the error reporting level will show anything that matters. Not many servers I've come across are set up as strict. Quote Link to comment https://forums.phpfreaks.com/topic/147583-enquiry-form-wont-send-to-email/#findComment-774800 Share on other sites More sharing options...
ched53 Posted March 3, 2009 Author Share Posted March 3, 2009 Ok, thanks Yesideez - it is now at least sending me an email - although its a blank email with just the field names in (its progress at least ) So here's where I'm at. The PHP on my enquiries (http://www.hairbykirbyblythe.co.uk/enquiries.php) page is: <?php ini_set("sendmail_from", " kirby@hairbykirbyblythe.co.uk "); mail($email_to, $email_subject, $email_message, $headers, '-fkirby@hairbykiryblythe.co.uk'); ?> <?php ini_set('sendmail_from', $email_from); $email_to = "kirby@hairbykirbyblythe.co.uk"; $name =$_POST['Name']; $email_from =$_POST['email']; $email_subject = "Enquiry"; $comments = $_POST['message']; $headers = "From: $email_from .\n"; "Reply-To: $email_from .\n"; $message= "Name: ". $name . "\ntelephone: " . $telephone . "\nemail: " . $email . "\nenquiry: " . $nenquiry; $sent = mail($email_to, $email_subject, $message, $headers, '-f .$email_from'); if ($sent) { header( "Location: http://www.hairbykirbyblythe.co.uk/thanks.html" ); } else { /* If there is an error display an error message */ echo 'There has been an error sending your enquiry. Please try later.'; } ?> and my sendmail.php is: <?php error_reporting(E_ALL ^ E_NOTICE); $email_to = "kirby@hairbykirbyblythe.co.uk"; $name =$_POST['Name']; $email_from =$_POST['email']; $email_subject = "Enquiry"; $comments = $_POST['message']; $headers ="From: $email_from\r\nReply-To: $email_from\r\n"; $message= "Name: ". $name . "\ntelephone: " . $telephone . "\nemail: " . $email . "\nenquiry: " . $nenquiry; $sent = mail($email_to, $email_subject, $message, $headers); if ($sent) { header( "Location: http://www.hairbykirbyblythe.co.uk/thanks.html" ); } else { /* If there is an error display an error message */ echo 'There has been an error sending your enquiry. Please try later.'; } ?> I'm sorry if it appears I haven't taken notice of what some people have said, thats not true - its just that I havent understood (as I said, I'm completely alien to all this). If you could just highlight the areas that are incorrect and let me know what I need to change them to I would be so grateful. Quote Link to comment https://forums.phpfreaks.com/topic/147583-enquiry-form-wont-send-to-email/#findComment-775342 Share on other sites More sharing options...
phant0m Posted March 3, 2009 Share Posted March 3, 2009 http://www.hairbykirbyblythe.co.uk/enquiries.php this is the form where you can enter a message mail etc.... When you click submit, it'll go to sendmail.php in order to actually send the email, right? Ok, that being so, we don't need any mail() commands(or any other of the php you posted) on enquiries.php. As for sendmail.php: The name attributes of the input fields have been set incorrectly! <label>Name:</label><p><input name="Name:" type="text" size="50" maxlength="50" /></p> <label>Telephone Number:</label> <p><input name="telephone" type="text" size="50" maxlength="20" /></p> <label>Email:</label><p><input name="email" type="text" size="50" maxlength="25" /></p> <label>Enquiry:</label><p><textarea name="enquiry" cols="90" rows="12"></textarea></p> should rather be: <label>Name:</label><p><input name="name" type="text" size="50" maxlength="50" /></p> <label>Telephone Number:</label> <p><input name="telephone" type="text" size="50" maxlength="20" /></p> <label>Email:</label><p><input name="email" type="text" size="50" maxlength="25" /></p> <label>Enquiry:</label><p><textarea name="message" cols="90" rows="12"></textarea></p> When you submit a form using the post method(that's what you do: <form action="sendmail.php" method="post">) - all the data from the form is collected in the array $_POST You can access the values again by using $_POST['nameOfTheFieldGoesHere'] This is how you tried to access the data: <?php $name =$_POST['Name']; $email_from =$_POST['email']; $email_subject = "Enquiry"; $comments = $_POST['message']; ?> As you can see, only 'email' matches the name specified in enquiries.php(name="email") I recommend you to name the input fields always in the same manner. This reduces the error rate. If you use this instead, it should work: <?php error_reporting(E_ALL ^ E_NOTICE); $email_to = "kirby@hairbykirbyblythe.co.uk"; $name = $_POST['name']; $email_from = $_POST['email']; $comments = $_POST['message']; $telephone = $_POST['telephone']; $email_subject = "Enquiry"; $headers = "From: $email_from\r\nReply-To: $email_from\r\n"; $message = "Name: " .$name ."\ntelephone: ".$telephone ."\nemail: " .$email ."\nenquiry: " .$comments; $sent = mail($email_to, $email_subject, $message, $headers); if ($sent) { header( "Location: http://www.hairbykirbyblythe.co.uk/thanks.html" ); } else { /* If there is an error display an error message */ echo 'There has been an error sending your enquiry. Please try later.'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/147583-enquiry-form-wont-send-to-email/#findComment-775358 Share on other sites More sharing options...
ched53 Posted March 3, 2009 Author Share Posted March 3, 2009 Thank you so much for your advice phant0m. Just one minor problem now, It's sending me the email with all the info from the form except the 'email' field is not sending the information any ideas? <?php error_reporting(E_ALL ^ E_NOTICE); $email_to = "kirby@hairbykirbyblythe.co.uk"; $name = $_POST['name']; $email_from = $_POST['email']; $comments = $_POST['message']; $telephone = $_POST['telephone']; $email_subject = "Enquiry"; $headers = "From: $email_from\r\nReply-To: $email_from\r\n"; $message = "Name: " .$name ."\ntelephone: ".$telephone ."\nemail: " .$email ."\nenquiry: " .$comments; $sent = mail($email_to, $email_subject, $message, $headers); if ($sent) { header( "Location: http://www.hairbykirbyblythe.co.uk/thanks.html" ); } else { /* If there is an error display an error message */ echo 'There has been an error sending your enquiry. Please try later.'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/147583-enquiry-form-wont-send-to-email/#findComment-775395 Share on other sites More sharing options...
Yesideez Posted March 3, 2009 Share Posted March 3, 2009 Just be sure to check that what variables you're populating by checking $_POST are defined in your form - they must match exactly otherwise the $_POST will always return empty. Quote Link to comment https://forums.phpfreaks.com/topic/147583-enquiry-form-wont-send-to-email/#findComment-775456 Share on other sites More sharing options...
phant0m Posted March 3, 2009 Share Posted March 3, 2009 ooops sorry just replace $email with $email_from and it should work Quote Link to comment https://forums.phpfreaks.com/topic/147583-enquiry-form-wont-send-to-email/#findComment-775463 Share on other sites More sharing options...
ched53 Posted March 3, 2009 Author Share Posted March 3, 2009 Thank you all so much for your help. This thing has been a nightmare for me as Im just a graphic designer. You've all been fantastic. just finally, is there a simple bit of code to put in that could just prompt the user if they were to enter an invalid email address? Quote Link to comment https://forums.phpfreaks.com/topic/147583-enquiry-form-wont-send-to-email/#findComment-775561 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.