php邮件不工作。邮件错误

时间:2013-12-06 14:53:20

标签: php smtp phpmailer

我无法使用php邮件程序类发送电子邮件。这是我得到的错误。

错误

  

邮件程序错误:以下发件人地址失败:admin@mobilebitzltd.com:调用Mail()而未连接。

这是我正在使用的代码。

$mail = new PHPMailer();
$mail->IsSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.live.com'; // Specify main and backup server
$mail->Port = '465';
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'admin@mydoamin.com'; // SMTP username
$mail->Password = 'sdf'; // SMTP password
$mail->SetFrom($from, $from);
$mail->AddReplyTo($from, $from);
$mail->Subject = $subject;
$mail->MsgHTML($message);
$address = $to;
$mail->AddAddress($address, $customer_name);

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

2 个答案:

答案 0 :(得分:0)

我建议将整个邮件进程放入try / catch块,以获取有关错误的更多信息,作为一个好的起点。异常中可能有更多细节可以帮助查明问题。

try {
    $mail->SetFrom($from, $from);
    ...
    ...
    $mail->Send();
} catch ( phpmailerException $e ) {
    echo $e->errorMessage(); 
} catch ( Exception $e ) {
    echo $e->getMessage(); 
}

我发现了另一个可能值得关注的帮助问题:Having trouble with PHPMailer

最重要的是,我认为重要的是有人指出你刚刚在互联网上发布了纯文字密码。您可能希望尽快更改无处不在

答案 1 :(得分:0)

添加

$mail->SMTPDebug = 1; 

获取有关出错的更多信息。

然后尝试

$mail = new PHPMailer; 

在顶部。