2016-07-11 2 views
1

im пытается отправить электронное письмо, только когда кто-то входит на страницу. Это для подтверждения оплаты в PayPal. Вы платите что-то и на странице, где вы видите, что вы делали, электронная почта отправляется автоматически.PHPMAILER SERVER -> SMTP ERROR: команда пароля не выполнена Ошибка SMTP connect()

Код следующий:

function send_email($from, $to, $subject, $nombre,$apellido) {   

     $pagoReal = $_SESSION["Payment_Amount"]; 
     $monedaReal = $_SESSION["currencyCodeType"]; 
     $estado = $_SESSION['estado']; 
     $id = $_SESSION['idHash']; 



     $mail = new PHPMailer(); 
     $mail->SMTPDebug=3; 
     $mail->IsSMTP(); 
     $mail->Host = 'localhost'; 
     $mail->CharSet = "UTF-8"; 

     $mail->From = $from; 
     $mail->FromName = 'Notificación de pago via Paypal'; 
     $mail->addAddress($to); 

     $mail->WordWrap = 50; 
     $mail->IsHTML(true); 
     $mail->SMTPAuth = true; 



     $contenido = "<html><body> 
        <p>Han realizado un nuevo ingreso via Paypal</p><br> 
        Nombre del cliente: $nombre $apellido<br> 
        Cantidad que pagó: $pagoReal $monedaReal <br> 
        Estado de la reserva:$estado <br> 
        Enlace a la factura : href='xxxxx/$id<br> 
        </body></html>"; 


     $mail->Subject = $subject; 
     $mail->Body = $contenido; 

     ['tmp_name'],$_FILES['cv_contacto']['name']); 



     if (!$mail->Send()) { 
      echo 'Error enviando mensaje.'; 
      echo 'Mailer Error: ' . $mail->ErrorInfo; 

      return "Mailer Error: " . $mail->ErrorInfo; 
     } else { 
      return 1; 
     } 

    } 

тогда я вызываю функцию

send_email('[email protected]', '[email protected]','Payment of '. $firstName." ".$lastName,$firstName,$lastName); 

И я получаю эту ошибку

Ошибка при аутентификации: Общий сбой 2016-07-11 14:20:51 SMTP ERROR: сбой пароля: 535 5.7.8 Ошибка: аутентификация не удалась: общий сбой 2016-07-11 14:20:51 КЛИЕНТ -> СЕРВЕР: QUIT 2016-07-11 14:20:51 SERVER -> КЛИЕНТ: 221 2.0.0 Bye 2016-07- 11 14:20:51 Соединение: закрыто 2016-07-11 14:20:51 Ошибка SMTP connect(). Ошибка enviando mensaje.Mailer Ошибка: SMTP connect() не удалось.

Любая идея, что я могу сделать?

Спасибо!

+0

Try '$ mail-> SMTPAUTH = ложь;' вместо истинно, если локальный сервер позволит вам пересылать почту. – drew010

+0

СПАСИБО ВАМ ЭТО РАБОТАЕТ !!! – franwebofrito

+0

Я рад, что вы это исправили, но используете старую версию PHPMailer, и вы основали свой код на устаревшем примере. [Получить последнюю версию] (http://phpmailer.github.io/PHPMailer). – Synchro

ответ

1

Выполните следующие шаги.

Use an App Password: If you use 2-Step Verification, try signing in with an App Password.

Allow less secure apps: If you don't use 2-Step Verification, you might need to allow less secure apps to access your account.

If you recently changed your Gmail password, you might need to re-enter your Gmail account information or completely repeat your Gmail account setup on your other email client. If the tips above didn't help, visit https://www.google.com/accounts/DisplayUnlockCaptcha and follow the steps on the page. If you use Gmail through your work, school, or other organization, visit https://www.google.com/a/yourdomain.com/UnlockCaptcha and replace yourdomain.com with your domain name.

0

Я решил этот вопрос:

Пожалуйста, следуйте приведенным ниже инструкциям:

1) Во-первых, скачать последние версии файлов PHPMailer. https://github.com/PHPMailer/PHPMailer

a) Check its there at all (on terminal) 

    ping smtp.gmail.com 

    This should give you something like this: 

    Trying 173.194.67.109... 
    Connected to gmail-smtp-msa.l.google.com. 
    Escape character is '^]'. 
    220 mx.google.com ESMTP ex2sm16805587wjd.30 - gsmtp 

b) openssl s_client -starttls smtp -crlf -connect smtp.gmail.com:587 

    You should expect a response like this: 

    Start Time: 1460541074 
    Timeout : 300 (sec) 
    Verify return code: 0 (ok) 
    --- 
    250 SMTPUTF8 

    Notice that the verify return code is 0, which indicates successful verification. 

    refer link : https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting 

2) Google в настоящее время не принимает логин из менее защищенных приложений.
Открыть ссылку: https://myaccount.google.com/security

 Firstly login your gmail account. 

    a)Scroll to the bottom and turn ON "Allow less secure apps: ON". 

    b)Now when you add the SMTP details to "Send as" google will accept them. 
    c)You need to do this for the email ID you are adding in your Send as section. 

3) код сценария:

  require 'PHPMailerAutoload.php'; 


      $mail = new PHPMailer(); 

      $mail->isSMTP();      // telling the class to use SMTP 
      $mail->SMTPDebug = 2;     
      // 0 = no output, 1 = errors and messages, 2 = messages only. 

      $mail->SMTPAuth = true;    // enable SMTP authentication 
      $mail->SMTPSecure = "tls";    // sets the prefix to the servier 
      $mail->Host = "smtp.gmail.com";  // sets Gmail as the SMTP server 
      $mail->Port = 587;      // set the SMTP port for the GMAIL 

      $mail->Username = "[email protected]"; // Gmail username 
      $mail->Password = "********";  // Gmail password 

      $mail->CharSet = 'windows-1250'; 
      $mail->SetFrom ('[email protected]'); // send to mail 
      $mail->AddBCC ('[email protected]'); // send to mail 
      $mail->Subject = $subject; 
      $mail->ContentType = 'text/plain'; 
      $mail->isHTML(false); 

      $body_of_your_email ="Hello Pradeep"; 
      $mail->Body = $body_of_your_email; 
      // you may also use $mail->Body =  file_get_contents('your_mail_template.html'); 
      $mail->AddAddress ('[email protected]', 'Recipients Name');  
      // you may also use this format $mail->AddAddress ($recipient); 

      if(!$mail->Send()) 
      { 
       echo $error_message = "Mailer Error: " . $mail->ErrorInfo; 
      } else 
      { 
      echo $error_message = "Successfully sent!"; 
      } 

Я надеюсь, что его работает отлично.

Благодаря

Смежные вопросы