phpmailer exchange server authentication

允我心安 提交于 2019-12-07 07:02:58

问题


My mail send code:

    $mail = new PHPMailer(true);
    $mail->IsSMTP();

    try {
        $mail->Host = 192.168.205.19;
        $mail->Port = 25;
        $mail->SMTPDebug  = 2;
        $mail->SMTPSecure = "tls";
        $mail->SMTPAuth = true;
        $mail->Username = "mymailadress@mysite.com";
        $mail->Password = "mypassword";

        $mail->From = "mymailaddress@mysite.com";
        $mail->FromName = "My Mail Address";
        $mail->SetFrom("mymailaddress@mysite.cm", "My Mail Address");

        $mail->AddAddress('toaddress@mysite.com');

        $mail->Subject = "Test for subject";
        $mail->MsgHTML("Test my mail body");

        if ($mail->Send()) {
            $result = 1;
        } else {
            $result = "Error: " . $mail->ErrorInfo;
        }
    } catch (phpmailerException $e) {
        $result = $e->errorMessage();
    } catch (Exception $e) {
        $result = $e->getMessage();
    }

    return $result;

Result?

SMTP -> FROM SERVER:220 evo.callpex.int Microsoft ESMTP MAIL Service ready at Tue, 27 Nov 2012 17:45:24 +0200 
SMTP -> ERROR: Password not accepted from server: 535 5.7.3 Authentication unsuccessful 

I'm using PHPMailer class for sent mail. And SMTP. I'm connecting to Exchange Mail server. But I have this error.

Why?

Thanks!


回答1:


May be you are using Administrator credentials. Don't know why but even I was not able to send mail using PHPMailer with admin credentials(There may be some security measures applicable for Administrator details). Try giving any other user credentials, it will work. It works for me with other user credentials.

And, In your code

  $mail->From = "mymailaddress@mysite.com";
  $mail->FromName = "My Mail Address";
  $mail->SetFrom("mymailaddress@mysite.cm", "My Mail Address");

$mail->SetFrom("mailid","name") itself will set From & FromName values. You no need to set that again.



来源:https://stackoverflow.com/questions/13587983/phpmailer-exchange-server-authentication

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!