2016-04-14 117 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