Reading guidance PHP requires an installed and running messaging system so that mail function mail () is available. The mail system program used is set up in the php.ini file.
Sending a message with the following code can always send a failure.
[php] View plaincopyprint?
!--? php . $to = "xxxxxxxx@qq.com";
$subject = "Test mail";
$message = "hello! A simple email message. ";
05.mail ($to, $subject, $message);
06.?>
, PHP needs an installed and running messaging system to make mail function mail () available. The mail system program used is set up in the php.ini file. The workaround is as follows:
1. Install sendmail
sudo apt-get install sendmail
sudo apt-get install sendmail-cf
sudo apt-get install Mailutils
2. Configure SendMail
To open/ETC/MAIL/SENDMAIL.MC, locate the following line:
Daemon_options (' Family=inet, NAME=MTA-V4, port= SMTP, addr=127.0.0.1 ') dnl
Change 127.0.0.1 to 0.0.0.0
perform the following command to back up the old configuration file and generate a new profile:
Cd/etc/mail
MV SENDMAIL.CF sendmail.cf~
M4 SENDMAIL.MC > SENDMAIL.CF
3. Test
Echo "This is a test mail." | mail-s "Test" xxxxxxxx@qq.com
Note: This message will be accepted as spam, and if you use 163 mailboxes you may be filtered out of the box to receive it.
4. Configure php.ini file
to open/etc/php5/apache2/php.ini, locate the following line:
; sendmail_path =
Change the line to: Sendmail_path =/usr/sbin/ Sendmail-t
In particular, it is important to note that the "-T" parameter is necessary, and if it is missing, the mail () function fails when the original PHP file is executed through the browser, but there is no problem if the original PHP file is executed directly on the server side using the PHP command line.
5. Restart Apache
Sudo/etc/init.d/apache2 restart
The original PHP code is executed again, and the message is sent successfully.
The above describes the reason that PHP cannot send mail with the email function, including the content of the contents, I hope that the PHP tutorial interested in a friend helpful.