My emails don't arrive for some reason.

Hello. I’m trying to send emails with the php mail function, but even though the function evaluates to true int he if statement, the emails never arrive. Below is the code for the form that receives the user input. I’ve changed my email address for privacy reasons:

<?php //start building the mail string $msg = "Name: ".$_POST['name']."\n"; $msg .= "E-Mail: ".$_POST['email']."\n"; $msg .= "Message: ".$_POST['message']."\n"; //set up the mail $recipient = "[email protected]"; $subject = "Form Submission Results"; $mailheaders = "From: My Web Site " . $email . "\n"; $mailheaders .= "Reply-To: ".$_POST['email']; //send the mail if(mail($recipient, $subject, $msg, $mailheaders)){ echo "The email was sent";} ?> Sending mail from the form in Listing 11.10

Thanks, <?php echo $_POST['name']; ?>, for your message.

Your e-mail address: <?php echo $_POST['email']; ?>

Your message:
<?php echo $_POST['message']; ?>

If anyone could link me to a great tutorial on email with php for beginners I would greatly appreciate it. Or, if you could help me out here that would be great as well.

Look in your php.ini file for your SMTP settings and see if they are correct.

Your php code is solid. The problem is probaby a problem with your web host. What is it?

You really need to use a php mailing library like phpmailer. You code is missing important headers that need to be sent. Honestly, I know a fair amount about email sending and the difficulties behind it. You will never have consistent delivery without using a bare minimum of a good php library. Even then you’re still subject to many more things that are harder to control.

Start with the library and make sure your email subject and content don’t resemble spam tags what so ever. Check your spam box also. If you never get them in your inbox or spam box, your web hosts server most likely marked them as spam cause they don’t have all the needed info to consider it legit.

If you want a ready to go contact form that uses ajax sending and phpmailer, you can download a full design from my website here http://amecms.com/article/Easy-to-use-contact-form-with-validation

Sponsor our Newsletter | Privacy Policy | Terms of Service