Reputation: 31637
Till yesterday below code was working. not sure, today below code is not working. I am not getting any email. Though, I am getting echo as right, but I am not getting any email.
$to = "[email protected]";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "[email protected]";
$headers = "From:" . $from;
if (mail($to, $subject, $message, $headers)) {
echo "right";
} else {
echo "wrong";
}
Any reason why this is happening?
I added print phpinfo();
and check for sendmail_path. I found below.
sendmail_path /usr/sbin/sendmail -t -i
It was server problem. Hence email was not getting sent.
Upvotes: 0
Views: 104
Reputation: 196
From what i understand the email is sent from the PHP mail() function. This function uses the local MTA to deliver the message.
If you have control over the server and its MTA you can start checking the logfiles of the server. There you should see the email from the PHP mail() function showing up. If this is not the case PHP seems to not pass it on to the MTA (in your case sendmail).
If it shows up in the logs, check the lines for more details. The reason can be in there. If you are not sure, post the log content (do not forget to mask private details of it).
But if it does not show any problems in the logs there could be a couple of other reasons. Like your IP to be blacklisted. To check that visit the following website http://mxtoolbox.com. But it would be possible as well that the receiving email server is bouncing the email back ... which would show up in the servers root inbox where you could see the return reason in it.
I hope that was helpfull for you!?
Upvotes: 1
Reputation: 4557
Some time mail() function may not work, so you should use PHPMailer, A well written documentation is written here :
rohitashv.wordpress.com/2013/01/19/how-to-send-mail-using-php/
Upvotes: 0
Reputation: 10506
To fix the problem in Ubuntu, Apache. You have to make sure that you have a mail sending software installed in your computer!
in ubuntu, open terminal and type the following command:
sudo apt-get install sendmail
after that try again!
Upvotes: 0
Reputation: 51
Try
$message = "test 1\r\ntest 2\r\ntest 3";
$message = wordwrap($message, 70, "\r\n");
mail([email protected]', 'My Subject', $message);
if this does not work check the php.ini
http://www.quackit.com/php/tutorial/php_mail_configuration.cfm
Upvotes: 0
Reputation: 1217
There is no PHP error here, it is a problem with your server setup. PHP will return true on mail() once the mail has been send off to sendmail, or whatever you are using. It does not know whether the email has actually been sent or not.
Upvotes: 0