JTCoder Posted February 10, 2010 Share Posted February 10, 2010 Hello, I am fairly new to PHP, and have just written some code to send from a simple form. However it is failing to send the information typed into the form. I have made sure to give each form field an ID, and have specified the matching ID as an index in the POST array. Once the form is submitted, the captcha utility verifies the text, then an if/else statement redirects to either an 'oops' page, or a 'submission successful' page. The PHP code on the 'submission successful' page then sends the info from the POST array to the specified email address using the mail() function. The code on the 'submission successful' page is as follows: <?php if(isset($_POST['submit'])) { $to = '[email protected]' ; //put your email address on which you want to receive the information $subject = 'Inquiry'; //set the subject of email. $headers = 'MIME-Version: 1.0' . "\r\n"; $headers = 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $message = "<table><tr><td>Your Name</td><td>".$_POST['name']."</td></tr> <tr><td>E-Mail</td><td>".$_POST['email']."</td></tr> <tr><td>Contact No</td><td>".$_POST['contact']."</td></tr> <tr><td>Message</td><td>".$_POST['message']."</td> </tr></table>" ; mail($to, $subject, $message, $headers); } ?> Thank you for your assistance. Jesse Quote Link to comment https://forums.phpfreaks.com/topic/191566-standard-mail-function-is-not-sending-email/ Share on other sites More sharing options...
alexjb Posted February 10, 2010 Share Posted February 10, 2010 Have you used the correct SMTP settings in php.ini? Quote Link to comment https://forums.phpfreaks.com/topic/191566-standard-mail-function-is-not-sending-email/#findComment-1009830 Share on other sites More sharing options...
teamatomic Posted February 10, 2010 Share Posted February 10, 2010 your headers var should look like $headers= $headers.= and you lack a From:[email protected] in the headers Fix that and it will send HTH Teamatomic Quote Link to comment https://forums.phpfreaks.com/topic/191566-standard-mail-function-is-not-sending-email/#findComment-1009847 Share on other sites More sharing options...
PFMaBiSmAd Posted February 10, 2010 Share Posted February 10, 2010 give each form field an ID You need to use name attributes. ID's only matter in the browser. Quote Link to comment https://forums.phpfreaks.com/topic/191566-standard-mail-function-is-not-sending-email/#findComment-1009850 Share on other sites More sharing options...
JTCoder Posted February 17, 2010 Author Share Posted February 17, 2010 Thank you for your responses; much appreciated. I have made the following corrections based on your responses and the PHP Manual, and am not receiving email. I checked the form, and the name attributes for each input tag are set. <?php if(isset($_POST['submit'])) { $to = '[email protected]' ; //put your email address on which you want to receive the information $subject = 'Thuris Media Enquiry'; //set the subject of email. $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $headers .= 'From: Test <[email protected]>' . "\r\n"; $message = "<table><tr><td>Your Name</td><td>".$_POST['name']."</td></tr> <tr><td>E-Mail</td><td>".$_POST['email']."</td></tr> <tr><td>Contact No</td><td>".$_POST['contact']."</td></tr> <tr><td>Message</td><td>".$_POST['message']."</td> </tr></table>" ; mail($to, $subject, $message, $headers); } ?> Thanks for your help, guys. Jesse Quote Link to comment https://forums.phpfreaks.com/topic/191566-standard-mail-function-is-not-sending-email/#findComment-1013509 Share on other sites More sharing options...
trq Posted February 17, 2010 Share Posted February 17, 2010 Again.... Have you used the correct SMTP settings in php.ini? Quote Link to comment https://forums.phpfreaks.com/topic/191566-standard-mail-function-is-not-sending-email/#findComment-1013514 Share on other sites More sharing options...
jl5501 Posted February 17, 2010 Share Posted February 17, 2010 Also you need to check with the host. Some hosts require that you have 'sendmail_from' set to a valid address in your domain either in the php.ini or with ini_set() in the script. Also these same hosts require the 5th parameter to mail() to be used as -f"[email protected]" which would contain the same email address as the sendmail_from. The only host I know requires this, is fasthosts in the UK, but could apply to others. Quote Link to comment https://forums.phpfreaks.com/topic/191566-standard-mail-function-is-not-sending-email/#findComment-1013594 Share on other sites More sharing options...
Deoctor Posted February 17, 2010 Share Posted February 17, 2010 have u checked whether the port that you are using is open in the server. check for port 25.. Quote Link to comment https://forums.phpfreaks.com/topic/191566-standard-mail-function-is-not-sending-email/#findComment-1013595 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.