phpmailer smtp无法正常工作

时间:2012-05-14 09:49:58

标签: php email smtp phpmailer smtp-auth

我已经尝试了很长一段时间了,我无法让phpmailer使用smtp。 我一直在这里测试http://smtper.sweetylife.com/,看看我的smtp是否正常工作,在这个网站上我可以毫无问题地连接。 我的phpmailer设置是:

    $mail   = new PHPMailer();
    $mail->IsSMTP(); // telling the class to use SMTP
    $mail->Host       = "mail.mydomain.com"; // SMTP Server
    $mail->SMTPDebug  = 2; // Debugmode
    $mail->SMTPAuth   = true; // enable SMTP authentication
    $mail->SMTPSecure = "tls";
    $mail->Port       = 587; // set the SMTP port for the GMAIL
    $mail->Username   = "administratie@mydomain.com"; // SMTP account username
    $mail->Password   = "password";        // SMTP account password
    //$mail->SetFrom("administratie@mydomain.com", "First Last");
    $mail->AddReplyTo("administratie@mydomain.com","First Last");
    $mail->Subject    = "PHPMailer Test Subject via smtp, basic with authentication";
    //$mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
    $mail->Body       = "demo mail";
    $address = "re@ceiv.ed";
    $mail->AddAddress($address, "John Doe");
    if(!$mail->Send()) {
        echo "Mailer Error: " . $mail->ErrorInfo;
    }
    else{
        echo "Message sent!";
    }

但它不起作用。 我收到以下错误:

SMTP -> FROM SERVER: 220 helios.web.xyn-ta.net ESMTP Exim 4.77 Mon, 14 May 2012 11:47:16 +0200
SMTP -> FROM SERVER: 250 helios.web.xyn-ta.net Hello localhost.localdomain [77.243.225.73]
SMTP -> FROM SERVER: 250 OK
SMTP -> FROM SERVER: 550 relay not permitted, authentication required
SMTP -> ERROR: RCPT not accepted from server: 550 relay not permitted, authentication required
SMTP -> FROM SERVER: 503-All RCPT commands were rejected with this error:
503-relay not permitted, authentication required
503 valid RCPT command must precede DATA
SMTP -> ERROR: DATA command not accepted from server: 503-All RCPT commands were rejected with this error:
503-relay not permitted, authentication required
503 valid RCPT command must precede DATA
SMTP -> FROM SERVER: 221 helios.web.xyn-ta.net closing connection
Mailer Error:

我不知道我做错了什么,有没有人有解决方法来解决这个问题?

1 个答案:

答案 0 :(得分:1)

这一行是问题所在:

SMTP -> FROM SERVER: 550 relay not permitted, authentication required

您的邮件服务器需要登录,并且您提供的密码凭据未被接受。您应该与邮政局长联系并确保您拥有正确的用户名和密码。

如果失败,请尝试使用脚本中的详细信息从命令行登录SMTP服务器,看看是否会产生任何错误。