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.
2.
3.