Reputation: 10081
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.
Upvotes: 3
Views: 9909
Reputation: 360682
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.
Upvotes: 3
Reputation: 11134
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 :
Upvotes: 2
Reputation: 163240
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
Upvotes: 0