0

你好,

我有一个非常简单的脚本,它只是假设通过电子邮件向用户发送确认电子邮件。但是,我不断收到以下错误:

身份验证失败 [SMTP:无法写入套接字:未连接(代码:250,响应:Hello localhost [127.0.0.1] SIZE 52428800 8BITMIME PIPELINING AUTH PLAIN LOGIN STARTTLS HELP)]

脚本如下。梨邮件已安装。是的,密码是正确的,但我没有把它放在这里的脚本中。以前有人见过这个错误吗?

function send_email($from, $to, $subject, $body)
{
  require_once "Mail.php";
  global $debug;

  $host = "localhost";
  $username = "user";
  $password = "*********";
  $headers = array
 (
  'From' => $from,
  'To' => $to,
  'Subject' => $subject
 );

 $smtp = Mail::factory
 (
  'smtp',
  array
  (
   'host' => $host,
   'auth' => true,
   'username' => $username,
   'password' => $password
   )
 );

 $mail = $smtp->send($to, $headers, $body);

 if (PEAR::isError($mail) && $debug)
 {
   echo("<p>" . $mail->getMessage() . "</p>");
 }

}

编辑:

exim_mainlog 实际上是在调用通过时显示的:

2013-09-06 15:50:51 来自 [127.0.0.1] 的 SMTP 连接:59845(TCP/IP 连接计数 = 1) 2013-09-06 15:50:51 来自 localhost [127.0.0.1] 的 SMTP 连接:59845丢失的

4

1 回答 1

0

好的,所以我完全放弃了 Pear::Mail,只是将整个脚本转换为 PHP_Mailer。

它现在可以正常工作

 function send_email($from, $to, $subject, $body)
 {
   ini_set("include_path", ".:/home/user/public_html/PHPMailer_v2.0.4/");
   require_once("class.phpmailer.php");
   global $debug;
   $mailer= new PHPMailer();
   $mailer->IsSMTP();
   $mailer->Host = 'localhost';
   $mailer->SMTPAuth = true;

   $mailer->Username = "email";
   $mailer->Password = "*******";

   $mailer->FromName = "User";
   $mailer->From = "email";
   $mailer->AddAddress($to);
   $mailer->Subject = $subject;

   $mailer->Body = $body;

   if(!$mailer->Send())
   {
     //echo "Message was not sent";
     echo "Mailer Error: " . $mailer->ErrorInfo;
     exit;
   }
 }
于 2013-09-07T19:16:44.630 回答