PHPmailerを使ってメールを送信しようとしています。
ローカル環境で実行すると送信されます。
サーバー(ロリポップサーバー)に上げるとエラーが出てきます。
PHP
1<?php 2use PHPMailer\PHPMailer\PHPMailer; 3use PHPMailer\PHPMailer\SMTP; 4use PHPMailer\PHPMailer\Exception; 5 6require 'vendor/autoload.php'; 7 8mb_language("japanese"); 9mb_internal_encoding("UTF-8"); 10 11$mail = new PHPMailer(true); 12 13$mail->CharSet = "iso-2022-jp"; 14$mail->Encoding = "7bit"; 15 16try { 17 //サーバの設定 18 $mail->SMTPDebug =3; 19 $mail->Debugoutput = function($str, $level) {echo "debug level $level; message: $str<br>";}; 20 $mail->isSMTP();//SMTP を使用 21 $mail->Host = 'smtp.gmail.com'; 22 $mail->SMTPAuth = true; 23 $mail->Username = 'hogehoge1@gmail.com'; 24 $mail->Password = 'hogehoge'; 25 //ユーザー名・パスワードは合っています。 26 $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; 27 $mail->Port = 587; 28 29 //受信者設定 30 //差出人アドレス, 差出人名 31 $mail->setFrom('hogehoge1@gmail.com', mb_encode_mimeheader('hoge1')); 32 // 受信者アドレス, 受信者名(受信者名はオプション) 33 $mail->addAddress('hogehoge2@gmail.com', mb_encode_mimeheader("hoge2")); 34 //コンテンツ設定 35 $mail->isHTML(true); // HTML形式を指定 36 //メール表題(タイトル) 37 $mail->Subject = mb_encode_mimeheader('テスト'); 38 //本文(HTML用) 39 $mail->Body = mb_convert_encoding('HTML メッセージ <b>BOLD</b>', "JIS", "UTF-8"); 40 //テキスト表示の本文 41 $mail->AltBody = mb_convert_encoding('プレインテキストメッセージ non-HTML mail clients', "JIS", "UTF-8"); 42 43 $mail->send(); //送信 44 echo 'Message has been sent'; 45} catch (Exception $e) { 46 echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}"; 47}
debug level 1; message: SMTP ERROR: Password command failed:
debug level 3; message: SMTP Error: Could not authenticate.
debug level 3; message: SMTP Error: Could not authenticate.
数十行出たあと、3行のエラーが出てきます。
ローカルでは送れています。
送れるようにしたいです。
助言ください。
補足情報(FW/ツールのバージョンなど)
PHP7.4
PHPMailer(Composerで入れたので多分最新版。。。)
あなたの回答
tips
プレビュー