search
HomeBackend DevelopmentPHP ProblemWhat should I do if I can't receive emails sent by php?

Solution to the problem that php cannot receive emails: first execute the command "sudo apt-get install sendmail" to install; then enter the command "ps aux |grep sendmail" in the terminal; then generate a new configuration file; Finally, test whether the configuration is successful in the terminal.

What should I do if I can't receive emails sent by php?

Recommended: "PHP Video Tutorial"

Solve 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, the emails cannot be received. 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

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 What should I do if I can't receive emails sent by php?. For more information, please follow other related articles on the PHP Chinese website!

Statement
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools