html
<form method="post"action="submit.php"> <div class="セット"> <p><input type="text"name="name[]"data-face="表"data-target="おもて面_01"maxlength="3"style="width:33%;"placeholder="yes / no"required> <input type="text"name="name[]"data-face="表"data-target="おもて面_02"maxlength="3"style="width:33%;"placeholder="yes / no"required> <input type="text"name="name[]"data-face="表"data-target="おもて面_03"maxlength="3"style="width:33%;"placeholder="yes / no"required> </p> <p><input type="text"name="data1"data-face="裏"data-target="うら面_01"maxlength="15"style="width:100%;"placeholder="お名前"required></p> <p><input type="text"name="title"data-face="裏"data-target="うら面_02"style="width:100%;"placeholder="メール・アドレス"required></p> <p><textarea name="message"data-face="裏"data-target="うら面_03"placeholder="お問い合わせ内容"required></textarea></p> </div> <div class="ボタン_インプット"> <div class="メール"> <p style="font-size:14px; margin:10px 0 0 28px;"> 確認のメールを<br> <input type="radio" name="copymailcheck" value="1" checked> 受け取る<br> <input type="radio" name="copymailcheck" value="0"> 受け取らない </p> </div> <div class="ボタン_キャンセルボタン"> <input type="submit"value="送信"style="margin:10px 0 6px 0;"> <input type="reset" value="キャンセル"> <input type="hidden"name="あくしょん"value="check"> </div> </div> </form>
submit.php
<?php function sanitizeInput($data) {return htmlspecialchars($data, ENT_QUOTES, 'utf-8');} $name=isset($_POST['name']) ? array_map('sanitizeInput', $_POST['name']) :['', '', '']; $data1=isset($_POST['data1']) ? sanitizeInput($_POST['data1']) :''; $email=isset($_POST['title']) ? sanitizeInput($_POST['title']) :''; $message=isset($_POST['message']) ? sanitizeInput($_POST['message']) :''; $copymailcheck=isset($_POST['copymailcheck']) && $_POST['copymailcheck'] == '1' ? true :false; $to='test@test.test.test'; $subject='お問い合わせ:' . $email; $body="名前1:{$name[0]}\n" . "名前2:{$name[1]}\n" . "名前3:{$name[2]}\n" . "お名前:$data1\n" . "メールアドレス:$email\n" . "お問い合わせ内容:\n$message\n"; $headers="From:test@test.test.test\r\n" . "Reply-To:$email\r\n" . "Content-Type:text/plain; charset=utf-8\r\n"; $mailSent=mail($to, $subject, $body, $headers); $formData="名前1:{$name[0]}\n" . "名前2:{$name[1]}\n" . "名前3:{$name[2]}\n" . "お名前:$data1\n" . "メールアドレス:$email\n" . "お問い合わせ内容:\n$message\n" . "----------------------------------------\n"; file_put_contents('form_data.txt', $formData, FILE_APPEND | LOCK_EX); $copyMailSent=false; if($copymailcheck && filter_var($email, FILTER_VALIDATE_EMAIL)) {$copy_to=$email; $copy_subject='確認メール:お問い合わせありがとうございます'; $copy_body="この度はお問い合わせいただき、誠にありがとうございます.\n\n" . "以下の内容でお問い合わせを受け付けました.\n\n" . "------ お問い合わせ内容 ------\n" . "名前1:{$name[0]}\n" . "名前2:{$name[1]}\n" . "名前3:{$name[2]}\n" . "お名前:$data1\n" . "メールアドレス:$email\n" . "お問い合わせ内容:\n$message\n" . "-----------------------------\n\n" . "何かございましたらお気軽にお問い合わせください."; $copy_headers="From:test@test.test.test\r\n" . "Reply-To:test@test.test.test\r\n" . "Content-Type:text/plain; charset=utf-8\r\n"; $copyMailSent=mail($copy_to, $copy_subject, $copy_body, $copy_headers);} ?> <style> body{font-family:Arial, sans-serif; background:linear-gradient(90deg, rgb(250, 250, 250), rgb(230, 230, 255)); display:flex; justify-content:center; align-items:center; height:100vh; margin:0;} .ボックス {text-align:center; padding:20px; background:linear-gradient(90deg, rgb(22, 135, 237), rgb(20, 55, 90)); border-radius:10px; box-shadow:0 4px 8px rgba(0, 0, 0, 0.2); max-width:400px; width:100%; color:white;} .ボックス h1{margin-bottom:20px;} .ボックス p{margin:10px 0;} .ボックス a{display:inline-block; margin-top:20px; padding:10px 20px; color:white; background-color:rgba(255, 255, 255, 0.2); text-decoration:none; border-radius:5px; transition:background-color 0.3s;} .ボックス a:hover {background-color:rgba(255, 255, 255, 0.4);} </style> <div class="ボックス"> <h1>送信が完了しました.</h1> <p> <?php if($mailSent) {echo 'お問い合わせメールが送信されました.';} else {echo 'お問い合わせメールの送信に失敗しました.';} if($copymailcheck && $copyMailSent) {echo '<br>確認メールが送信されました.';} else {echo '<br>確認メールの送信に失敗しました.';} ?> </p>