The Mail function in PHP failed to send a message solution _php tips

Source: Internet
Author: User
Tags php script

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:
Yum Install SendMail

By the way, the host name to set a domain name format, such as:, 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:
Service SendMail Status

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:

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:
$send = Mail (' ', ' message header ', ' test message content, if received, indicates mail function successfully enabled! ');
if ($send) {
Echo ' true ';
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.