The example in this article describes a workaround for mail functions in PHP that failed to send messages. Share to everyone for your reference. The specific analysis is as follows:
The Mail function in PHP is a self-contained function, but if you really want to use the Mail function to send an email it must be to give you the system to install the SendMail components, the following I encountered Mail can not send the problem, the following a look at the solution bar.
Before that server transfer, found that the site with mail () sent Mail can not send, but found SendMail has been installed, if not installed SendMail can be executed, the code is as follows:
Copy Code code as follows:
By the way, the host name to set a domain name format, such as: jb51.net, otherwise restart the sendmail will be very long to start up, or to wait a long time, the code is as follows:
Copy Code code as follows:
Then see if SendMail is working correctly, and the code is as follows:
Copy Code code as follows:
If it is not running, the status is changed to start, and then, edit php.ini, you can create a phpinfo in the Web environment, because I use LNMP.
Copy Code code as follows:
Vi/usr/local/php/etc/php.ini
Re-find:; Sendmail_path =, press I edit, replace with:
Copy Code code as follows:
Sendmail_path =/usr/sbin/sendmail-t-I.
My system defaults to:
Copy Code code as follows:
Sendmail_path =/usr/sbin/sendmail-t-i-f
This-F seems to be the mail function deactivated, remove-F after the mail function work back to normal, followed by restarting the PHP process, generally: Service php restart LNMP is: Service php-fpm Restart,apache can: Service httpd Restart
To share a PHP script test code, the code is as follows:
Copy Code code as follows:
<?php
$send = Mail (' yourEmail@lisizhang.com ', ' message header ', ' test message content, if received, indicates mail function successfully enabled! ');
if ($send) {
Echo ' true ';
}else{
echo ' false ';
}
?>
If the return result false indicates that the message sent failed, if TRUE indicates that the message was sent successfully.
I hope this article will help you with your PHP program design.