我已经尝试使用phpmailer()它给msg已经发送但我还没有收到任何邮件

时间:2017-03-14 08:30:36

标签: php email phpmailer

我的日志显示如下 $mail->SMTPSecure = 'tls';
$mail->Port = 587;

  

017-03-14 09:53:25   服务器 - >客户:220 smtp.gmail.com   客户 - >服务器:EHLO localhost
  服务器 - >客户:250-smtp.gmail.com在您的服务中   客户 - >服务器:STARTTLS
  客户 - > SERVER:这是非HTML邮件客户端的纯文本正文   客户 - > 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连接()失败。   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-&gt; SMTPDebug = 0; `现在没有错误。我没有收到任何邮件。

2 个答案:

答案 0 :(得分:0)

您是否在gmail帐户中完成了此操作?

Allow less secure app    打开它

答案 1 :(得分:0)

  

017-03-14 09:53:25服务器 - &gt;客户:220 smtp.gmail.com客户端 - &gt;服务器:EHLO localhost
  服务器 - &gt;客户:250-smtp.gmail.com在您的服务中   客户 - &gt;服务器:STARTTLS
  客户 - &gt; SERVER:这是非HTML邮件客户端的纯文本正文   客户 - &gt; SERVER:Content-Type:text / html; charset = us-ascii 2017-03-14 09:53:27
  客户 - &gt;服务器:这个机构以粗体显示! 2017-03-14 09:53:27
  服务器 - &gt;客户端:221 2.0.0关闭连接63sm14765080wmg.22 - gsmtp已发送消息

这不是错误,请参阅消息已发送

您在这里看到的是SMTPDebug日志的输出。

所以只需注释掉你的调试日志:

// $mail->SMTPDebug = 2; 
相关问题