質問編集履歴

1

ソースコードを更新いたしました。

2021/05/26 05:33

投稿

VAAAANG
VAAAANG

スコア1

test CHANGED
File without changes
test CHANGED
@@ -36,6 +36,8 @@
36
36
 
37
37
    if( !$items['name'] ) $blank = $error['name'] = 'お名前が入力されていません';
38
38
 
39
+ ...
40
+
39
41
 
40
42
 
41
43
   $_SESSION["items"] = $items;
@@ -68,17 +70,413 @@
68
70
 
69
71
 
70
72
 
71
- なお下記のコードでエラーメッセージを表示するようはしております。
72
-
73
- ```
74
-
75
- <?php if( isset($error['name']) ) echo '<p class="error-text">' . h($error['name']) . '</p>'; ?>
76
-
77
- ```
78
-
79
- PHPバージョン:7.4.13
80
-
81
-
73
+ 下記がだいたいのコードにります。
74
+
75
+ ※今回の質問と関係ない記述(htmlタグなど)は省いています。
76
+
77
+ ```
78
+
79
+ <?php
80
+
81
+ session_start();
82
+
83
+
84
+
85
+ function h($s) {
86
+
87
+ return htmlspecialchars($s, ENT_QUOTES, "UTF-8");
88
+
89
+ }
90
+
91
+
92
+
93
+ $text = array();
94
+
95
+ $blank = true;
96
+
97
+ $items = $_SESSION["items"];
98
+
99
+
100
+
101
+ $client_name = '企業名';
102
+
103
+ $client_address = "企業メールアドレス";
104
+
105
+
106
+
107
+ if( isset($_POST['check']) ){
108
+
109
+ $items = $_POST['items'];
110
+
111
+ $blank = false;
112
+
113
+
114
+
115
+ if( !$items['name'] ) $blank = $error['name'] = 'お名前が入力されていません';
116
+
117
+ if( !$items['ruby'] ) $blank = $error['ruby'] = 'ふりがなが入力されていません';
118
+
119
+
120
+
121
+ if( !preg_match("/^[^@]+@[^@]+$/",$items['mail01']) ) $blank = $error['mail01'] = '正しい形式のメールアドレスをご入力ください';
122
+
123
+ if( !$items['mail01'] ) $blank = $error['mail01'] = 'メールアドレスが入力されていません';
124
+
125
+ if( !$items['mail02'] ) $blank = $error['mail02'] = 'メールアドレスが入力されていません';
126
+
127
+ if( $items['mail01'] !== $items['mail02'] ) $blank = $error['mail02'] = '上記メールアドレスと異なります';
128
+
129
+
130
+
131
+ if( !($items['tel01'] && $items['tel02'] && $items['tel03']) ) $blank = $error['tel'] = '電話番号が入力されていません';
132
+
133
+
134
+
135
+ $_SESSION["items"] = $items;
136
+
137
+ }
138
+
139
+
140
+
141
+ if( isset($_POST['send']) ){
142
+
143
+
144
+
145
+ setcookie( session_name(), '', time()-42000, '/' );
146
+
147
+ session_destroy();
148
+
149
+ $_SESSION['send_num'] = $send_num;
150
+
151
+
152
+
153
+ $message = <<<EOT
154
+
155
+ ■ お名前
156
+
157
+ $items[name]
158
+
159
+
160
+
161
+ ■ ふりがな
162
+
163
+ $items[ruby]
164
+
165
+
166
+
167
+ ■ メールアドレス
168
+
169
+ $items[mail01]
170
+
171
+
172
+
173
+ ■ 電話番号
174
+
175
+ $items[tel01] - $items[tel02] - $items[tel03]
176
+
177
+
178
+
179
+ ■ ご住所
180
+
181
+ $items[pc01] - $items[pc02]
182
+
183
+ $items[address]
184
+
185
+
186
+
187
+ EOT;
188
+
189
+ $client_message = <<<EOT
190
+
191
+
192
+
193
+ ホームページからお問い合わせがありました。
194
+
195
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
196
+
197
+
198
+
199
+ $message
200
+
201
+
202
+
203
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
204
+
205
+ $home_url
206
+
207
+ EOT;
208
+
209
+ $user_message = <<<EOT
210
+
211
+
212
+
213
+ $items[name] 様
214
+
215
+
216
+
217
+ このたびは、 $client_name にお申込みいただき、ありがとうございます。
218
+
219
+ 近日担当者よりご連絡を差し上げますので、しばらくお待ちくださいませ。
220
+
221
+
222
+
223
+
224
+
225
+ $message
226
+
227
+
228
+
229
+ EOT;
230
+
231
+
232
+
233
+ mb_language("japanese");
234
+
235
+ mb_internal_encoding("UTF-8");
236
+
237
+ mb_convert_encoding($client_address,"UTF-8");
238
+
239
+ mb_convert_encoding($client_message,"UTF-8");
240
+
241
+ $user_message = mb_convert_encoding($user_message,"UTF-8");
242
+
243
+
244
+
245
+ if(!mb_send_mail($client_address,$items['name']."さんよりお問い合わせがありました",$client_message,"From: ".$client_address)){exit("e");}
246
+
247
+ if(!mb_send_mail($items['mail01'],"お問い合わせありがとうございました",$user_message,"From:".mb_encode_mimeheader($client_name)."<".$client_address.">")){exit("e");}
248
+
249
+
250
+
251
+ $sent = true;
252
+
253
+ $blank = false;
254
+
255
+
256
+
257
+ header('Location: /thanks/');
258
+
259
+ exit;
260
+
261
+
262
+
263
+ }
264
+
265
+ ?>
266
+
267
+
268
+
269
+ <?php if( $blank ){ ?>
270
+
271
+
272
+
273
+ <p>下記項目を入力の上、「確認画面へ進む」を押してください。</p>
274
+
275
+ <p>お申し込み受付後、受付完了メールをお送りします。※は必須項目です。</p>
276
+
277
+
278
+
279
+ <?php }elseif( !isset($sent) ){ ?>
280
+
281
+
282
+
283
+ <p>以下の内容でよろしければ「送信する」ボタンを押して下さい</p>
284
+
285
+
286
+
287
+ <?php } else { ?>
288
+
289
+
290
+
291
+ <p>送信が完了しました。</p>
292
+
293
+ <p>このたびはお申込みいただき、ありがとうございます。</p>
294
+
295
+ <p>近日担当者よりご連絡を差し上げますので、しばらくお待ちくださいませ。</p>
296
+
297
+
298
+
299
+ <?php } ?>
300
+
301
+
302
+
303
+ <form action="#anc-contact" method="post" class="contact-form">
304
+
305
+
306
+
307
+ <?php if( $blank ){ ?>
308
+
309
+
310
+
311
+ <table class="contact-form-table">
312
+
313
+ <tr>
314
+
315
+ <th><label for="name">お名前(全角)</label><span>*</span></th>
316
+
317
+ <td>
318
+
319
+ <?php if( isset($error['name']) ) echo '<p class="error-text">' . h($error['name']) . '</p>'; ?>
320
+
321
+ <input type="text" name="items[name]" value="<?php echo h($items['name']); ?>" id="name" class="input-mid" placeholder="例) 山田 太郎">
322
+
323
+ </td>
324
+
325
+ </tr>
326
+
327
+ <tr>
328
+
329
+ <th><label for="ruby">ふりがな(全角)</label><span>*</span></th>
330
+
331
+ <td>
332
+
333
+ <?php if( isset($error['ruby']) ) echo '<p class="error-text">' . h($error['ruby']) . '</p>'; ?>
334
+
335
+ <input type="text" name="items[ruby]" value="<?php echo h($items['ruby']); ?>" id="ruby" class="input-mid" placeholder="例) やまだ たろう">
336
+
337
+ </td>
338
+
339
+ </tr>
340
+
341
+ <tr>
342
+
343
+ <th><label for="mail01">メールアドレス(半角)</label><span>*</span></th>
344
+
345
+ <td>
346
+
347
+ <?php if( isset($error['mail01']) ) echo '<p class="error-text">' . h($error['mail01']) . '</p>'; ?>
348
+
349
+ <input type="email" name="items[mail01]" value="<?php echo h($items['mail01']); ?>" id="mail01" class="input-big" placeholder="例) xxxxxx@example.com">
350
+
351
+ </td>
352
+
353
+ </tr>
354
+
355
+ <tr>
356
+
357
+ <th><label for="mail02">確認用メールアドレス(半角)</label><span>*</span></th>
358
+
359
+ <td>
360
+
361
+ <?php if( isset($error['mail02']) ) echo '<p class="error-text">' . h($error['mail02']) . '</p>'; ?>
362
+
363
+ <input type="email" name="items[mail02]" value="<?php echo h($items['mail02']); ?>" id="mail02" class="input-big" placeholder="例) xxxxxx@example.com">
364
+
365
+ </td>
366
+
367
+ </tr>
368
+
369
+ <tr>
370
+
371
+ <th><label for="tel">電話番号(半角)</label><span>*</span></th>
372
+
373
+ <td>
374
+
375
+ <?php if( isset($error['tel']) ) echo '<p class="error-text">' . h($error['tel']) . '</p>'; ?>
376
+
377
+ <input type="tel" name="items[tel01]" value="<?php echo h($items['tel01']); ?>" class="input-min" id="tel"> -
378
+
379
+ <input type="tel" name="items[tel02]" value="<?php echo h($items['tel02']); ?>" class="input-min"> -
380
+
381
+ <input type="tel" name="items[tel03]" value="<?php echo h($items['tel03']); ?>" class="input-min">
382
+
383
+ </td>
384
+
385
+ </tr>
386
+
387
+ <tr>
388
+
389
+ <th><label for="pc01">ご住所</label></th>
390
+
391
+ <td>
392
+
393
+ 〒 <input type="tel" name="items[pc01]" value="<?php echo h($items['pc01']); ?>" id="pc01" class="input-min">-
394
+
395
+ <input type="tel" name="items[pc02]" value="<?php echo h($items['pc02']); ?>" class="input-min">
396
+
397
+ <input type="button" value="郵便番号から自動入力" onclick="AjaxZip3.zip2addr('items[pc01]','items[pc02]','items[address]','items[address]');">
398
+
399
+ <input type="text" name="items[address]" value="<?php echo h($items['address']); ?>" class="input-big mt5">
400
+
401
+ </td>
402
+
403
+ </tr>
404
+
405
+ </table>
406
+
407
+ <p class="submits"><input type="submit" value="入力内容を確認する" name="check"></p>
408
+
409
+
410
+
411
+ <?php }elseif( !isset($sent) ){ ?>
412
+
413
+
414
+
415
+ <table class="contact-form-table">
416
+
417
+ <tr>
418
+
419
+ <th>お名前</th>
420
+
421
+ <td><?php echo h($items['name']); ?></td>
422
+
423
+ </tr>
424
+
425
+ <tr>
426
+
427
+ <th>ふりがな</th>
428
+
429
+ <td><?php echo h($items['ruby']); ?></td>
430
+
431
+ </tr>
432
+
433
+ <tr>
434
+
435
+ <th>メールアドレス</th>
436
+
437
+ <td><?php echo h($items['mail01']); ?></td>
438
+
439
+ </tr>
440
+
441
+ <tr>
442
+
443
+ <th>電話番号</th>
444
+
445
+ <td><?php echo h($items['tel01']); ?> - <?php echo h($items['tel02']); ?> - <?php echo h($items['tel03']); ?></td>
446
+
447
+ </tr>
448
+
449
+ <tr>
450
+
451
+ <th>ご住所</th>
452
+
453
+ <td><?php echo h($items['pc01']); ?>-<?php echo h($items['pc02']); ?><br><?php echo h($items['address']); ?></td>
454
+
455
+ </tr>
456
+
457
+ </table>
458
+
459
+ <p class="submits">
460
+
461
+ <input type="submit" name="return" value="入力内容を変更する">
462
+
463
+ <input type="submit" name="send" value="送信する">
464
+
465
+ </p>
466
+
467
+
468
+
469
+ <?php } ?>
470
+
471
+
472
+
473
+
474
+
475
+ ```
476
+
477
+ 現サーバPHPバージョン:7.4.13
478
+
479
+ 旧サーバPHPバージョン:5.6
82
480
 
83
481
 
84
482