Reputation: 141
I am trying to use the php mail()
function on my server. Weirdly, it returns true but I do not receive anything in my email inbox.
Yet the cpanel email forwarder is working fine.
So prolly it's not a configuration thing since the forwarder sends me emails?
I tried adding in:
ini_set("sendmail_from", "[email protected]");
But that didn't work.
Here's my code:
$subject = "My Subject";
$body = "Email Body ";
$headers = 'From: [email protected]' . "\r\n" .
'Reply-To: [email protected]' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
if (mail($email,$subject,$body,$headers))
echo "Sent!";
else
echo "Fail!";
Upvotes: 14
Views: 11166
Reputation: 1
In my case, changing server settings from IPv6 addresses to IPv4 addresses solved the problem.
Upvotes: 0
Reputation: 3864
Check your mail.log after sending a test email:
sudo tail -f /var/log/mail.log
Then you can see the ID assigned to the last email you tried to send. E.g. I see:
Jan 11 23:03:14 vagrant-ubuntu-trusty-64 postfix/pickup[17228]: 69F3441529: uid=33 from=<www-data>
69F3441529 is the unique id assigned to that email. You can then grep the log for all lines that have that ID...
sudo grep 69F3441529 /var/log/mail.log
You should then be able to spot any error message that may be present, and then Google them :)
Upvotes: 1
Reputation: 28936
There are a myriad of reasons that could cause this problem. Here are a few:
mail()
returns true when the outgoing mail server accepts the message for delivery. You will need to troubleshoot the other possibilities to find the point of failure.
Upvotes: 6
Reputation: 1106
We faced the exact same issue. The solution was in php.ini set the appropriate sendmail_path.
sendmail_path = "/usr/sbin/sendmail -t -i"
Setting the above solved the issue.
Upvotes: 1
Reputation: 168853
The mail()
function very rarely returns anything other than true
. It only cares about the fact that it's successfully given the email to the MTA (Mail Transfer Agent - ie the program that actually sends it).
The MTA will only reject an email immediately if it is badly formed. In this case, you'll get an error in PHP. But it can also reject an email or fail to send after it has accepted it from PHP, for a variety of reasons, non of which PHP will have any idea about because it has already received it's true
response.
Your MTA will have an error log which you can examine for more information if the error is occurring locally.
Upvotes: 4
Reputation: 10495
I had this problem with a script that I was using that was sending from and receiving at the same domain. Have you tried sending the email to an email address the resides on a different domain? This might help narrow down the possible issues.
Upvotes: 1