2016-04-14 3 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 Ошибка: не удалось выполнить аутентификацию. КЛИЕНТ -> СЕРВЕР: QUIT Ошибка SMTP connect(). https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting Ошибка Mailer: сбой SMTP connect().

+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


Примечание:

Добавить отчеты об ошибках в верхней части файла (ов) сразу после открытия PHP-тега для Пример <?php error_reporting(E_ALL); ini_set('display_errors', 1);

и включить отладку на PHPMailer

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

, чтобы увидеть, если он дает что-нибудь.

+0

Спасибо за ваш ответ, но «Менее безопасные приложения» уже включены. – user2381175