質問編集履歴

1

脱字

2020/02/14 21:27

投稿

PonCotsu
PonCotsu

スコア9

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