This article mainly introduces the solution to the failure of mail sending using the mail function in php. It involves the configuration skills for the components related to the Linux operating platform and has some reference value. For more information, see
This article mainly introduces the solution to the failure of mail sending using the mail function in php. It involves the configuration skills for the components related to the Linux operating platform and has some reference value. For more information, see
This article describes how to solve the mail failure caused by the mail function in php. Share it with you for your reference. The specific analysis is as follows:
The mail function in php is a built-in function for sending mails, but if you really want to use the mail function to send mails, you must install the sendmail component on your system, now I have encountered the problem that mail cannot be sent. Let's take a look at the solution.
After the previous server was transferred, it was found that the website could not send an email via mail (), but sendmail was installed clearly. If sendmail is not installed, run the following code:
The Code is as follows:
Yum install sendmail
By the way, you must set a domain name format for the host name, for example, jb51.net. Otherwise, it will take a very long time to restart sendmail. Otherwise, it will take a long time. The Code is as follows:
The Code is as follows:
Hostname jb51.net
Check whether sendmail is running properly. The Code is as follows:
The Code is as follows:
Service sendmail status
If you do not run it, you can start it, change status to start, and then edit php. ini. You can create a phpinfo in the web environment, because I use lnmp.
The Code is as follows:
Vi/usr/local/php/etc/php. ini
Search again:; sendmail_path =, edit by I, replace:
The Code is as follows:
Sendmail_path =/usr/sbin/sendmail-t-I
My system defaults:
The Code is as follows:
Sendmail_path =/usr/sbin/sendmail-t-I-f
This-f seems to have disabled the mail function. After removing-f, the mail function returns to normal. Then, restart the PHP process, which is generally: service php restart LNMP is: service php-fpm restart, which can be: service httpd restart under Apache
I would like to share with you a php script test code. The Code is as follows:
The Code is as follows:
<? Php
$ Send = mail ('youremail @ lisizhang.com ', 'email title', 'test email content. If you receive this email, the mail function is enabled successfully! ');
If ($ send ){
Echo 'true ';
} Else {
Echo 'false ';
}
?>
If the returned result is false, the email fails to be sent. If the returned result is true, the email is successfully sent.
I hope this article will help you with php programming.