2017-05-16 13 views
0

私は "Google Mailの安全性の低いアプリケーションを有効にする"オプションを変更しましたが、私のGmailアプリケーションからこのエラーが発生しています。私は、コードを実行すると、それは私に、このエラーが発生しますPHPmailer - Gmailのsmtp接続エラー

require 'inc/PHPMailerAutoload.php'; 
$mail = new PHPMailer; 

$mail = new PHPMailer; 

$mail->IsSMTP();          // Set mailer to use SMTP 
$mail->Host = 'smtp.gmail.com';     // Specify main and backup server 
$mail->Port = 587;         // Set the SMTP port 
$mail->SMTPAuth = true;        // Enable SMTP authentication 

$mail->Username = '*al********@gmail.com';    // SMTP username 
$mail->Password = '****at****';     // SMTP password 
$mail->SMTPSecure = 'tls'; 

$mail->From = '*al********@gmail.com'; 
$mail->FromName = '******i'; 
$mail->AddAddress('[email protected]', 'Ande C.'); // Add a recipient 

$mail->IsHTML(true);         // Set email format to HTML 

$mail->Subject = 'Here is the subject'; 
$mail->Body = 'This is the HTML message body <strong>in bold!</strong>'; 
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients'; 

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

echo 'Message has been sent'; 

... 「メッセージがsent.Mailerエラーことができませんでした:SMTPは、接続()が失敗しましたhttps://github.com/PHPMailer/PHPMailer/wiki/Troubleshootingを。」 - 私は右致しておりません何...より良いアプローチ、または私が関与できる任意のpreferrable SMTPサーバーです..私は提案が必要です。

ありがとうございました。

答えて

0
require "vendor/autoload.php"; 

//This solution is for version 6.0.3 of PHPMailer 

    use PHPMailer\PHPMailer\PHPMailer; 
    use PHPMailer\PHPMailer\Exception; 

    $mailer = new PHPMailer(true); 

    try { 
    $mailer->isSMTP(); 

$mailer->SMTPOptions = [ 
    'ssl'=> [ 
     'verify_peer' => false, 
     'verify_peer_name' => false, 
     'allow_self_signed' => true 
    ] 
]; 

$mailer->Host = 'smtp.gmail.com'; 
$mailer->SMTPAuth = true; 
$mailer->Username = '[email protected]'; 
$mailer->Password = '1234567'; 
$mailer->SMTPSecure = 'tls'; 
$mailer->Port = 587; 

$mailer->CharSet = 'UTF-8'; 
$mailer->setFrom('[email protected]'); 
$mailer->addAddress('[email protected]', 'Andres Guzmán'); 

$mailer->isHTML(true); 
$mailer->Subject = 'Subject'; 
$mailer->Body = '<b>Body <b>GRACIAS!</b>'; 

$mailer->send(); 
$mailer->ClearAllRecipients(); 
echo "Mensaje enviado"; 

    } catch (Exception $e) { 
     echo "Falla en el envío del mensaje. INFO: " . $mailer->ErrorInfo; 
    } 
+1

いくつかの説明を追加できますか?あなたは何を変えましたか?なぜあなたはそれを変更しましたか? – Yannjoel

関連する問題