Home > Backend Development > PHP Problem > How to solve the problem of not receiving php mail

How to solve the problem of not receiving php mail

藏色散人
Release: 2023-03-03 10:50:01
Original
2341 people have browsed it

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.

How to solve the problem of not receiving php mail

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
Copy after login

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
Copy after login

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
Copy after login

Find the following line:

Code

DAEMON_OPTIONS(`Family=inet,  Name=MTA-v4, Port=smtp, Addr=127.0.0.1′)dnl
Copy after login

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
Copy after login

Find the sentence ";sendmail_path", remove the comment ";", and then add the sendmail startup directory

sendmail_path = /usr/sbin/sendmail -t -i
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template