teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

1

脱字

2020/02/14 21:27

投稿

PonCotsu
PonCotsu

スコア9

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