質問編集履歴

3

質問、コードの変更

2020/08/21 12:26

投稿

退会済みユーザー
test CHANGED
@@ -1 +1 @@
1
- localhostから電子メールをemail.htmlの<form>からemail.phpを使ってGmailに送って表示したい
1
+ localhostからGmailにメールを送って表示したい
test CHANGED
@@ -1,373 +1,185 @@
1
- localhostから電子メールをemail.htmlの<form>からemail.phpを使ってGmailに送って表示したい。
2
-
3
- 一応送信は出来る状態なのですが、表示はemail.phpに設定した$body="hellooooo";です。
4
-
5
- これを<form>から送られたメッセージを表示したいのですが、どうすればいいかわからないので、
6
-
7
- ヒント、もしくは修正の仕方を教えてください。
8
-
9
- email.phpコードはgmailに送信出来るようにurlドを修正しています。
1
+ swiftmailerを使って以下設定で実行するとエラが出ます。
10
-
11
- email.phpコードの5行目、6行目の
12
-
13
- //$mail = $_REQUEST["email"] ;
14
-
15
- //$message = $_REQUEST["message"] ;
16
-
17
- を使って<form>から送られたメッセージを表示したいのです。
18
-
19
- よろしくお願いいたします。
20
2
 
21
3
 
22
4
 
23
- ```html
5
+ $message
24
6
 
25
- //email.html
7
+ ->setCharset('iso-2022-jp')
8
+
9
+ ->setEncoder(Swift_Encoding::get7BitEncoding()) // 52行目、エラー
26
10
 
27
11
 
28
12
 
29
- <!-- https://living-sun.com/ja/php/668969-mailer-error-smtp-connect-failed-in-php-mailer-https-githubcom-phpmailer-phpmailer-wiki-troubleshooting-duplicate-php-email-phpmailer.html -->
13
+ ここの行がどうしても解決できないのでヒント、助言をお願いいたします。
30
14
 
31
- <form method="post" action="email.php">
15
+ いろいろ使っているプラグインもあると思いますが、XAMPPを使っています。
16
+
17
+ 書かなければならないファイルなどや。バージョンがあったら教えてください。
18
+
19
+ お願いいたします。
32
20
 
33
21
 
34
22
 
23
+ ```
24
+
25
+ // swiftmailer5_4.php
26
+
27
+ <?php
28
+
35
- Email: <input name="email" id="email" type="text" /><br />
29
+ // https://php-archive.net/php/swift-mailer/ 参照
30
+
31
+ // https://stackoverrun.com/ja/q/12418106   参照
36
32
 
37
33
 
38
34
 
39
- Message:<br />
35
+ require 'vendor/autoload.php';
40
36
 
37
+
38
+
39
+ // アカウントの設定
40
+
41
+ $config = array(
42
+
43
+ 'host' => 'smtp.gmail.com',
44
+
45
+ 'port' => 587,
46
+
47
+ 'user' => 'sanchunaka@gmail.com',
48
+
49
+ 'pass' => '6BeKxxx',
50
+
51
+ 'encryption' => 'tls'
52
+
53
+ );
54
+
55
+
56
+
57
+ // メールの内容
58
+
59
+ $subject = '件名です';
60
+
61
+ $body = '本文です';
62
+
63
+ $from = array('sanchunaka@gmail.com' => '送信者名');
64
+
65
+ $to = array('sanchunaka@gmail.com' => '受信者名');
66
+
67
+
68
+
69
+ // 日本語に関する初期設定
70
+
71
+ Swift::init(function () {
72
+
73
+ Swift_DependencyContainer::getInstance()
74
+
75
+ ->register('mime.qpheaderencoder')
76
+
77
+ ->asAliasOf('mime.base64headerencoder');
78
+
79
+ Swift_Preferences::getInstance()->setCharset('iso-2022-jp');
80
+
81
+ });
82
+
83
+
84
+
85
+ // SMTP サーバーとの接続設定
86
+
87
+ /** @var \Swift_SmtpTransport $transport */
88
+
41
- <textarea name="message" id="message" rows="15" cols="40"></textarea><br />
89
+ $transport = new Swift_SmtpTransport('smtp.gmail.com', 587, 'tls');
42
90
 
43
91
 
44
92
 
