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;
}
}
?>