Howdie do,
我有一个非常简单的脚本,只是想通过电子邮件向用户发送确认电子邮件。但是,我一直收到以下错误:
身份验证失败[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]:59845丢失的SMTP连接
答案 0 :(得分: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;
}
}