45
- <input type="submit" value="Submit" />
93
+ $transport->setUsername($config['user'])->setPassword($config['pass']);
94
+
95
+
96
+
97
+ $mailer = new Swift_Mailer($transport);
98
+
99
+ //$mailer = Swift_Mailer::newInstance($transport);
100
+
101
+
102
+
103
+ $mailer->options = array (
104
+
105
+ 'ssl' => array(
106
+
107
+ 'verify_peer' => false,
108
+
109
+ 'verify_peer_name' => false,
110
+
111
+ 'allow_self_signed' => true));
46
112
 
47
113
 
48
114
 
49
- </form>
115
+
50
116
 
51
- ```
117
+ // メールの作成
118
+
119
+ $message = new Swift_Message($subject);
52
120
 
53
121
 
54
122
 
55
- ```php
123
+ $message
56
124
 
125
+ ->setCharset('iso-2022-jp')
126
+
127
+ ->setEncoder(Swift_Encoding::get7BitEncoding())
128
+
129
+ ->setSubject($subject)
130
+
131
+ ->setFrom($from)
132
+
133
+ ->setTo($to)
134
+
135
+ ->setBody($body);
136
+
137
+
138
+
57
- //email.php
139
+ // 送信
140
+
141
+ $result = $mailer->send($message);
58
142
 
59
143
 
60
144
 
