How can I use email to send emails under Linux lnmp?

  
                

After the Linux system is configured with the lnmp environment, there is a problem that the mail function cannot send mail. How to solve this problem? In fact, there are two ways, one is to use the sendmail component, but to use postfix, the specific with the small series to understand it.

a method of using a mail to sendmail component

1. sendmail component mounting

yum install sendmail

2. Use the following command Restart php-fpm process

/etc/init.d/php-fpm restart

3. Check if sendmail is working properly

/etc/init.d/sendmail status

If you show that running is running.

Commands that may be used

/etc/init.d/sendmail start (starts sendmail)

/etc/init.d/sendmail stop (closes sendmail)< Br>

/etc/init.d/sendmail restart (restart sendmail)

4. Configure php.ini, fill in the absolute path of sendmail

Open the edit php.ini using the command< Br>

vi /usr/local/php/etc/php.ini

Enter? Sendmail_path find the location (or manually jump to find sendmail_path), you will find the default is the following code

; sendmail_path =

Press i to enter the edit, modify this line to

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

Press Esc to quit editing, type:wq to save and exit

5. Restart php-fpm process

/etc/init.d/php-fpm restart

This is a success. If you don't worry, create a new php file named mail.php, you can use the following code to test it.

"? Php

$txt = “hello,you are a good boy! ”;

//Change the following email address to your

$mail = ‘[email protected]’;

//send mail

mail($mail, “My subject”, $txt);

echo ‘message was sent! ’;

? 》

Save and upload to your website root directory and run it in your browser:

http://your URL/mail.php

When is your time? The mailbox should be able to receive the mail, but basically in the spam, pay attention to check, if you can not receive the mail, check the normal operation process, there is a restart of sendmail or restart php. In general, you will receive your mail normally.

Of course, the function is implemented, but when tested with the above test code, it is found that sending a message successfully is very slow and slow, it takes dozens of seconds or even a minute. Then I posted or replied to the comments on the blog, which was unusually slow, exceeding the psychological deadline for the user to wait. It is imperative to optimize this efficiency, otherwise it can only be cut off.

There are many online methods. Modifying this file is a modification of the file. It feels more troublesome, so I found the least modified operation and then succeeded.

Modify /etc/hosts, before modification

127.0.0.1 localhost.localdomain localhost

Modify to

127.0.0.1 localhost.localdomain localhost Host Name

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

Restart the sendmail after completing the modification

service sendmail restart
2 pages

Copyright © Windows knowledge All Rights Reserved