In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "the solution that cannot use mail to send email under Linux lnmp". In the daily operation, I believe that many people have doubts about the solution that many people can not use mail to send email under Linux lnmp. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubt that "you can't use mail to send email under Linux lnmp". Next, please follow the editor to study!
After configuring the lnmp environment, the Linux system has the problem that the mail function can not send e-mail. How to solve this problem? In fact, there are two ways, one is to use sendmail components, but to use postfix, specific with the editor to learn about it.
Method one, use the sendmail component to send mail
1. Install sendmail components
Yum install sendmail
two。 Restart the php-fpm process using the following command
/ etc/init.d/php-fpm restart
3. Check whether sendmail is running properly
/ etc/init.d/sendmail status
If it shows that running is running, it is OK.
Commands that may be used
/ etc/init.d/sendmail start (start sendmail)
/ etc/init.d/sendmail stop (close sendmail)
/ etc/init.d/sendmail restart (restart Sendmail)
4. Configure php.ini and fill in the absolute path of sendmail
Use the command to open and edit php.ini
Vi / usr/local/php/etc/php.ini
Input? Sendmail_path search location (or manually jump to find sendmail_path), you will find that the default is the following code
; sendmail_path =
Press I to enter the edit and change the line to
Sendmail_path = / usr/sbin/sendmail-t-I
Press Esc to exit editing, enter: wq save exit
5. Restart the php-fpm process
/ etc/init.d/php-fpm restart
This is a success. If you are not assured, create a new php file and name it mail.php. You can test it using the following code.
"? Php
$txt = "hello,you are a good boy!"
/ / change the following email address to yours
$mail = 'somebody@example.com'
/ / send email
Mail ($mail, "My subject", $txt)
Echo 'message was sentencing'
? "
Save and upload to the root of your website and run it in the browser:
Http:// your URL / mail.php
At that time, your mailbox should be able to receive e-mail, but basically in spam, pay attention to check, if you can not receive email, check to see if it is normal during the operation, whether to restart sendmail or restart php. Generally speaking, you can receive e-mail normally.
Of course, the function is implemented, but when testing with the above test code, it is found that it takes dozens of seconds or even a minute to successfully send an email. Then I post or respond to comments on my blog is also unusually slow, exceeding the psychological period for users to wait. It is imperative to optimize this efficiency, otherwise this function can only be cut off.
There are many online methods, modify this file is to modify that file, feel more troublesome, so find a modification with the least operation, and then succeed.
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 sendmail after completing the modification
Service sendmail restart
Second, if you don't use sendmail, you can try to use postfix to send email.
Since the installation of the lnmp environment, there is still a problem that the mail function under lnmp cannot send email. Here, I do not recommend you to use sendmail as a message, because it is inefficient and slow.
Yum remove sendmail
Then began to install Postfix, which is much more efficient than sendmail, fast sending letters, low memory, can be said to be the current server to send letters first choice, of course, there are many gods will say that smtp is also good, that is right, but personal hobbies, I like the server to send letters simple!
Install Postfix
Yum install postfix
Change the default MTA to Postfix:
/ usr/sbin/alternatives-- set mta / usr/sbin/sendmail.postfix
When you're done, check again to see if you've changed MTA to Postfix:
Alternatives-display mta
Configure Postfix,vi to edit main.cf
Vi / etc/postfix/main.cf
After opening it, find the following items, remove the # in front of them, and configure them:
Myhostname = mail.2zzt.com
Mydomain = 2zzt.com
Myorigin = $mydomain
Inet_interfaces = all
Mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
Mynetworks = 192.168.100.10swap 28, 127.0.0.0swap 8
Relay_domains =
Home_mailbox = Maildir/
If you don't like vi online editing, you can download main.cf and upload it to the server's / 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
Set up boot boot
Chkconfig postfix on
Postfix can be regarded as OK at this point, but we still get the absolute path of sendmail configured in php.in!
Use the command to open and edit php.ini
Vi / usr/local/php/etc/php.ini
Input? Sendmail_path search location (or manually jump to find sendmail_path), you will find that the default is the following code
; sendmail_path =
Press I to enter the edit and change the line to
Sendmail_path = / usr/sbin/sendmail-t-I
Press Esc to exit editing, enter: wq save exit
Restart the php-fpm process
/ etc/init.d/php-fpm restart
At this point, on the "Linux lnmp can not use mail email solution" study is over, I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.