2016-04-01 14 views
3
<?php 

include("class.phpmailer.php"); 
include("class.smtp.php"); 

$mail = new PHPMailer(); 

$mail->IsSMTP(); // telling the class to use SMTP 
$mail->Mailer = "smtp"; 
$mail->SMTPDebug = 2; 
$mail->Host = "ssl://smtp.gmail.com"; // specify main and backup server 
$mail->Port = 587; // set the port to use 
$mail->SMTPAuth = true; // turn on SMTP authentication 
$mail->SMTPSecure = "tls"; 

$mail->Username = "[email protected]"; // SMTP username 
$mail->Password = "password"; // SMTP password 

$mail->From = "[email protected]"; 
$mail->FromName = "Webmaster"; 

$mail->AddAddress("[email protected]"); 
$mail->AddReplyTo("[email protected]", "Webmaster"); 
$mail->IsHTML(true); 

$mail->Subject = "First PHPMailer Message"; 
$mail->Body  = "Hi! \n\n This is my first e-mail sent through PHPMailer."; 
$mail->WordWrap = 50; 

if(!$mail->Send()) { 
    echo 'Message was not sent.'; 
    echo 'Mailer error: ' . $mail->ErrorInfo; 
} else { 
    echo 'Message has been sent.'; 
} 
?> 

への接続に失敗しましたそれは私が私のXAMPPローカルサーバー上でこのPHPをホスティングしていますエラーphpmailerのSMTPエラー:サーバー

2016-04-01 08:41:43 SMTP ERROR: Failed to connect to server: (0) 
2016-04-01 08:41:43 SMTP connect() failed. 

https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting Message was not sent.Mailer error: SMTP connect() failed. 

https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting 

を返します。 extension=php_openssl.dllphp.ini)は既に推奨されていません。

+0

あなたはphpmailerの古いバージョンを使用していては、廃止された例で、あなたのコードをベースとしています。 [最新版を入手する](https://github.com/PHPMailer/PHPMailer)、[提供されたGmailの例](https://github.com/PHPMailer/PHPMailer/tree/master/examples)を使用してください。これは**最初のものです**あなたのエラーメッセージからリンクされたトラブルシューティングのガイドはチェックするように言いますが、あなたは明らかにそれを読んでいません。 – Synchro

+3

[Gmailメールサーバ経由でメールを送信する](https://stackoverflow.com/questions/16048347/send-email-using-gmail-smtp-server-through-php-mailer) –

答えて

2

設定が間違っている可能性があります。ホストをsmtp.gmail.comに変更すると、問題が解決する可能性があります。

あなたはセキュリティtlsを設定していることに気づきましたが、sslにも接続したいと思っています。

$mail->Host = "ssl://smtp.gmail.com";$mail->Host = "smtp.gmail.com";に変更し、セキュリティをsslに変更します。 this answerから

$mail = new PHPMailer(); // create a new object 
$mail->IsSMTP(); // enable SMTP 
$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only 
$mail->SMTPAuth = true; // authentication enabled 
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for Gmail 
$mail->Host = "smtp.gmail.com"; 
$mail->Port = 465; // or 587 
$mail->IsHTML(true); 
$mail->Username = "[email protected]"; 
$mail->Password = "password"; 
$mail->SetFrom("[email protected]"); 
$mail->Subject = "Test"; 
$mail->Body = "hello"; 
$mail->AddAddress("[email protected]"); 

if(!$mail->Send()) { 
    echo "Mailer Error: " . $mail->ErrorInfo; 
} else { 
    echo "Message has been sent"; 
} 
+0

の可能な複製接続問題。しかし、私はもう少し問題があった、Googleのメールは、アクセスをブロックするようだ。 http://stackoverflow.com/questions/20337040/gmail-smtp-debug-error-please-log-in-via-your-web-browserこれはセキュリティの問題を解決しました –

+0

そこに何かエラーがありますか? –

+0

廃止された例に基づいてコードを投稿しないでください。最新の状態に保たれているので、[PHPMailerで提供されるサンプル](https://github.com/PHPMailer/PHPMailer/tree/master/examples)を使用してください。 – Synchro

関連する問題