LNMP Mail function cannot send message 2 solutions

Source: Internet
Author: User
Tags fpm ini

Method One, use the SendMail component to send the message

1. Install SendMail components

Yum Install SendMail

2. Restart the PHP-FPM process using the following command

/ETC/INIT.D/PHP-FPM restart

3. Detect whether the SendMail is running normally

/etc/init.d/sendmail status

If the display is running running can be.

The command that might be used

/etc/init.d/sendmail start (Start SendMail)
/etc/init.d/sendmail Stop (Close sendmail)
/etc/init.d/sendmail Restart (reboot sendmail)

4. Configure php.ini, fill in the SendMail absolute path

Open edit php.ini with command

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

Input? Sendmail_path find positioning (or manually jump to find Sendmail_path), you will find that the default is the following code

; Sendmail_path =

Press I into the editor, change this line to

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

Press ESC to exit edit, enter: Wq Save exit

5. Restart the PHP-FPM process

/ETC/INIT.D/PHP-FPM restart

This is successful, if not at ease, create a new php file, named mail.php, you can use the following code test.

<?php

$txt = "Hello,you are a good boy!";

The following email address is changed to your

$mail = ' somebody@example.com ';

Send mail

Mail ($mail, "My subject", $txt);

Echo ' message was sent! ';

?>
Save and upload to your site's root directory and run it in the browser:

http://your website/mail.php

Then your mailbox should be able to receive mail, but basically in the spam, pay attention to see, if you do not receive the message, check the operation process is normal, there are wood restart SendMail or restart PHP. Generally, you can receive the mail normally.

Of course, the function is implemented, but with the above test code test, found that a successful e-mail message is slow and slow, it takes several 10 seconds or even a minute. Then I post or respond to comments in the blog is also unusually slow, more than the user waiting for the psychological period. Optimization of this efficiency is imperative, or you can only cut off this function.

A lot of online methods, modify the file is to modify the file, feel more trouble, so find a minimal operation of the modification, and then succeeded.

Modify/etc/hosts, before modification

127.0.0.1 localhost.localdomain localhost

Modified into

127.0.0.1 localhost.localdomain localhost host name

The command to view the host name of this computer is: hostname

Restart SendMail after completing the modification

Service SendMail Restart

Sincerely, comment and return to a few seconds to complete the publication of success. When you comment on the time to look at a slower than slow, at the same time can receive comments to reply to the email, thank you.

This article refers to LNMP notes: Troubleshooting mail functions that do not send mail and solve SendMail startup slow problem article content.

Method Two, if you do not need to sendmail you can try to use Postfix to send mail


Since the use of the LNMP environment of military brother, Lnmp mail function can not send mail the problem is still present, here, I do not recommend that you use SendMail as a letter, the reason is inefficient, slow, so, a come up to have him unloaded, here I directly said the tutorial, not ink!

Yum Remove SendMail

And then began to install Postfix, which is relatively high efficiency with sendmail, write faster, occupy low memory, can be said to be the current server to send the first choice, of course, there are many great God will say SMTP is also good, that is true, but personal hobbies, I like the simple server letter!

Install Postfix

Yum install Postfix

Change the default MTA to Postfix:

/usr/sbin/alternatives--set Mta/usr/sbin/sendmail.postfix

After that, check again to see if the MTA is changed to Postfix:

Alternatives--display MTA

Configure Postfix,vi Edit MAIN.CF

Vi/etc/postfix/main.cf

After opening, find the following items, remove the # in front of it, and do the configuration:

Myhostname = mail.2zzt.com
MyDomain = 2zzt.com
Myorigin = $mydomain
Inet_interfaces = All
mydestination = $myhostname, localhost $mydomain, localhost, $mydomain
Mynetworks = 192.168.100.10/28, 127.0.0.0/8
Relay_domains =
Home_mailbox = maildir/

Here I will give a complete file of MAIN.CF, the province of the people to change the wrong, we simply main.cf file in the 2zzt.com to replace your own domain name can be OK

Do not like the VI online editing, you can directly download MAIN.CF upload to the server/etc/postfix/main.cf to replace it

Detect and start postfix

Service Postfix Status

If it is not started, execute the following command:

Service Postfix start

Setting up Boot

Chkconfig Postfix on

To this step postfix is OK, but we still get php.in sendmail under the absolute path of configuration!

Open edit php.ini with command

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

Input? Sendmail_path find positioning (or manually jump to find Sendmail_path), you will find that the default is the following code

; Sendmail_path =

Press I into the editor, change this line to

Sendmail_path =/usr/sbin/sendmail-t-I.

Press ESC to exit edit, enter: Wq Save exit

Restart the PHP-FPM process

/ETC/INIT.D/PHP-FPM restart

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.