2017-05-16 6 views
0

"Google Mail의 보안 수준이 낮은 앱 사용"옵션을 변경했으며 Gmail 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을."- 내가 잘 수 없어요 무엇을 ... 그리고 더 나은 접근법, 또는 내가 선호하는 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