2017-12-10 9 views
0

先週まで働いていた以下のコードを使って試してみました。おそらくGmail側でいくつかの変更があります。しかし、いろいろな組み合わせが試されても機能しません。 は)危険なアプリはまだあなたがphpmailerのphpmail gmail SMTPに接続できません

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

を設定へ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(PHPMailer-> SendSend() 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

関連する問題