2017-04-11 14 views
-1

私の問題を解決するために何時間も検索されていますが、失敗しました。メーラーエラーのエラー:SMTP connect()が失敗しました

これはXAMPPでGmailに電子メールを送信し、このエラーを毎回取得する私の簡単なコードを使用phpmailerのです:

Message could not be sent.Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

と、これは私のPHPコードです:

<?php 
require_once('PHPMailer/PHPMailerAutoload.php'); 

$mail = new PHPMailer(); 
$mail->isSMTP(); 
$mail->SMTPAuth = true; 
$mail->SMTPSecure = 'ssl'; 
$mail->HOST = 'smtp.gmail.com'; 
$mail->PORT = '465'; 
$mail->isHTML(); 
$mail->Username = '##myemail##@gmail.com'; 
$mail->Password = '##mypass##'; 
$mail->SetFrom('[email protected]'); 
$mail->Subject = 'Hello World'; 
$mail->Body = 'A test email!'; 
$mail->AddAddress('[email protected]'); 


if(!$mail->send()) { 
    echo 'Message could not be sent.'; 
    echo 'Mailer Error: ' . $mail->ErrorInfo; 
} else { 
    echo 'Message has been sent'; 
} 

?> 

私を助けてください。

+1

wikiをチェックしましたか? https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting#smtp-error-could-not-connect-to-smtp-host – modsfabio

+0

おそらく認証エラーがありますが、 '$ mail-> SMTPDebug = 2 'エラーの内容を教えてください。 – Linek

+1

[PHPMailer、SMTP connect()はGmailでエラーに失敗しました](http://stackoverflow.com/questions/25924651/phpmailer-smtp-connect-failed-error-with-gmail) – Synchro

答えて

0

デバッグを出力するには、$mail->SMTPDebug = 3; $mail->isHTML(true);を追加します。 Gmailを使用して安全でないアプリで接続を有効にしていることを確認してください。このリンクを見てくださいhttps://support.google.com/a/answer/6260879?hl=en

関連する問題