0

I'm using PHPMailer to send emails using my outlook email but I keep getting this error

Message could not be sent. Mailer Error:
"The following From address failed: xxxxx@xxxxx.onmicrosoft.com : 
MAIL FROM command failed,Client not authenticated to send mail. [
xxxxxx.namprd13.prod.outlook.com 2023-07-14T21:47:08.967Z 08DB842E797B0C23]\r\n,530,5.7.57SMTP server error: MAIL FROM command failed Detail: Client not authenticated to send mail. 
[xxxx.namprd13.prod.outlook.com 2023-07-14T21:47:08.967Z 08DB842E797B0C23]\r\n SMTP code: 530 Additional SMTP info: 5.7.57SMTP server error: 
MAIL FROM command failed Detail: Client not authenticated to send mail. 
[xxxxxx.namprd13.prod.outlook.com 2023-07-14T21:47:08.967Z 08DB842E797B0C23]\r\n SMTP code: 530 Additional SMTP info: 5.7.57"

I am using a sandbox outlook email which might be the issue but highly doubt it since I was able to send a message using ms-graph-sdk

This is my code:

try {
    //Server settings
    $mail->SMTPDebug  = SMTP::DEBUG_SERVER;
    $mail->Host       = 'smtp-mail.outlook.com'; //smtp.office365.com:587
    $mail->Username   = 'xxxx@xxxx.onmicrosoft.com';
    $mail->Password   = 'xxxxxxxxxx';
    $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
    $mail->Port       = 587;
    $mail->isSMTP();
    //$mail->SMTPAuth   = true;

    //Recipients
    $mail->setFrom('xxxx@xxxxxxx.onmicrosoft.com', 'Mailer');
    $mail->addAddress('myaddress@gmail.com');

    //Content
    $mail->isHTML(true);
    $mail->Subject = 'Here is the subject';
    $mail->Body    = 'This is the HTML message body <b>in bold!</b>';
    $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

    if (! $response = $mail->send()) {
        Log::info('Message could not be sent.');
        Log::info('Mailer Error: ' . json_encode($mail->ErrorInfo));
        exit;
    } else {
        echo 'Message of Send email using Outlook SMTP server has been sent';
    }
    echo 'Message has been sent';
}
catch (Exception $e) {
    Log::info("Message could not be sent. Mailer Error:" . json_encode($mail->ErrorInfo));
}

I tried the 3 solutions offered here https://stackoverflow.com/a/68312304/2609521 but they didn't work.
1.enter image description here

2. enter image description here

3.enter image description here

MalcolmInTheCenter
  • 1,376
  • 6
  • 27
  • 47
  • This is not a programming question, but purely an SMTP configuration that you run. Get your SMTP setup in order, verify it (e.g. http://jetmore.org/john/code/swaks/installation.html) and then configure PHPMailer according to the docs. – hakre Jul 14 '23 at 22:48
  • I'm fairly sure you can no longer send through Outlook using regular password auth; you need to configure XOAUTH2. Unfortunately it's tricky and unreliable (thanks Microsoft), but there is [a setup guide for PHPMailer](https://github.com/PHPMailer/PHPMailer/wiki/Microsoft-Azure-and-XOAUTH2-setup-guide), and some [background discussion of it](https://github.com/PHPMailer/PHPMailer/issues/2116). – Synchro Jul 15 '23 at 00:41
  • The issue is here: _"Detail: Client not authenticated to send mail."_. Fix your authentication. – Tangentially Perpendicular Jul 15 '23 at 00:42
  • 2
    You should pause for a second and think about what you're doing. You're currently _disabling security features_ that helps you protect your email service, just to be able to use SMTP with PHP. That's the wrong approach. If it worked with their graph sdk, why not use that method instead? – M. Eriksson Jul 15 '23 at 00:56

0 Answers0