61
- <?php
145
+ /* 実行結果
62
146
 
63
- // https://living-sun.com/ja/php/668969-mailer-error-smtp-connect-failed-in-php-mailer-・・// https-githubcom-phpmailer-phpmailer-wiki-troubleshooting-duplicate-php-email-pmailer.html
147
+ hiroko@HIROKO711 C:\xampp\htdocs\SwiftMailer_proj\mailer5
64
148
 
149
+ # php src/swiftmailer5_4.php
150
+
151
+ PHP Fatal error: Uncaught Error: Class 'Swift_Encoding' not found in C:\xampp\h
152
+
153
+ tdocs\SwiftMailer_proj\mailer5\src\swiftmailer5_4.php:52
154
+
65
- namespace MyApp;
155
+ Stack trace:
156
+
157
+ #0 {main}
158
+
159
+ thrown in C:\xampp\htdocs\SwiftMailer_proj\mailer5\src\swiftmailer5_4.php on l
160
+
161
+ ine 52
66
162
 
67
163
 
68
164
 
69
- //$mail = $_REQUEST["email"] ;
165
+ Fatal error: Uncaught Error: Class 'Swift_Encoding' not found in C:\xampp\htdocs
70
166
 
71
- //$message = $_REQUEST["message"] ;
167
+ \SwiftMailer_proj\mailer5\src\swiftmailer5_4.php:52
72
168
 
73
- //var_dump ($mail);
169
+ Stack trace:
74
170
 
75
- //var_dump ($message);
171
+ #0 {main}
76
172
 
173
+ thrown in C:\xampp\htdocs\SwiftMailer_proj\mailer5\src\swiftmailer5_4.php on l
77
174
 
78
-
79
- use PHPMailer\PHPMailer\PHPMailer;
80
-
81
- use PHPMailer\PHPMailer\Exception;
82
-
83
-
84
-
85
- //Load Composer's autoloader
86
-
87
- require 'C:\xampp\htdocs\phpmailer\vendor/autoload.php';
88
-
89
-
90
-
91
- $mail = new PHPMailer(true); // Passing `true` enables exceptions
92
-
93
-
94
-
95
- $mail->SMTPOptions = array(
96
-
97
- 'ssl' => array(
98
-
99
- 'verify_peer' => false,
100
-
101
- 'verify_peer_name' => false,
102
-
103
- 'allow_self_signed' => true
104
-
105
- )
106
-
107
- );
108
-
109
-
110
-
111
- echo "\n";
112
-
113
- //Server settings
114
-
115
- $mail->SMTPDebug = 2;
116
-
117
-
118
-
119
- $mail->isSMTP(); // Set mailer to use SMTP
120
-
121
-
122
-
123
- $mail->Host = "smtp.gmail.com";
124
-
125
-
126
-
127
- $mail->SMTPAuth = true; // turn on SMTP authentication
128
-
129
-
130
-
131
- $mail->Username = "sanchunaka@gmail.com"; // SMTP username
132
-
133
-
134
-
135
- $mail->Password = "xxxFi9x"; // SMTP password
136
-
137
-
138
-
139
- $mail->SMTPSecure = "tls";
140
-
141
-
142
-
143
- $mail->Port = 587;
144
-
145
-
146
-
147
- $mail->AddAddress("sanchunaka@gmail.com","taturou nakamura");
148
-
149
-
150
-
151
- $mail->SetFrom("sanchunaka@gmail.com","taturou nakamura");
152
-
153
-
154
-
155
- $mail->WordWrap = 50;
156
-
157
-
158
-
159
- $mail->isHTML(true);
160
-
161
-
162
-
163
- $mail->Subject = "You have received feedback from your website!";
164
-
165
-
166
-
167
- $body="hellooooo";
168
-
169
-
170
-
171
- $mail->MsgHTML($body);
172
-
173
-
174
-
175
- if(!$mail->Send()){
176
-
177
-
178
-
179
- echo "Message could not be sent. <p>";
180
-
181
-
182
-
183
- echo "Mailer Error: " . $mail->ErrorInfo;
184
-
185
-
186
-
187
- exit;
188
-
189
-
190
-
191
- }
192
-
193
-
194
-
195
- echo "Message has been sent";
196
-
197
-
198
-
199
- /* 実行結果 正常動作
200
-
201
- hiroko@HIROKO711 C:\xampp\htdocs\php_mailer
202
-
203
- # php src/email.php
204
-
205
- 2020-07-31 12:41:57 SERVER -> CLIENT: 220 smtp.gmail.com ESMTP h4sm1066901pg
206
-
207
- q.9 - gsmtp
208
-
209
- 2020-07-31 12:41:57 CLIENT -> SERVER: EHLO hiroko711
210
-
211
- 2020-07-31 12:41:57 SERVER -> CLIENT: 250-smtp.gmail.com at your service, [1
212
-
213
- 26.169.48.171]
214
-
215
- 250-SIZE 35882577
216
-
217
- 250-8BITMIME
218
-
219
- 250-STARTTLS
220
-
221
- 250-ENHANCEDSTATUSCODES
222
-
223
- 250-PIPELINING
224
-
225
- 250 SMTPUTF8
226
-
227
- 2020-07-31 12:41:57 CLIENT -> SERVER: STARTTLS
228
-
229
- 2020-07-31 12:41:57 SERVER -> CLIENT: 220 2.0.0 Ready to start TLS
230
-
231
- 2020-07-31 12:41:58 CLIENT -> SERVER: EHLO hiroko711
232
-
233
- 2020-07-31 12:41:58 SERVER -> CLIENT: 250-smtp.gmail.com at your service, [1
234
-
235
- 26.169.48.171]
236
-
237
- 250-SIZE 35882577
238
-
239
- 250-8BITMIME
240
-
241
- 250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLI
242
-
243
- ENTTOKEN OAUTHBEARER XOAUTH
244
-
245
- 250-ENHANCEDSTATUSCODES
246
-
247
- 250-PIPELINING
248
-
249
- 250 SMTPUTF8
250
-
251
- 2020-07-31 12:41:58 CLIENT -> SERVER: AUTH LOGIN
252
-
253
- 2020-07-31 12:41:58 SERVER -> CLIENT: 334 VXNlcm5hbWU6
254
-
255
- 2020-07-31 12:41:58 CLIENT -> SERVER: [credentials hidden]
256
-
257
- 2020-07-31 12:41:58 SERVER -> CLIENT: 334 UGFzc3dvcmQ6
258
-
259
- 2020-07-31 12:41:58 CLIENT -> SERVER: [credentials hidden]
260
-
261
- 2020-07-31 12:41:58 SERVER -> CLIENT: 235 2.7.0 Accepted
262
-
263
- 2020-07-31 12:41:58 CLIENT -> SERVER: MAIL FROM:<anchunaka@gmail.com>
264
-
265
- 2020-07-31 12:41:59 SERVER -> CLIENT: 250 2.1.0 OK h4sm1066901pgq.9 - gsmtp
266
-
267
- 2020-07-31 12:41:59 CLIENT -> SERVER: RCPT TO:<anchunaka@gmail.com>
268
-
269
- 2020-07-31 12:41:59 SERVER -> CLIENT: 250 2.1.5 OK h4sm1066901pgq.9 - gsmtp
270
-
271
- 2020-07-31 12:41:59 CLIENT -> SERVER: DATA
272
-
273
- 2020-07-31 12:41:59 SERVER -> CLIENT: 354 Go ahead h4sm1066901pgq.9 - gsmtp
274
-
275
-
276
-
277
- 2020-07-31 12:41:59 CLIENT -> SERVER: Date: Fri, 31 Jul 2020 14:41:57 +0200
278
-
279
- 2020-07-31 12:41:59 CLIENT -> SERVER: To: taturou nakamura <anchunaka@gmail.
280
-
281
- com>
282
-
283
- 2020-07-31 12:41:59 CLIENT -> SERVER: From: taturou nakamura <anchunaka@gmai
284
-
285
- l.com>
286
-
287
- 2020-07-31 12:41:59 CLIENT -> SERVER: Subject: You have received feedback fr
288
-
289
- om your website!
290
-
291
- 2020-07-31 12:41:59 CLIENT -> SERVER: Message-ID: <1q1hKQR6FprjUIdsqzX1aud7x
292
-
293
- s82ZRbFpVMCf7eAmw@hiroko711>
294
-
295
- 2020-07-31 12:41:59 CLIENT -> SERVER: X-Mailer: PHPMailer 6.1.7 (https://git
296
-
297
- hub.com/PHPMailer/PHPMailer)
298
-
299
- 2020-07-31 12:41:59 CLIENT -> SERVER: MIME-Version: 1.0
300
-
301
- 2020-07-31 12:41:59 CLIENT -> SERVER: Content-Type: multipart/alternative;
302
-
303
- 2020-07-31 12:41:59 CLIENT -> SERVER: boundary="b1_1q1hKQR6FprjUIdsqzX1aud7
304
-
305
- xs82ZRbFpVMCf7eAmw"
306
-
307
- 2020-07-31 12:41:59 CLIENT -> SERVER: Content-Transfer-Encoding: 8bit
308
-
309
- 2020-07-31 12:41:59 CLIENT -> SERVER:
310
-
311
- 2020-07-31 12:41:59 CLIENT -> SERVER: This is a multi-part message in MIME f
312
-
313
- ormat.
175
+ ine 52
314
-
315
- 2020-07-31 12:41:59 CLIENT -> SERVER:
316
-
317
- 2020-07-31 12:41:59 CLIENT -> SERVER: --b1_1q1hKQR6FprjUIdsqzX1aud7xs82ZRbFp
318
-
319
- VMCf7eAmw
320
-
321
- 2020-07-31 12:41:59 CLIENT -> SERVER: Content-Type: text/plain; charset=us-a
322
-
323
- scii
324
-
325
- 2020-07-31 12:41:59 CLIENT -> SERVER:
326
-
327
- 2020-07-31 12:41:59 CLIENT -> SERVER: hellooooo
328
-
329
- 2020-07-31 12:41:59 CLIENT -> SERVER:
330
-
331
- 2020-07-31 12:41:59 CLIENT -> SERVER: --b1_1q1hKQR6FprjUIdsqzX1aud7xs82ZRbFp
332
-
333
- VMCf7eAmw
334
-
335
- 2020-07-31 12:41:59 CLIENT -> SERVER: Content-Type: text/html; charset=us-as
336
-
337
- cii
338
-
339
- 2020-07-31 12:41:59 CLIENT -> SERVER:
340
-
341
- 2020-07-31 12:41:59 CLIENT -> SERVER: hellooooo
342
-
343
- 2020-07-31 12:41:59 CLIENT -> SERVER:
344
-
345
- 2020-07-31 12:41:59 CLIENT -> SERVER:
346
-
347
- 2020-07-31 12:41:59 CLIENT -> SERVER: --b1_1q1hKQR6FprjUIdsqzX1aud7xs82ZRbFp
348
-
349
- VMCf7eAmw--
350
-
351
- 2020-07-31 12:41:59 CLIENT -> SERVER:
352
-
353
- 2020-07-31 12:41:59 CLIENT -> SERVER: .
354
-
355
- 2020-07-31 12:42:00 SERVER -> CLIENT: 250 2.0.0 OK 1596199320 h4sm1066901pg
356
-
357
- q.9 - gsmtp
358
-
359
- 2020-07-31 12:42:00 CLIENT -> SERVER: QUIT
360
-
361
- 2020-07-31 12:42:00 SERVER -> CLIENT: 221 2.0.0 closing connection h4sm10669
362
-
363
- 01pgq.9 - gsmtp
364
-
365
- Message has been sent
366
176
 
367
177
 
368
178
 
369
179
  */
370
180
 
181
+
182
+
371
- ?>
183
+ ?>コード
372
184
 
373
185
  ```

2

タグの追加

2020/08/21 12:26

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
File without changes

1

タグの追加

2020/08/01 12:11

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
File without changes