Friday, 25 November 2016

email - PHP 7 Mail() not working





I have read I believe every post on here related to this. I have a feeling that this is Linux file rights related, but not to sure. My environment is a test Centos7 box running Apache 2.4 and Php7 with phpMyAdmin etc. I can send mail using the sendmail somename@domain.com. I have tested this.
In my php.ini file(s) I have "sendmail_path = /usr/sbin/sendmail -t -i;"



$to = "Jesse.---@-----------.com";
$subject = "My subject";
$txt = "Hello world!";

$headers = "From: webmaster@example.com" . "\r\n" .
"CC: somebodyelse@example.com";
$mail = mail($to,$subject,$txt,$headers); //I have tried with no headers as well.


The mail function returns a false.


Answer



This problem can have so many reasons, that's why I am not using mail() anymore, I use PHPMailer with an external SMTP (GMAIL for example), but if you still want to use mail(), make sure that Sendmail, Exim or Postfix is installed on your server.



Test the mail() on the terminal first, if you can send on terminal, the problem may be some configuration on the php.ini, if the message fails on the terminal, you need to check the Postfix / Sendmail / Exim logs for the error message.




Make sure with your server provider too, if you are authorized to use mail(). Some servers block this function due to spam, and they require manual authorization.


No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...