2013-10-10 24 views
6

私はPHPを初めて使い、PHPを使用してメールを送信します。私は、私に連絡した人の電子メールを受け入れるという私に連絡フォームを持っているので、メールは私に送られます。私はhttps://github.com/PHPMailer/PHPMailer/tree/masterからPHPMailerライブラリを使用しています。次に使用しているコードスニペットがあります。PHPMailerでSMTP connect()がエラーに失敗しました

<?php 
require("class.phpmailer.php"); 
$mail = new PHPMailer(); 
$mail->IsSMTP(); 

$mail->SMTPSecure = 'tls'; 

$mail->Host  = "resolver1.opendns.com"; // this SMTP server of my machine 
//$mail->Host  = "208.67.222.222";//ip ; which one to use the resolver1.opendns.com or 208.67.222.222 ??? 

$mail->From  = "[email protected];//email id of the person 

$mail->AddAddress("[email protected]");//my email id 

$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.'; 
} 
?> 

「メッセージは送信されませんでした.Mailerエラー:SMTP connect()failed」というエラーが表示されます。 私は問題が何かを得ていません..? $ mail-> Host = "";これが何を表すのかコメントしてください。

+0

ネットワークインタフェースのIPv6アドレスがある場合、それを削除してください。 –

+0

私はresolver1.opendns.comがあなたの電子メールを受け入れるとは思わない。 –

+0

私は '$ mail-> Port = $ SmtpPort;'を追加する必要がありました。これは開発サーバー上で動作しましたが、それ以前のプロダクションでは動作しませんでした。 – minipif

答えて

0

resolver1.opendns.comのtcpポート25をチェックしてください。ブロックされているか、sendmailやいくつかのMTAなどのstmpdを起動していません。

は25

のtelnet resolver1.opendns.comを試してみて、あなたは、TCPポート25が開かれていないでしょう。

23

$mail->SMTPDebug = 1;を追加し、問題のデバッグを試みます。

+0

私のRHELシステムでは、私がPostfixを設定したが、代わりの方法を使ってデフォルトのMTAに切り替えていなかったときにこのエラーが出ました。 – im3r3k

1

多分あなたの設定上の問題です。 phpmailerの構成の

の例では、このようなものです:

<?php 
require 'class.phpmailer.php'; 

$mail = new PHPMailer; 

$mail->isSMTP();          // Set mailer to use SMTP 
$mail->Host = 'smtp1.example.com;smtp2.example.com'; // Specify main and backup server 
$mail->SMTPAuth = true;        // Enable SMTP authentication 
$mail->Username = 'jswan';       // SMTP username 
$mail->Password = 'secret';       // SMTP password 
$mail->SMTPSecure = 'tls';       // Enable encryption, 'ssl' also accepted 

$mail->From = '[email protected]'; 
$mail->FromName = 'Mailer'; 
$mail->addAddress('[email protected]', 'Josh Adams'); // Add a recipient 
$mail->addAddress('[email protected]');    // Name is optional 
$mail->addReplyTo('[email protected]', 'Information'); 
$mail->addCC('[email protected]'); 
$mail->addBCC('[email protected]'); 

$mail->WordWrap = 50;         // Set word wrap to 50 characters 
$mail->addAttachment('/var/tmp/file.tar.gz');   // Add attachments 
$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name 
$mail->isHTML(true);         // Set email format to HTML 

$mail->Subject = 'Here is the subject'; 
$mail->Body = 'This is the HTML message body <b>in bold!</b>'; 
$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'; 

ここで$ mail->ホストは、SMTPメールサーバーです。通常はsmtpで始まります。

4

@joydesignerさんが非常によく知っているように、SMTP経由で接続するには、hostname, username and passwordを渡す必要があります。その後、接続してメールを送信する必要があります。ここで

$mail->Host = 'smtp1.example.com;smtp2.example.com'; // Specify main and backup server 
$mail->SMTPAuth = true;        // Enable SMTP authentication 
$mail->Username = 'jswan';       // SMTP username 
$mail->Password = 'secret';       // SMTP password 
$mail->SMTPSecure = 'tls';       // tls or ssl connection as req 

私はあなただけで、host情報、plsは同様username & passwordを追加し、一度試す経過している参照してください。

またTLS/SSL PORTは、ご使用のサーバーに開いていることを確認します

チェックをして:

telnet resolver1.opendns.com 25 
関連する問題