2016-04-14 67 views
0
function send_mail($message, $subject) 
{ 
    if (array_key_exists('resume', $_FILES)) 
    { 
     $uploadfile = tempnam(sys_get_temp_dir(), sha1($_FILES['resume']['name'])); 
     if (move_uploaded_file($_FILES['resume']['tmp_name'], $uploadfile)) 
     { 
      require './PHPMailer/PHPMailerAutoload.php'; 
      $mail    = new PHPMailer; 
      $mail->isSMTP(); 
      $mail->SMTPDebug = 1; 
      $mail->Debugoutput = 'html'; 
      $mail->Host  = 'smtp.gmail.com'; 
      $mail->Port  = 587; 
      $mail->SMTPSecure = 'tls';    
      $mail->SMTPAuth = true; 
      $mail->Username = "[email protected]"; 
      $mail->Password = "XXXX"; 
      $mail->SetFrom('[email protected]', 'ABC'); 
      $mail->AddAddress('[email protected]'); 
      $mail->Subject = $subject; 
      $mail->MsgHTML($message); 
      $mail->AltBody = 'This is a plain-text message body'; 
      $mail->addAttachment($uploadfile); 

      if ($mail->Send()) 
      { 
       echo "<script>alert('Your application is sent successfully. Our recruitment team will get in touch with you soon.');</script>"; 
      } 
      else 
      { 
       echo "Mailer Error: " . $mail->ErrorInfo; 

      } 
     } 
     else 
     { 
      echo 'Failed to move file to ' . $uploadfile; 
     } 
    } 

}的PHPMailer:密码命令失败:534-5.7.14

我得到下面提到的错误:

CLIENT -> SERVER: EHLO localhost 
CLIENT -> SERVER: STARTTLS 
CLIENT -> SERVER: EHLO localhost 
CLIENT -> SERVER: AUTH LOGIN 
CLIENT -> SERVER: ZGV0ZWN0aW9uaW5zdHJ1bWVudEBnbWFpbC5jb20= 
CLIENT -> SERVER: ZGV0ZWN0aW9uaW5kaWE= 
SMTP ERROR: Password command failed: 534-5.7.14   <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbuk534-5.7.14 PHxasqAG-1Yi0Ij1bFvZdQIBCbXiwU2i-qOUAnhhTN-mHhCHRat1ivgXGVmBuQTk0cJTl2534-5.7.14 7kvt6yrXWWs9R8Rz1mxkje545Mg0F7Xx3Cl1VTW33gDBxGfcVfR-pIVPd1SIqMHWdICkLz534-5.7.14 pPL3_DNms_IS8jJkz3Eo3MH91Yq1OU3XUV1EXzfxaUA7xbYyK9jbwM1XVvVQ-NqqYYKCMY534-5.7.14 uNWA9kWIDl_XXYWrNNP6_cCiWomH8> Please log in via your web browser and534-5.7.14 then try again.534-5.7.14 Learn more at534 5.7.14 https://support.google.com/mail/answer/78754 bb5sm14055457pac.21 - gsmtp 

SMTP错误:无法验证。 客户端 - >服务器:退回 SMTP connect()失败。 https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting 邮件错误:SMTP连接()失败。

+0

如果您按照链接到错误消息的故障排除指南中的建议进行操作,您会有更多想法。对于一个开始设置'SMTPDebug = 2',这样你就可以看到服务器消息。 – Synchro

回答

0

你可能需要启用less secure apps


Change account access for less secure apps

To help keep Google Apps users' accounts secure, we may block less secure apps from accessing Google Apps accounts. As a Google Apps user, you will see a "Password incorrect" error when trying to sign in. If this is the case, you have two options:

  1. Option 1: Upgrade to a more secure app that uses the most up to date security measures. All Google products, like Gmail, use the latest security measures.
  2. Option 2: Change your settings to allow less secure apps to access your account. We don't recommend this option because it might make it easier for someone to break into your account. If you want to allow access anyway, follow these steps:

    2.1. Go to the " Less secure apps " section in My Account

    2.2. Next to "Access for less secure apps," select Turn on. (Note to Google Apps users: This setting is hidden if your administrator has locked less secure app account access.)

If you still can't sign in to your account, the " password incorrect " error might be caused by a different reason.

SRC:https://support.google.com/accounts/answer/6010255?hl=en


注:

添加错误的文件的顶部报告(S)在您打开PHP标记之后看到的PHPMailer

$mail->SMTPDebug = 1; // enables SMTP debug information (for testing) 
         // 1 = errors and messages 
         // 2 = messages only 

例如<?php error_reporting(E_ALL); ini_set('display_errors', 1);

,并启用调试,如果它得到任何东西。

+0

感谢您的回复,但“安全性较低的应用程序”已启用。 – user2381175