Mail function in PHP failed to send file resolution

Source: Internet
Author: User
Tags php script

Before that server transferred, found that the Web site with mail () sent to send mail. But found SendMail has been installed.

If SendMail is not installed, you can perform

The code is as follows Copy Code

Yum Install SendMail

Yes, the host name should be formatted with a domain name. For example: sangsir.com
Otherwise, it will take a long time to restart the sendmail. (otherwise it will be a long wait)

The code is as follows Copy Code
Hostname sangsir.com

Then see if SendMail is working properly.

The code is as follows Copy Code
Service SendMail Status

Can start if it is not running. Status replaced by Start
Immediately thereafter, the editor php.ini. You can create a phpinfo in a Web environment
Because I'm using a lnmp.

Vi/usr/local/php/etc/php.ini


And then find:

; Sendmail_path =


By I edit, replace with:

The code is as follows Copy Code
Sendmail_path =/usr/sbin/sendmail-t-I.

My system defaults to:

Sendmail_path =/usr/sbin/sendmail-t-i-f

This-F appears to have the mail function deactivated, and the mail function has been restored to normal after the-F has been removed.


Immediately thereafter, restart 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

<?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!

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.