社内でMicrosoft365を使用する事となり、メールもoutlookを使用する事となるので、
今までありました、メールサーバーが無くなります。
社内のPHPのシステムから、メールを送信する処理をMicrosoft365を利用したメール送信に置き換える
作業をしていまして、詰まっております。
ソースコードとしては、
<?php // PHPMailerを読み込む use PHPMailer\PHPMailer\PHPMailer; use PHPMailer\PHPMailer\Exception; use PHPMailer\PHPMailer\SMTP; require './PHPMailer/PHPMailer/src/PHPMailer.php'; require './PHPMailer/PHPMailer/src/Exception.php'; require './PHPMailer/PHPMailer/src/SMTP.php'; // PHPMailerのインスタンスを作成する $mail = new PHPMailer(true); try { // SMTP設定 //Office365 認証情報 $host = 'smtp.office365.com'; $username = '********************'; $password = '************'; //差出人 $from = '*********'; $fromname = '******'; //宛先 $to = '******************'; $toname = '*************'; //件名・本文 $subject = '件名'; $body = '本文'; $mail->isSMTP(); $mail->SMTPDebug = 2; $mail->SMTPAuth = true; $mail->Host = $host; $mail->Username = $username; $mail->Password = $password; $mail->SMTPSecure = 'tls'; $mail->Port = 587; $mail->CharSet = "utf-8"; $mail->Encoding = "base64"; $mail->setFrom($from, $fromname); $mail->addAddress($to, $toname); $mail->Subject = $subject; $mail->Body = $body; // メール送信 $mail->send(); echo 'Message has been sent'; } catch (Exception $e) { echo '失敗: ', $mail->ErrorInfo; } ?>
となりまして、
エラーメッセージは
SERVER -> CLIENT: 535 5.7.139 Authentication unsuccessful, SmtpClientAuthentication is disabled for the Tenant. Visit https://aka.ms/smtp_auth_disabled for more information.
SMTP ERROR: Password command failed: 535 5.7.139 Authentication unsuccessful, SmtpClientAuthentication is disabled for the Tenant. Visit https://aka.ms/smtp_auth_disabled for more information.
SMTP Error: Could not authenticate.
となります。
調査ですが、
SMTP認証をオフになっていたのをオンにするとの事で、オンにしてみましたが、上手くいかず、
難航しております。
ご存知の方がおられましたら、ご教示いただけますと幸いです。
よろしくお願いいたします。

回答1件
あなたの回答
tips
プレビュー