Solution to mail failure in php using the mail function

Source: Internet
Author: User
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.

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: info-contact@alibabacloud.com 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.