2017-12-10 14 views
0

지난 주까지 근무해온 아래 코드를 사용해 보았습니다. Gmail 측에서 일부 변경 될 수 있습니다. 하지만 다양한 조합을 시도해도 작동하지 않습니다. 안전하지 않은 애플리케이션을 허용 당신은 Phpmailerphpmail gmail SMTP에 연결할 수 없습니다.

$mail->SMTPOptions = array(
'ssl' => array(
    'verify_peer' => false, 
    'verify_peer_name' => false, 
    'allow_self_signed' => true 
) 

)을 config (설정) 할 SMTPOption를 추가 여전히 SMTP에게

<?php 
sendMail("[email protected]", "[email protected]", "test", "test msg<br>hello!"); 

function sendMail($to, $from, $subject, $message) { 
    try { 
     //$to='[email protected]'; 
     $headers = "MIME-Version: 1.0" . "\r\n"; 
     $headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n"; 
     $headers .= 'From:' . $from . ' <[email protected]>' . "\r\n"; 
     ini_set("sendmail_from", "[email protected]"); 
     require_once("class.phpmailer.php"); 
     require_once("class.smtp.php"); 
     set_time_limit(240); 
     $mail = new PHPMailer(true); 
     $mail->IsSMTP(); // telling the class to use SMTP 
     $mail->SMTPAutoTLS = false; 
     $mail->Host = "smtp.gmail.com"; 
     $mail->SMTPDebug = 4; 
     $mail->SMTPAuth = true;     // enable SMTP authentication 
     $mail->Port = 587; // or 587     // set the SMTP port for the GMAIL server 
     $mail->Username = "[email protected]"; // SMTP account username 
     $mail->Password = "password123"; // SMTP account password 
     $mail->From = "[email protected]"; 
     $mail->SMTPSecure = 'tls'; 

     $mail->AddAddress("[email protected]"); 
     $mail->SetFrom('[email protected]', $from); 
     $mail->AddReplyTo("[email protected]", $from); 
     $mail->AddBCC("[email protected]"); 
     $mail->IsHTML(true); 
     $mail->Subject = $subject; 
     $mail->Body = $message; 
     $mail->WordWrap = 50; 
     echo 'sendMail to=>' . $to; 
     if (!$mail->Send()) { 
      echo 'Message was not sent.'; 
      echo 'Mailer error: ' . $mail->ErrorInfo; 
     } else { 
      echo '<br>Message was sent successfully to selected recipients.'; 
     } 
    } catch (Exception $ex) { 

     echo'EXCEPTION <br>'; 
     echo '<br>Caught exception: ' . $ex->getMessage() . "\n".$ex->getTraceAsString(); 
    } 
} 

?> 
+0

실제 오류를 게시해야합니다. 그것은 당신의 코드에 문제가되지 않습니다. Gmail의 루트 CA 인증서가 최근에 변경되면 문제가 될 수 있습니다. 최근에 여러 번 답변을 얻었으므로 해당 주제에 대한 질문을 검색하십시오. – Synchro

+0

나는 많은 의견을 찾았습니다. 또한 CA 인증서 cacert.pem을 추가했지만 여전히 작동하지 않았습니다. 계속 표시 SMTP 호스트에 연결할 수 없습니다. 오류는 다음과 같습니다. => [email protected] -> FROM SERVER : 220 smtp.gmail.com ESMTP f23sm26136426pfk.71 - gsmtp SMTP -> FROM SERVER : 250-smtp.gmail.com PHPMailer-> PostSend() # 3 mailtest.php (36) : PHPMailer-> Send() # 4 mailtest.php (PHP4) 3) : sendMail ('togmail @ gmail ....', 'frommailid @ gma ...', 'test', 'test msg hel ...') # 5 {main} – user1969292

+0

샘플 .NET을 사용해 보았습니다. 이상하게도 문제없이 작동합니다. 그러나 PHPmailer와 작동하지 않는 동일한 문제. 동일한 포트, 동일한 이메일, 동일한 서버. 그러나 PHP에서는 작동하지 않습니다. – user1969292

답변

0

를 연결할 수 없습니다 ON입니다;

+0

시도해도 아무런 변화가 없었습니다. 예외 : SMTP 오류 : SMTP 호스트에 연결할 수 없습니다. # 0 – user1969292