你好堆垛机,
PHP 新手,我正在从预先构建的代码中组合一个多页表单。
基本上,用户可以根据需要选择尽可能多的复选框......然后表单提交到这个辅助页面。这个二级页面回显了他们通过 .. 在页面顶部选择的复选框,$check
然后他们可以输入他们的联系信息,所有信息都通过表单提交,连同$check
信息。
除了$check
没有输入表单消息外,一切都运行良好,但它在页面顶部运行,显示用户输入的选项。
任何帮助表示赞赏!
<?php
$emailOut = '';
if(!empty($_POST['choices'])) {
foreach($_POST['choices'] as $check) {
echo $check; //echoes the value set in the HTML form for each checked checkbox.
//so, if I were to check 1, 3, and 5 it would echo value 1, value 3, value 5.
//in your case, it would echo whatever $row['Report ID'] is equivalent to.
$emailOut .= $check."\n"; //any output you want
}
}
$errors = '';
$myemail = 'test@myemailHERE.com';//<-----Put Your email address here.
if(empty($_POST['name']) ||
empty($_POST['email']) ||
empty($_POST['message']))
{
$errors .= "\n Error: all fields are required";
}
$name = $_POST['name'];
$email_address = $_POST['email'];
$message = $_POST['message'];
if (!preg_match(
"/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i",
$email_address))
{
$errors .= "\n Error: Invalid email address";
}
if( empty($errors))
{
$to = $myemail;
$email_subject = "Contact form submission: $name";
$email_body = "You have received a new message. $check ".
" Here are the details:\n Name: $name \n Email: $email_address \n Message \n $message \n $emailOut";
$headers = "From: $myemail\n";
$headers .= "Reply-To: $email_address";
mail($to,$email_subject,$email_body,$headers);
//redirect to the 'thank you' page
header('Location: contact-form-thank-you.html');
}
?>