这个问题在这里已有答案:
我的日志显示如下 $mail->SMTPSecure = 'tls'; $mail->Port = 587;
017-03-14 09:53:25服务器 - >客户端:220 smtp.gmail.com客户端 - >服务器:EHLO localhost服务器 - >客户端:250-smtp.gmail.com在您的服务客户端 - >服务器:STARTTLS客户端 - >服务器:这是非HTML邮件客户端的纯文本正文CLIENT - > SERVER:Content-Type:text / html; charset = us-ascii 2017-03-14 09:53:27客户端 - >服务器:这个机身以粗体显示! 2017-03-14 09:53:27服务器 - >客户端:221 2.0.0关闭连接63sm14765080wmg.22 - gsmtp消息已发送
以前的代码看起来如下 . 我已将端口更改为465,将SMTPSecure更改为ssl . 我有不同的错误
2017-03-14 07:40:31 SMTP错误:无法连接到服务器:(0)2017-03-14 07:40:31 SMTP connect()失败 . https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting无法发送消息.Mailer错误:SMTP connect()失败 . https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
我通过添加发送电子邮件密码和名称在php.ini中进行了更改 .
<?php
require 'PHPMailer/PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->SMTPDebug = 2; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com';// Specify main and backup SMTP s
$mail->SMTPAuth = true;
$mail->Username = 'sender@gmail.com'; // SMTP user
$mail->Password = 'password'; // SMTP pas
$mail->SMTPSecure = 'ssl'; // Enable TLS 'tls'encryption,
$mail->Port = 465; // TCP port to
$mail->setFrom('sender@gmail.com', 'Eiman');
$mail->addAddress('sender1@gmail.com', 'user1');
$mail->addAddress('sender2@gmail.com'); // Name is optional
//$mail->addReplyTo('info@example.com', 'Information');
//$mail->addCC('cc@example.com');
//$mail->addBCC('bcc@example.com');
//mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
//$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Registration Form';
$mail->Body = 'This body <b>in bold!</b>';
$mail->AltBody = 'This is the body in ';
if (!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
最后我改变了 $mail->SMTPDebug = 0; `现在没有错误 . 我没有收到任何邮件 .
2 回答
你在你的Gmail帐户中做过这个吗?
将其打开
这不是错误,请参阅文本 Message has been sent
你在这里看到的是
SMTPDebug
日志的输出 .所以只需注释掉你的调试日志: