我正在尝试发送电子邮件而且我有2个脚本:
send.php
<?php
require_once 'PHPMailerAutoload.php';
require_once 'class.phpmailer.php';
require_once 'class.smtp.php';
$mail = new PHPMailer();
$body = " ";
$mail->IsSMTP();
$mail->SMTPDebug = 4;
$mail->SMTPAuth = true;
$mail->SMTPSecure = "tls";
$mail->Host = "smtp.gmail.com";
$mail->Port = 587;
$mail->Username = "XXXXXXXX@gmail.com";
$mail->Password = "XXXXXXXX";
$mail->Subject = "TEST";
$mail->MsgHTML($body);
$address = "YYYYYYYY@gmail.com";
$mail->AddAddress($address, "");
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
?>
的script.php
<?php
echo shell_exec("php send.php");
?>
通过直接在浏览器中调用send.php
,即可发送电子邮件。问题是当我拨打script.php
时,电子邮件不会发送,我收到错误。以下是输出的最后一行:
2016-02-09 19:19:55 Connection: opening to smtp.gmail.com:587, t=300, opt=array (
)
2016-02-09 19:19:55 Connection: opened
2016-02-09 19:19:55 SMTP -> get_lines(): $data was ""
2016-02-09 19:19:55 SMTP -> get_lines(): $str is "220 smtp.gmail.com ESMTP cc7sm606507lbd.11 - gsmtp
"
2016-02-09 19:19:55 SMTP -> get_lines(): $data is "220 smtp.gmail.com ESMTP cc7sm606507lbd.11 - gsmtp
"
2016-02-09 19:19:55 SERVER -> CLIENT: 220 smtp.gmail.com ESMTP cc7sm606507lbd.11 - gsmtp
2016-02-09 19:19:55 CLIENT -> SERVER: EHLO raspberrypi
....
Warning: stream_socket_enable_crypto(): this stream does not support SSL/crypto in /var/www/html/class.smtp.php on line 325
2016-02-09 19:19:55 CLIENT -> SERVER: QUIT
2016-02-09 19:19:56 SMTP -> get_lines(): $data was ""
2016-02-09 19:19:56 SMTP -> get_lines(): $str is "�F"
2016-02-09 19:19:56 SMTP -> get_lines(): $data is "�F"
2016-02-09 19:19:56 SERVER -> CLIENT: �F
2016-02-09 19:19:56 SMTP ERROR: QUIT command failed: �F
2016-02-09 19:19:56 Connection: closed
2016-02-09 19:19:56 SMTP connect() failed.
Mailer Error: SMTP connect() failed.
可能导致此问题的原因是什么?我正在使用PHP7