2011-12-28 10 views
0

PHPMailerクラスを使用してSMTP経由でメールを送信しようとしています。私の問題は、最初の試みのため、メールの送信者はoerfect取り組んでいるが、それはエラーを投げ、後続のすべての試行のために:phpmailerが断続的なエラーをスローする:接続されているかどうかを確認中にEOFが見つかりました

SMTP -> NOTICE: 
    EOF caught while checking if connected 

コードを送信する私の電子メールには、次のとおりです。

function sendEmail($toAddress,$fromAddress,$toName,$fromName,$subject,$emailContent,$content_type = false, $attach_path="", $cc = '', $cc_name="") 
{ 
     require_once('phpmailer/class.phpmailer.php'); 
     if (empty($content_type)) $content_type = false; 
     $mail = new PHPMailer(); 
     $mail->IsSMTP();   // set mailer to use SMTP 
     $mail->SMTPAuth = MY_SMTP_AUTH;  // turn on SMTP authentication 
     $mail->Host = MY_SMTP_HOST_NAME; 

     if (!empty($this->smtpEncryptionMode)) 
     { 
       $mail->SMTPSecure= $this->smtpEncryptionMode; 
     } 
     if (!empty ($this->smtpPort)) 
     { 
       $mail->Port = MY_SMTP_PORT; 
     } 
     else $mail->Port = 25; 
     $mail->Username = $this->smtpUserName; 
     $mail->Password = $this->smtpUserPassword; 
     $mail->From  =$fromAddress; 
     $mail->FromName = $fromName; 

      if(is_array($toAddress)) 
       { 
         foreach($toAddress as $to) 
         { 
           $mail->AddAddress($to, ""); 
         } 
       } 
       else 
       { 
     $mail->AddAddress($toAddress, $toName); 
       } 
     $mail->AddReplyTo($fromAddress, $fromName); 
     $mail->CharSet = 'UTF-8'; 
     $mail->WordWrap = 80; // set word wrap to 80 characters 
     $mail->IsHTML($content_type); // set email format to basic 
     $mail->Subject = $subject; 
     $mail->Body = $emailContent; 
     //Here it sets other parameters e.g attachment path etc. 
     $mail->SMTPDebug = true; 
     $result = $mail->Send(); 
     if($result == false) { $result = $mail->ErrorInfo;echo $result; }// Switch this on when debugging. 
     return $result; 

なぜそれが投げていますすべての連続した試行でエラー?

私はclass.smtp.phpから推測することができるものから、それは実際にsmtp_connectionインスタンスのソケットの状態をチェックする()接続された機能の内側に失敗している、そしてそこにそれがEOFを取得しているということです。

接続自体は確立されていないと思います...しかし、最初のインスタンスではどうなっていますか?

答えて

0

関数はwhileループであり、そうであればクラスを閉じる必要があります。簡単にこれを試すことがあります。

あなたは(test_mailを呼び出す例えば一度にインスタンスをメールに送信することはできません
$result = $mail->Send(); 
$mail->close(); 
+0

私は** $ mail-> SmtpClose()**を使用してみましたが、それはSMTPサーバ側の問題ではwork.Couldませんでしたか?それをどのように確認できますか? – debaShish

0

)、その後、Emailerの()関数test_mailは、他の機能はphpmailerのを使用しながら、別の接続を使用し、ポート465に接続されている今、Emailerのだろう最初の関数の接続がまだ終了していないため、EOFエラーが発生します。

/*function test_mail(){ 
    $to = '[email protected]'; 
    $subject = 'Test email using PHP'; 
    $message = 'This is a test email message'; $headers = 'From: [email protected]' . "\r\n" . 'Reply-To: [email protected]' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); mail($to, $subject, $message, $headers, '[email protected]'); 

}*/ 

function emailer($sendby,$subject,$body,$sendto,$cc){ 
    require("../obj/PHPMailer-master/class.phpmailer.php"); 

    $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->Host = "relay-hosting.secureserver.net"; 
    $mail->Port = 25;       // or 587 or 465 

    /* 
    $mail->SMTPAuth = true;      // authentication enabled 
    $mail->Host = "smtpout.secureserver.net"; 
    $mail->Port = 465;      // or 587 or 465 
    */ 

    //var_dump($mail);exit(); 
    $mail->IsHTML(true);      // sends email as html 
    $mail->Username = MAILER_USERNAME; // mailserver username 
    $mail->Password = MAILER_PASSWORD;    // mailserver password 
    $mail->SetFrom("[email protected]");     // Seen as message from 
    $mail->Subject = $subject;     // Subject of the message 
    $mail->Body = $body;      // email body - can be html 
    $mail->AddAddress($sendto);     // where email will be sent 
    $mail->addCC($cc); 

    if(!$mail->Send()){ 
     return "Mailer Error: "; // . $mail->ErrorInfo 
    } 
    else{ 
     return "Message has been sent"; 
     $mail->close(); 
    } 
} 
関連する問題