Home>Article>Backend Development> How to solve the problem of not receiving php mail
Solution to the problem that php mail cannot be received: first use the command "sudo apt-get install mailutils" to install mailutils; then open the sendmail configuration macro file; then modify the content to "Addr=0.0.0.0"; finally Just test the configuration.
Recommended: "PHP Tutorial"
SolutionSolution to the problem of not receiving emails sent by php mail
I think many people want to use php mail to send emails for some verification, but when the script is written and the usage is correct, what happens to the email? I don’t get these questions either. Here I have found a method for you, which is very simple and practical.
The blogger's development environment is the LNMP platform built under ubuntu17.04:
Why can't you receive your email? It’s because you haven’t done any relevant configuration: Now you know, then follow my steps
First of all, we need to install some software:
The sendmail function in ubuntu can send emails very conveniently. To use ubuntu sendmail, you need to install two packages first
sudo apt-get install sendmail sudo apt-get install sendmail-cf
Note:
To use the most commonly used mail functions under Ubuntu, you need to install mailutils,
Installation command: sudo apt-get install mailutils
If you use the function with attachments, you also need to install sharutils,
Installation command: sudo apt-get install sharutils; (yum install sharutils )
Terminal input command: ps aux |grep sendmail
The output is as follows:
root 20978 0.0 0.3 8300 1940 ? Ss 06:34 0:00 sendmail: MTA: accepting connections root 21711 0.0 0.1 3008 776 pts/0 S+ 06:51 0:00 grep sendmail
Indicates that sendmail has been successfully installed and started
After installation, we need to perform some related configurations
sendmail will only send emails to local users by default. Only by extending it to the entire Internet can it become a real mail server.
Open the sendmail configuration macro file: /etc/mail/sendmail.mc
vi /etc/mail/sendmail.mc
Find the following line:
Code
DAEMON_OPTIONS(`Family=inet, Name=MTA-v4, Port=smtp, Addr=127.0.0.1′)dnl
Modify Addr=0.0 .0.0 , indicating that you can connect to any server.
Generate a new configuration file:
Code
#cd /etc/mail #mv sendmail.cf sendmail.cf~ //做一个备份 #m4 sendmail.mc > sendmail.cf //>的左右有空格,提示错误没有安装sendmail-cf $ sudo vim /etc/php5/apache2/php.ini
Find the sentence ";sendmail_path", remove the comment ";", and then add the sendmail startup directory
sendmail_path = /usr/sbin/sendmail -t -i
Theoretically, you can send emails here.
Finally, you can test whether the configuration is successful in the terminal:
The common ways to send emails in the terminal are as follows:
1. How to write a general email: mail test@126.com Cc Edit the CC object, Subject: email subject, enter Enter, after the email body, press Ctrl-D to end
2. Quick sending method: echo "Email body" | mail -s Email subject test@126. com
3. Send the file content as the email body: mail -s test test@126.com < test.txt
4. Send an email with an attachment: uuencode attachment name attachment Display name | mail -s Mail subject sending address
For example: uuencode test.txt test.txt | mail -s Test test@126.com
After the terminal test is successful, it means that you have You can use the mail function to send emails.
The above is the detailed content of How to solve the problem of not receiving php mail. For more information, please follow other related articles on the PHP Chinese website!