3

I have a form that submits to PHP self. This script runs and says it is successful, but I do not receive an email.

if(isset($_POST['name']) and isset($_POST['email']) and isset($_POST['phone'])) 

{
   //setup variables from input    
 $EMAIL = "[email protected]";    
 $inEmail = $_POST['email'];    
 $subject = "Enquiry from ".$POST['name'];   
 $name = $_POST['name'];   

 //setup message    
 $message = "Enquiry from: ".$name."\nEmail: ".$inEmail."\nPhone: ".$phone."\n\nDeparture Date: ".$departureDate."\n\nreturnDate: ".$returnDate;

 $message = wordwrap($message, 70);   


 //email enquiry details to site owner    
 if (mail($EMAIL, $subject, $message))    
 {    
  echo "Enquiry sent!";    
 } else    
 {
  echo "fail!";    
 }
?>

The "Enquiry sent" message does appear.

I have postfix installed and I have also tried with sendmail installed. I have scanned local host using nmap and the smtp port is open.

Can anyone see any reason that the mail does not sent.

3 Answers 3

3

Check your mail log (usually /var/log/maillog). It would show the message arriving from PHP, and any delivery attempts/rejection notices from the MX of the receiver.

Sign up to request clarification or add additional context in comments.

2 Comments

I have done this, at first it said there was an error as there was no sender, now it says status=deferred (delivery temporarily suspended: connect to alt4.gmail-smtp-in.l.google.com[74.125.67.27]:25: Connection timed out)
Temporarily suspended is either due to throttling, or google's using grey listing and expecting your server to retry again later. That means your code's working fine and PHP is delivery the mail properly, but something's acting to trigger anti-spam measures.
2

There a lot of possible reason that could explain why your email is sent and not received. Beside just setting up your SMTP server there are other things you need to do to make sure your email isn't just dropped before it reaches his destination.

You should take a look at this article that explains, what you should check :

http://www.codinghorror.com/blog/2010/04/so-youd-like-to-send-some-email-through-code.html

In summary you need to :

Comments

0

Assuming that sendmail is working on your system, and that PHP is configured to use it correctly, try adding -f in the additional parameters, like this...

mail($EMAIL, $subject, $message, '[email protected]'

This sets the envelope with a proper from address. See more on the PHP site: http://www.php.net/manual/en/function.mail.php#92528

1 Comment

+1 for the -f, but you'd want to include the normal additional headers 4th parameter first to include the normal From: address.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.