Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

phpmailer exchange server authentication

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 = "[email protected]";
        $mail->Password = "mypassword";

        $mail->From = "[email protected]";
        $mail->FromName = "My Mail Address";
        $mail->SetFrom("[email protected]", "My Mail Address");

        $mail->AddAddress('[email protected]');

        $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!

like image 869
B. Altan Kocaoglu Avatar asked Nov 24 '22 11:11

B. Altan Kocaoglu


1 Answers

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 = "[email protected]";
  $mail->FromName = "My Mail Address";
  $mail->SetFrom("[email protected]", "My Mail Address");

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

like image 106
Siva Kumar J Avatar answered Dec 07 '22 22:12

Siva Kumar J