PHP mail function is not working
I've configured a server and it works fine, however, php mail function is not working. Could you please describe further steps for solving this issue?
Should I install SMTP server or something else?
Thank you in advance.
3 Replies
While I personally don’t have much experience with PHP and the php mail() function, doing some quick digging around, I was able to find what seems to be a helpful guide on testing and fixing the php mail() function:
How to Test and Fix the php mail() Function
I hope this helps point you in the right direction. Feel free to update this Community post with any additional information that may be useful for other Community members to assist you with this.
This is another case. I did a lot to find the solution, but it seems that need to discover deeper.
What I already did:
created the log file - phpmail.log and according to this file, error connected to headers:
[08-May-2018 18:46:55 UTC] mail() on [/var/www/html/path…:7]: To: your@email.address -- Headers:
Kinda late for this reply, but having the same problem earlier.
Searched for solution and found this thread.
I'm using CentOS 7.x and PHP is not sending email via browser (apache) user but when using terminal (sudoer) executing "php sendmail.php" where sendmail.php
is a test php script that has a simple code:
<?php
mail($recipient, $subject, $body);
Step1 - check /var/log/maillog
$ sudo tail -n 100 maillog
you might see something like:
NOQUEUE: SYSERR(apache): /etc/mail/sendmail.cf: line 0: cannot open: Permission denied
means (apache) user/group doesn't have permission to the sendmail binary and can't access the sendmail config file.
Step 2 - check SElinux config
$ sudo getsebool -a | grep mail
result:
gitosis_can_sendmail --> off
httpd_can_sendmail --> off
logging_syslogd_can_sendmail --> off
logwatch_can_network_connect_mail --> off
mailman_use_fusefs --> off
postfix_local_write_mail_spool --> on
Step 3 - enable sendmail for httpd (apache)
$ sudo setsebool -P httpd_can_sendmail on
$ sudo getsebool -a | grep mail
gitosis_can_sendmail --> off
httpd_can_sendmail --> on
logging_syslogd_can_sendmail --> off
logwatch_can_network_connect_mail --> off
mailman_use_fusefs --> off
postfix_local_write_mail_spool --> on
Try again the php file and access via browser… it should now send the email to the recipient. You might wanna check your SPAM folder though :)
Hope it helps.