2017-05-15 57 views
-1

我真的希望你们中的一个人可以帮助我。我一直用这个拉着我的头发约2个小时。我的客户电子邮件服务器上的其中一个帐户遭到入侵,Google开始阻止我们发送电子邮件的企图。所以我试图从基本的PHP邮件命令切换到PHPMailer并通过Google的SMTP服务器发送。此客户使用Google专业版的所有帐户。PHP邮件与PHPMailer通过谷歌SMTP

我使用了以下内容:

$mail    = new PHPMailer(); 

    $mail->isSMTP(); // telling the class to use SMTP 
    $mail->SMTPDebug = 1;      // enables SMTP debug information (for testing) 
    $mail->Host  = "smtp.gmail.com";  // sets GMAIL as the SMTP server 
    $mail->SMTPSecure = "tls";     // sets the prefix to the server 
    $mail->SMTPAuth = true;     // enable SMTP authentication 
    $mail->Port  = 587;     // set the SMTP port for the GMAIL server 
    $mail->Username = "[email protected]"; // GMAIL username 
    $mail->Password = "*********";   // GMAIL password 

    $mail->SetFrom('[email protected]', 'Jimmy'); 

    $mail->Subject = $this->subject; 

    $body    = $this->message; 
    //$body    = eregi_replace("[\]",'',$body);   

    $mail->MsgHTML($body); 

    $mail->AddAddress($this->to, 'bob'); 

    if(!$mail->Send()) { 
     error_log("Mailer Error: " . $mail->ErrorInfo); 
     echo '[br /]Fail'; 
    } else { 
     error_log("Message sent!"); 
     echo '[br /]Pass'; 
    } 

我知道证书是正确的,因为我可以与他们登录。我已经做了所有种类的东西这个脚本,它正试图使用​​的帐户发送:从TLS

  1. 更改到SSL
  2. '疏通Captcha验证码的帐户
  3. 禁用2因素身份验证(它已经关闭)
  4. 启用“不够安全的应用”

我不知道还能做什么。这是我不断收到的错误:

2017-05-15 03:12:30 CLIENT -> SERVER: EHLO americanbeautytools.com 
2017-05-15 03:12:30 CLIENT -> SERVER: STARTTLS 
2017-05-15 03:12:30 CLIENT -> SERVER: EHLO americanbeautytools.com 
2017-05-15 03:12:30 CLIENT -> SERVER: AUTH LOGIN 
2017-05-15 03:12:30 CLIENT -> SERVER: xxx= 
2017-05-15 03:12:30 CLIENT -> SERVER: xxx= 
2017-05-15 03:12:32 SMTP ERROR: Password command failed: 535 Incorrect authentication data 
2017-05-15 03:12:32 SMTP Error: Could not authenticate. 
2017-05-15 03:12:32 CLIENT -> SERVER: QUIT 
2017-05-15 03:12:32 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting 

有关密码命令失败的部分是我没有得到的部分。当我用这个电子邮件帐户登录时,这怎么会是错误的?

我已经看了大约15个关于这个主题的话题,而他们的建议都没有解决我的问题。这是一个谷歌专家帐户,我的客户通过谷歌运行,所以它不会是'免费'限制的事情。

+0

差不多*你发现,*和*排除指南这些线程中的每一个*,会告诉你**设置'SMTPDebug = 2' **。当它设置为1时,你不会看到服务器说的任何东西。 – Synchro

+0

如果您将代码基于PHPMailer提供的gmail示例,那么首先您就不会陷入这个难题。 – Synchro

+0

@Synchro - 我确实已将它设置为2,并且没有提供任何其他有用的信息。你的第二条评论没有帮助。我有我的代码镜像PHPMailer的例子,它的许多变化和错误仍然存​​在。我完成了这个设置。我正在切换到外部邮件提供商。 –

回答

-1

使用G套件帐户或sendgrid帐户进行测试。我已经使用我的gmail凭证进行了测试。

$mail = new PHPMailer; 
$mail->isSMTP(); 
$mail->Host = 'smtp.gmail.com'; 
$mail->Port = 465; 
$mail->SMTPSecure = 'ssl'; 
$mail->SMTPAuth = true; 
$mail->Username = '[email protected]'; // SMTP username 
$mail->Password = '123456789'; // SMTP password 
$mail->setFrom('[email protected], 'Krishna'); 
$mail->addAddress($to_addr, 'Test');  // Add a recipient 
$mail->Subject = $subject; 
$mail->isHTML(true); 
$mail->Body = $message; 
+0

请不要在没有解释它如何回答问题的情况下发布代码。 – Synchro

+0

@Synchro请不要给任何建议,如果你没有任何答案.. –

+0

这是不可能回答这个问题,因为海报还没有提供足够的信息继续下去。当这个问题得到解决后,我可以回答。同时,与你不同,我不会发布猜测作为答案。 – Synchro

-1
<?php 

     require ('../PHPMailerAutoload.php'); //add PhPMailerAutoload.php file Path 
     $mail = new PHPMailer(); // create Object 

     $name=$_POST['Name']; //get name from post method 
     $to=$_POST['email']; //get email from post method 
     $message = $_POST['message']; //get msg from post method 

     $mail->isSMTP(); // telling the class to use SMTP 
     $mail->SMTPDebug = 2;      // enables SMTP debug information (for testing) 
     $mail->Host  = "smtp.gmail.com";  // sets GMAIL as the SMTP server 
     $mail->SMTPSecure = "ssl";     // sets the prefix to the server 
     $mail->SMTPAuth = true;     // enable SMTP authentication 
     $mail->Port  = 465;     // set the SMTP port for the GMAIL server 
     $mail->Username = "[email protected]"; // GMAIL username 
     $mail->Password = "*********";   // GMAIL password 
     $mail->SetFrom('[email protected]', 'Jimmy'); //Set who the message is to be sent from 
     $mail->Subject = "Email from Mailer"; // $this->subject; 
     $mail->Body = "test Email msg";  // $this->message; 
     $mail->isHTML(true); 
     $mail->MsgHTML($message); 
     $mail->addAddress($to,$name); 
     $mail->WordWrap = 70; 

     if(!$mail->Send()) { 
      echo 'Message could not be sent.'.'<br>'; 
      echo "Mailer Error: " . $mail->ErrorInfo); 
      exit; 

     } else { 
      echo 'Message sent.'.'<br>'; 
      exit; 
     } 


    ?> 
+0

请不要发布未注释的,过时的代码。 – Synchro

相关问题