PHP7でメール送信機能を作りたいと考えております。
ロリポップのSMTPサーバーとPHPMailer(6系)を使ってメール送信をしたいのですが、
PHPMailerのReadMeの例を読んで、その通りにやって ロリポップFTPサーバーにあげてURLを読み込んでみてもメールが送られずエラーが表示されます。
どこの情報が足りないのか(あるいはそもそも間違っているのか)、よくわからないので教えてくれると嬉しいです。
スクリプトにおいてはコメント欄に僕の疑問点が書いてあります。回答で答えてくれると助かります。
PHP
1 2 3<?php 4// Import PHPMailer classes into the global namespace 5// These must be at the top of your script, not inside a function(ここはなんのために?) 6use PHPMailer\PHPMailer\PHPMailer; 7use PHPMailer\PHPMailer\SMTP; 8use PHPMailer\PHPMailer\Exception; 9 10 11 12//サンプルサイトをみているとここに、requireもしくはrequire_onceでここにException.php, OAuth.php, PHPMailer.php, POP3.php, SMTP.php,phpmailer.lang-ja.phpを読み込んでいる。 13require_once('PHPMailer/src/SMTP.php'); 14require_once('PHPMailer/src/OAuth.php'); 15require_once('PHPMailer/src/Exception.php'); 16require_once('PHPMailer/src/POP3.php'); 17require_once('PHPMailer/src/PHPMailer.php'); 18require_once('PHPMailer/language/phpmailer.lang-ja.php'); 19 20 21 22// Load Composer's autoloader 23// require 'vendor/autoload.php'; //autoload.phpがどこにも見つからないのはなぜ...?ダウンロードしたコンテンツ内になかったのでコメント化しないとページがそもそも開けませんでした 24 25// Instantiation and passing `true` enables exceptions 26$mail = new PHPMailer(true); 27 28try { 29 //Server settings 30 $mail->SMTPDebug = SMTP::DEBUG_SERVER; // Enable verbose debug output 31 $mail->isSMTP(); // Send using SMTP 32 $mail->Host = 'smtp.lolipop.jp'; // Set the SMTP server to send through(ロリポップSMTPサーバー) 33 $mail->SMTPAuth = true; // Enable SMTP authentication 34 $mail->Username = 'xxx@xxxx.jp'; // SMTP username(ロリポップのSMTPサーバーのメールアカウント) 35 $mail->Password = '********'; // SMTP password(メールアカウントのパスワード) 36 $mail->SMTPSecure = 'ssl'; // Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` also accepted(ssl接続) 37 $mail->Port = 465; // TCP port to connect to(ポート番号) 38 39 //Recipients 40 $mail->setFrom('xxx@xxxx.jp', 'Mailer'); //送信元のアドレスと送信者名(この場合、ロリポップのwebメールアドレス?) 41 $mail->addAddress('xxxxx@gmail.com', 'Joe User'); // Add a recipient(送信先と受信者名。この場合、Gmailアドレス?) 42 // $mail->addAddress('ellen@example.com'); // Name is optional(追加で送りたいアドレス) 43 // $mail->addReplyTo('info@example.com', 'Information'); 44 // $mail->addCC('cc@example.com'); 45 // $mail->addBCC('bcc@example.com'); 46 47 // Attachments 48 // $mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments 49 // $mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name 50 51 // Content 52 $mail->isHTML(true); // Set email format to HTML(ここはよくわからない。) 53 $mail->Subject = 'Here is the subject'; 54 $mail->Body = 'This is the HTML message body <b>in bold!</b>'; 55 $mail->AltBody = 'This is the body in plain text for non-HTML mail clients'; 56 57 $mail->send(); //Webページに訪れた際に送信に成功したら'Messaga has been sent'が表示され、失敗したら'"Message could not be sent. Mailer Error: {$mail->ErrorInfo}"が表示される。' 58 echo 'Message has been sent'; 59} catch (Exception $e) { 60 echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}"; 61} 62
エラーは以下のように出ました。(メールアドレスの部分だけは伏せておきました。)
2020-02-14 21:14:18 SERVER -> CLIENT: 220 smtp-proxy001.phy.lolipop.jp LOLIPOP-Fsecure
2020-02-14 21:14:18 CLIENT -> SERVER: EHLO xxx@xxxx.jp(メールアドレス)
2020-02-14 21:14:18 SERVER -> CLIENT: 250-smtp-proxy001.phy.lolipop.jp Hi smtp-proxy001.phy.lolipop.lan [172.19.44.42]250-8BITMIME250-AUTH PLAIN LOGIN250 SIZE 102400000
2020-02-14 21:14:18 CLIENT -> SERVER: AUTH LOGIN
2020-02-14 21:14:18 SERVER -> CLIENT: 334 VXNlcm5hbWU6
2020-02-14 21:14:18 CLIENT -> SERVER: [credentials hidden]
2020-02-14 21:14:18 SERVER -> CLIENT: 334 UGFzc3dvcmQ6
2020-02-14 21:14:18 CLIENT -> SERVER: [credentials hidden]
2020-02-14 21:14:18 SERVER -> CLIENT: 535 Authentication failed for xxx@xxxx.jp(メールアドレス) - authsql/login - wrong password
2020-02-14 21:14:18 SMTP ERROR: Password command failed: 535 Authentication failed for xxx@xxxx.jp(メールアドレス) - authsql/login - wrong password
SMTP Error: Could not authenticate.
2020-02-14 21:14:18 CLIENT -> SERVER: QUIT
2020-02-14 21:14:18 SERVER -> CLIENT: 221 smtp-proxy001.phy.lolipop.jp closing connection. Have a wonderful day.
SMTP Error: Could not authenticate.
Message could not be sent. Mailer Error: SMTP Error: Could not authenticate.
回答2件
あなたの回答
tips
プレビュー