質問編集履歴
1
コードを規定の方法で掲載しました
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,243 +1,249 @@
|
|
1
|
+
```<?php
|
2
|
+
|
3
|
+
session_start();
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
$mode = !empty($_POST['mode'])? $_POST['mode']:'';
|
8
|
+
|
9
|
+
|
10
|
+
|
11
|
+
$namae = "";
|
12
|
+
|
13
|
+
$company = "";
|
14
|
+
|
15
|
+
$email = "";
|
16
|
+
|
17
|
+
$honbun = "";
|
18
|
+
|
19
|
+
$error = "";
|
20
|
+
|
21
|
+
$error_namae = "";
|
22
|
+
|
23
|
+
$error_company = "";
|
24
|
+
|
25
|
+
$error_email = "";
|
26
|
+
|
27
|
+
$error_honbun = "";
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
if($mode){
|
32
|
+
|
33
|
+
if(empty($_SESSION['token']) || $_SESSION['token']!=$_POST['token']){
|
34
|
+
|
35
|
+
die('不正な遷移です。');
|
36
|
+
|
37
|
+
}
|
38
|
+
|
39
|
+
if(empty($_POST['namae'])){
|
40
|
+
|
41
|
+
$error_namae = "<class='error'><font color='red' size='2'>お名前を入力してください</font></class>\n";
|
42
|
+
|
43
|
+
}else{
|
44
|
+
|
45
|
+
$namae = htmlspecialchars($_POST['namae']); }
|
46
|
+
|
47
|
+
$company = htmlspecialchars($_POST['company']);
|
48
|
+
|
49
|
+
if(empty($_POST['email'])){ $error_email = "<class='error'><font color='red' size='2'>メールアドレスを入力してください</font></class>\n";
|
50
|
+
|
51
|
+
}else{
|
52
|
+
|
53
|
+
$email = htmlspecialchars($_POST['email']); }
|
54
|
+
|
55
|
+
if(empty($_POST['honbun'])){ $error_honbun = "<class='error'><font color='red' size='2'>本文を入力してください</font></class>\n";
|
56
|
+
|
57
|
+
}else{
|
58
|
+
|
59
|
+
$honbun = htmlspecialchars($_POST['honbun']); }
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
if($error_namae || $error_email || $error_honbun){
|
64
|
+
|
65
|
+
$mode = 'input';
|
66
|
+
|
67
|
+
}
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
if($mode == 'submit'){
|
72
|
+
|
73
|
+
session_destroy();
|
74
|
+
|
75
|
+
$to = '送信先'; $subject = 'お問い合わせがありました';
|
76
|
+
|
77
|
+
$message = 'お名前:'.$namae."\n"
|
78
|
+
|
79
|
+
.'御社名:'.$company."\n"
|
80
|
+
|
81
|
+
.'メールアドレス:'.$email."\n"
|
82
|
+
|
83
|
+
.'本文:'.$honbun."\n";
|
84
|
+
|
85
|
+
$header = 'From:test@ad5.jp';
|
86
|
+
|
87
|
+
$result = mb_send_mail($to,$subject,$message,$header);
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
if($result){ header('Location:https://送信先');
|
92
|
+
|
93
|
+
exit;
|
94
|
+
|
95
|
+
}else{
|
96
|
+
|
97
|
+
$mode = 'error';
|
98
|
+
|
99
|
+
$error = 'メール送信に失敗しました';
|
100
|
+
|
101
|
+
}
|
102
|
+
|
103
|
+
}
|
104
|
+
|
105
|
+
}else{
|
106
|
+
|
107
|
+
$mode = 'input';
|
108
|
+
|
109
|
+
$_SESSION['token'] = bin2hex(openssl_random_pseudo_bytes(16));
|
110
|
+
|
111
|
+
}
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
(省略)
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
<main id="toiawase" class="cf">
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
<?php if($mode == 'input'): ?>
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
<form action="toiawase_test.php" method="post">
|
136
|
+
|
137
|
+
<input type="hidden" name="mode" value="confirm">
|
138
|
+
|
139
|
+
<input type="hidden" name="token" value="<?php echo $_SESSION['token']; ?>">
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
<table class="error">
|
144
|
+
|
145
|
+
<tr><td colspan="2"><?php if($error_namae): ?><em><?php echo $error_namae; ?></em><?php endif; ?></td></tr>
|
146
|
+
|
147
|
+
<tr><td>お名前:</td><td><input type="text" name="namae" value="<?php echo $namae; ?>"></td></tr>
|
148
|
+
|
149
|
+
<tr><td colspan="2"><?php if($error_company): ?><em><?php echo $error_company; ?></em><?php endif; ?></td></tr>
|
150
|
+
|
151
|
+
<tr><td>御社名:</td><td><input type="text" name="company" value="<?php echo $company; ?>"></td></tr>
|
152
|
+
|
153
|
+
<tr><td colspan="2"><?php if($error_email): ?><em><?php echo $error_email; ?></em><?php endif; ?></td></tr>
|
154
|
+
|
155
|
+
<tr><td>メールアドレス:</td><td><input type="email" name="email" value="<?php echo $email; ?>"></td></tr>
|
156
|
+
|
157
|
+
<tr><td colspan="2"><?php if($error_honbun): ?><em><?php echo $error_honbun; ?></em><?php endif; ?></td></tr>
|
158
|
+
|
159
|
+
<tr><td>本文:</td><td><textarea name="honbun" cols="50" rows="10"><?php echo $honbun; ?></textarea></td></tr>
|
160
|
+
|
161
|
+
</table>
|
162
|
+
|
163
|
+
<p><button type="submit">確認</button></p>
|
164
|
+
|
165
|
+
</form>
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
<?php elseif($mode == 'confirm'): ?>
|
170
|
+
|
171
|
+
<table class="error">
|
172
|
+
|
173
|
+
<tr><td>お名前:</td><td><?php echo $namae; ?></td></tr>
|
174
|
+
|
175
|
+
<tr><td>御社名:</td><td><?php echo $company; ?></td></tr>
|
176
|
+
|
177
|
+
<tr><td>メールアドレス:</td><td><?php echo $email; ?></td></tr>
|
178
|
+
|
179
|
+
<tr><td>本文:</td><td><?php echo nl2br($honbun); ?></td></tr>
|
180
|
+
|
181
|
+
</table>
|
182
|
+
|
183
|
+
|
184
|
+
|
185
|
+
<form action="toiawase_test.php" method="post">
|
186
|
+
|
187
|
+
<input type="hidden" name="mode" value="submit">
|
188
|
+
|
189
|
+
<input type="hidden" name="token" value="<?php echo $_SESSION['token']; ?>">
|
190
|
+
|
191
|
+
<input type="hidden" name="namae" value="<?php echo $namae; ?>">
|
192
|
+
|
193
|
+
<input type="hidden" name="company" value="<?php echo $company; ?>">
|
194
|
+
|
195
|
+
<input type="hidden" name="email" value="<?php echo $email; ?>">
|
196
|
+
|
197
|
+
<input type="hidden" name="honbun" value="<?php echo $honbun; ?>">
|
198
|
+
|
199
|
+
<p><button type="submit">送信</button></p>
|
200
|
+
|
201
|
+
</form>
|
202
|
+
|
203
|
+
|
204
|
+
|
205
|
+
<form action="toiawase_test.php" method="post">
|
206
|
+
|
207
|
+
<input type="hidden" name="mode" value="input">
|
208
|
+
|
209
|
+
<input type="hidden" name="token" value="<?php echo $_SESSION['token']; ?>">
|
210
|
+
|
211
|
+
<input type="hidden" name="namae" value="<?php echo $namae; ?>">
|
212
|
+
|
213
|
+
<input type="hidden" name="company" value="<?php echo $company; ?>">
|
214
|
+
|
215
|
+
<input type="hidden" name="email" value="<?php echo $email; ?>">
|
216
|
+
|
217
|
+
<input type="hidden" name="honbun" value="<?php echo $honbun; ?>">
|
218
|
+
|
219
|
+
<p><button type="submit">戻る</button></p>
|
220
|
+
|
221
|
+
</form>
|
222
|
+
|
223
|
+
|
224
|
+
|
225
|
+
<?php else: ?>
|
226
|
+
|
227
|
+
<p>エラーが発生しました</p>
|
228
|
+
|
229
|
+
<?php if($error): ?><p><em><?php echo $error; ?></em></p><?php endif; ?>
|
230
|
+
|
231
|
+
<?php endif; ?>
|
232
|
+
|
233
|
+
|
234
|
+
|
235
|
+
</main>
|
236
|
+
|
237
|
+
```
|
238
|
+
|
1
239
|
メールフォームを作成していますが、以下の記述でアップロードしたら、Internal Server Errorが出てしまいます。
|
2
240
|
|
241
|
+
メインフォルダ内にテストフォルダを作って作成をしていた段階では確認できていたのですが、いざテストフォルダを外したらエラーになってしまいました。
|
242
|
+
|
243
|
+
tokenの記述があやしいのかと思っていますが分かりません。
|
244
|
+
|
245
|
+
|
246
|
+
|
3
247
|
何かおかしい部分はありますでしょうか?
|
4
248
|
|
5
249
|
なお、送信先は、単独で開くことは確認できています。
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
<?php
|
10
|
-
|
11
|
-
session_start();
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
$mode = !empty($_POST['mode'])? $_POST['mode']:'';
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
$namae = "";
|
20
|
-
|
21
|
-
$company = "";
|
22
|
-
|
23
|
-
$email = "";
|
24
|
-
|
25
|
-
$honbun = "";
|
26
|
-
|
27
|
-
$error = "";
|
28
|
-
|
29
|
-
$error_namae = "";
|
30
|
-
|
31
|
-
$error_company = "";
|
32
|
-
|
33
|
-
$error_email = "";
|
34
|
-
|
35
|
-
$error_honbun = "";
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
if($mode){
|
40
|
-
|
41
|
-
if(empty($_SESSION['token']) || $_SESSION['token']!=$_POST['token']){
|
42
|
-
|
43
|
-
die('不正な遷移です。');
|
44
|
-
|
45
|
-
}
|
46
|
-
|
47
|
-
if(empty($_POST['namae'])){
|
48
|
-
|
49
|
-
$error_namae = "<class='error'><font color='red' size='2'>お名前を入力してください</font></class>\n";
|
50
|
-
|
51
|
-
}else{
|
52
|
-
|
53
|
-
$namae = htmlspecialchars($_POST['namae']); }
|
54
|
-
|
55
|
-
$company = htmlspecialchars($_POST['company']);
|
56
|
-
|
57
|
-
if(empty($_POST['email'])){ $error_email = "<class='error'><font color='red' size='2'>メールアドレスを入力してください</font></class>\n";
|
58
|
-
|
59
|
-
}else{
|
60
|
-
|
61
|
-
$email = htmlspecialchars($_POST['email']); }
|
62
|
-
|
63
|
-
if(empty($_POST['honbun'])){ $error_honbun = "<class='error'><font color='red' size='2'>本文を入力してください</font></class>\n";
|
64
|
-
|
65
|
-
}else{
|
66
|
-
|
67
|
-
$honbun = htmlspecialchars($_POST['honbun']); }
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
if($error_namae || $error_email || $error_honbun){
|
72
|
-
|
73
|
-
$mode = 'input';
|
74
|
-
|
75
|
-
}
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
if($mode == 'submit'){
|
80
|
-
|
81
|
-
session_destroy();
|
82
|
-
|
83
|
-
$to = '送信先'; $subject = 'お問い合わせがありました';
|
84
|
-
|
85
|
-
$message = 'お名前:'.$namae."\n"
|
86
|
-
|
87
|
-
.'御社名:'.$company."\n"
|
88
|
-
|
89
|
-
.'メールアドレス:'.$email."\n"
|
90
|
-
|
91
|
-
.'本文:'.$honbun."\n";
|
92
|
-
|
93
|
-
$header = 'From:test@ad5.jp';
|
94
|
-
|
95
|
-
$result = mb_send_mail($to,$subject,$message,$header);
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
if($result){ header('Location:https://送信先');
|
100
|
-
|
101
|
-
exit;
|
102
|
-
|
103
|
-
}else{
|
104
|
-
|
105
|
-
$mode = 'error';
|
106
|
-
|
107
|
-
$error = 'メール送信に失敗しました';
|
108
|
-
|
109
|
-
}
|
110
|
-
|
111
|
-
}
|
112
|
-
|
113
|
-
}else{
|
114
|
-
|
115
|
-
$mode = 'input';
|
116
|
-
|
117
|
-
$_SESSION['token'] = bin2hex(openssl_random_pseudo_bytes(16));
|
118
|
-
|
119
|
-
}
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
(省略)
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
<main id="toiawase" class="cf">
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
<?php if($mode == 'input'): ?>
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
<form action="toiawase_test.php" method="post">
|
144
|
-
|
145
|
-
<input type="hidden" name="mode" value="confirm">
|
146
|
-
|
147
|
-
<input type="hidden" name="token" value="<?php echo $_SESSION['token']; ?>">
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
<table class="error">
|
152
|
-
|
153
|
-
<tr><td colspan="2"><?php if($error_namae): ?><em><?php echo $error_namae; ?></em><?php endif; ?></td></tr>
|
154
|
-
|
155
|
-
<tr><td>お名前:</td><td><input type="text" name="namae" value="<?php echo $namae; ?>"></td></tr>
|
156
|
-
|
157
|
-
<tr><td colspan="2"><?php if($error_company): ?><em><?php echo $error_company; ?></em><?php endif; ?></td></tr>
|
158
|
-
|
159
|
-
<tr><td>御社名:</td><td><input type="text" name="company" value="<?php echo $company; ?>"></td></tr>
|
160
|
-
|
161
|
-
<tr><td colspan="2"><?php if($error_email): ?><em><?php echo $error_email; ?></em><?php endif; ?></td></tr>
|
162
|
-
|
163
|
-
<tr><td>メールアドレス:</td><td><input type="email" name="email" value="<?php echo $email; ?>"></td></tr>
|
164
|
-
|
165
|
-
<tr><td colspan="2"><?php if($error_honbun): ?><em><?php echo $error_honbun; ?></em><?php endif; ?></td></tr>
|
166
|
-
|
167
|
-
<tr><td>本文:</td><td><textarea name="honbun" cols="50" rows="10"><?php echo $honbun; ?></textarea></td></tr>
|
168
|
-
|
169
|
-
</table>
|
170
|
-
|
171
|
-
<p><button type="submit">確認</button></p>
|
172
|
-
|
173
|
-
</form>
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
<?php elseif($mode == 'confirm'): ?>
|
178
|
-
|
179
|
-
<table class="error">
|
180
|
-
|
181
|
-
<tr><td>お名前:</td><td><?php echo $namae; ?></td></tr>
|
182
|
-
|
183
|
-
<tr><td>御社名:</td><td><?php echo $company; ?></td></tr>
|
184
|
-
|
185
|
-
<tr><td>メールアドレス:</td><td><?php echo $email; ?></td></tr>
|
186
|
-
|
187
|
-
<tr><td>本文:</td><td><?php echo nl2br($honbun); ?></td></tr>
|
188
|
-
|
189
|
-
</table>
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
<form action="toiawase_test.php" method="post">
|
194
|
-
|
195
|
-
<input type="hidden" name="mode" value="submit">
|
196
|
-
|
197
|
-
<input type="hidden" name="token" value="<?php echo $_SESSION['token']; ?>">
|
198
|
-
|
199
|
-
<input type="hidden" name="namae" value="<?php echo $namae; ?>">
|
200
|
-
|
201
|
-
<input type="hidden" name="company" value="<?php echo $company; ?>">
|
202
|
-
|
203
|
-
<input type="hidden" name="email" value="<?php echo $email; ?>">
|
204
|
-
|
205
|
-
<input type="hidden" name="honbun" value="<?php echo $honbun; ?>">
|
206
|
-
|
207
|
-
<p><button type="submit">送信</button></p>
|
208
|
-
|
209
|
-
</form>
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
<form action="toiawase_test.php" method="post">
|
214
|
-
|
215
|
-
<input type="hidden" name="mode" value="input">
|
216
|
-
|
217
|
-
<input type="hidden" name="token" value="<?php echo $_SESSION['token']; ?>">
|
218
|
-
|
219
|
-
<input type="hidden" name="namae" value="<?php echo $namae; ?>">
|
220
|
-
|
221
|
-
<input type="hidden" name="company" value="<?php echo $company; ?>">
|
222
|
-
|
223
|
-
<input type="hidden" name="email" value="<?php echo $email; ?>">
|
224
|
-
|
225
|
-
<input type="hidden" name="honbun" value="<?php echo $honbun; ?>">
|
226
|
-
|
227
|
-
<p><button type="submit">戻る</button></p>
|
228
|
-
|
229
|
-
</form>
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
<?php else: ?>
|
234
|
-
|
235
|
-
<p>エラーが発生しました</p>
|
236
|
-
|
237
|
-
<?php if($error): ?><p><em><?php echo $error; ?></em></p><?php endif; ?>
|
238
|
-
|
239
|
-
<?php endif; ?>
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
</main>
|