我已经在 PHP 中设置了一个电子邮件 Web 表单。表单正常工作并发送电子邮件。但不是重定向它会出现这个错误:错误;您需要提交表格!警告:无法修改标头信息 - 第 70 行 /home/con17120/public_html/form-to-email.php 中的标头已由(输出开始于 /home/con17120/public_html/form-to-email.php:5)发送“虽然表单仍然可以正常工作,但它不会重定向。
.....谢谢HTML:
<form method="post" name="myemailform" action="form-to-email.php">
<h1>June/July Crops: </h1>
<h2><input type="checkbox" class="form cushycms" value="yes" name="check1">Pink Lady Apples 2kg <b>$7.00</b></h2>
<h2><input type="checkbox" class="form cushycms" value="yes" name="check2">Seedless Imperials Mandarines 1kg <b>$4.00</b></h2>
<h2><input type="checkbox" class="form cushycms" value="yes" name="check3">Bananas 1kg <b>$4.00</b></h2>
<h2><input type="checkbox" class="form cushycms" value="yes" name="check4">Seedless Thompson Grapes 1kg <b>$6.00</b></h2>
<h2><input type="checkbox" class="form cushycms" value="yes" name="check5">Strawberries <b> TBA</b></h2>
<h2><input type="checkbox" class="form cushycms" value="yes" name="check6">Cherries <b> TBA</b></h2>
<h2><input type="checkbox" class="form cushycms" value="yes" name="check7">Pistachio Nuts 1/4kg <b>$5.00</b> </h2>
<h2><input type="checkbox" class="form cushycms" value="yes" name="check8">Cashew Nuts 1/4kg <b>$5.00</b></h2>
<h2><input type="checkbox" class="form cushycms" value="yes" name="check9">Tassie Dutch Cream Potatoes 2kg <b>$7.00</b></h2>
<h2><input type="checkbox" class="form cushycms" value="yes" name="check10">Avocado's 4 for <b>$7.00</b></h2>
<h2><input type="checkbox" class="form cushycms" value="yes" name="check11">Tomatoes 1kg <b>$4.00</b></h2>
<h2><input type="checkbox" class="form cushycms" value="yes" name="check12">Cold Pressed Honey 1 kg <b>$11.00</b></h2>
<h2><input type="checkbox" class="form cushycms" value="yes" name="check13">Cage Free Eggs 1 Doz <b>$4.00</b></h2>
<h2><input type="checkbox" class="form cushycms" value="yes" name="check14">Soup Packs <br>(Carrot, parsley, onion, parsnip, celeriac) <b>$4.00</b></h2>
<input class="send" type="submit" value="Submit">
<input class="send" type="reset" value="Reset">
</section>
<section class="form">
<h1>Order:</h1>
<h2 style="margin-top:-15px;">To avoid delays pre-order here. Simply choose your crops, fill in your details below and click submit. </h2><br>
Full Name:<br>
<input class="name-email" type="text" name="name" placeholder="John Smith"><br>
Business:<br>
<input class="name-email" type="text" name="business" placeholder="Business Inc." ><br>
Email:<br>
<input class="name-email" type="text" name="email" placeholder="john.appleased@gmail.com"><br>
Message<br>
<input class="name-email" type="text" name="message" placeholder="Extra Comments" ><br>
</form>
PHP:
//Validate first
if(empty($name)||empty($visitor_email))
{
echo "Name and email are mandatory!";
exit;
}
if(IsInjected($visitor_email))
{
echo "Bad email value!";
exit;
}
$email_from = '';//<== update the email address
$email_subject = "New Order submission";
$email_body = "You have received a new order from: $name.\n".
"Email:$email_from: /n"
"Business Name: $business.\n".
"Here is the message: $message\n".
"PinkLadyApples2kg:$check1\n".
"Mandarines1kg:$check2\n".
"Bananas1kg:$check3\n".
"Grapes1kg:$check4\n".
"Strawberries:$check5\n".
"Cherries:$check6\n".
"PistachioNuts1.4kg:$check7\n".
"CashewNuts1/4kg:$check8\n".
"TassieDutchPotatoes2kg:$check9\n".
"Avocados4:$check10\n".
"Tomatoes1kg:$check11\n".
"Honey1doz:$check12\n".
"Eggs1doz:$check13\n".
"Soup:$check14\n".
$to = "";//<== update the email address
$headers = "From: $email_from \r\n";
$headers .= "Reply-To: $visitor_email \r\n";
//Send the email!
mail($to,$email_subject,$email_body,$headers);
//done. redirect to thank-you page.
header( 'Location:/thank-you.html' );
// Function to validate against any email injection attempts
function IsInjected($str)
{
$injections = array('(\n+)',
'(\r+)',
'(\t+)',
'(%0A+)',
'(%0D+)',
'(%08+)',
'(%09+)'
);
$inject = join('|', $injections);
$inject = "/$inject/i";
if(preg_match($inject,$str))
{
return true;
}
else
{
return false;
}
}
?>