重复的问题,对我来说没有合适的答案...... 我已经看到围绕这个主题的一些威胁,但它们都没有帮助解决我的问题。问题是标题所说的。我有一个邮件脚本,工作正常,但我的脚本继续刷新时再次发送表单的输入。我该如何解决这个问题?
PS:我使用header('Location: http://www.intu.nl/versie2/contact');
这是我的代码:
<?php
//if "submitted" variable is filled out, send email
if (isset($_REQUEST['submitted'])) {
$errors = array();
$ontvanger = "my@email.com";
//emailchek
if (!empty($_REQUEST['email'])) {
$afzender = $_REQUEST['email'];
if (!filter_var($afzender, FILTER_VALIDATE_EMAIL) === false) {
$afzender = $_REQUEST['email'];
}
else {
$errors[] = "Uw E-mail adres niet juist is ingevuld.";
}
} else {
$errors[] = 'Uw E-Mail adres niet is ingevuld.';
}
// Naam check
if (!empty($_REQUEST['name'])) {
$naam = $_REQUEST['name'];
} else {
$naam = 'is niet ingevuld.';
}
//nummer check
if (!empty($_REQUEST['phone'])) {
$telefoon = $_REQUEST['phone'];
if(!ctype_digit($telefoon)){
$telefoon = "geen telefoonnummer meegegeven";
}
} else {
$telefoon = "geen telefoon nummer meegegeven";
}
if (!empty($_REQUEST['comment'])) {
$inhoud = $_REQUEST['comment'];
} else {
$errors[ ] = "Uw bericht was leeg";
}
$headers = array();
$headers[ ] = "MIME-Version: 1.0";
$headers[ ] = "Content-type: text/plain; charset=utf-8";
$headers[ ] = "Email: " . $afzender;
$headers[ ] = "Telefoon nummer: " . $telefoon;
$headers[ ] = "naam: " . $naam;
$headers[ ] = "Inhoud van het bericht:";
//send email
if (empty($errors)) {
mail($ontvanger, "Een E-Mail verzonden van INTUhome.nl", $inhoud, implode("\r\n", $headers), "-f".$afzender);
print('<h2 class="green"><i class="icon-ok"></i>Bedankt voor uw bericht! </h2><h3> Wij zullen zo snel mogelijk contact met u opnemen.</h3>');
header('Location: http://www.intu.nl/versie2/contact');
}
else {
echo "<h2 class='green'>De E-Mail is niet verzonden omdat:</h2>";
foreach ($errors as $msg) {
echo '<li><h3>' . $msg . '</h3></li>';
}
echo '</br>';
echo '<A HREF="../contact"><h4>Ga terug</h4></A>';
}
} else{
?>
<form method="get">
<div class="input-group input-group-lg"><span class="input-group-addon"><span class="glyphicon glyphicon-user"></span></span>
<input name="name" type="text" placeholder="Naam" class="form-control">
</div>
<div class="input-group input-group-lg"><span class="input-group-addon"><span class="glyphicon glyphicon-earphone"></span></span>
<input name="phone" type="text" placeholder="Telefoon-nummer" class="form-control">
</div>
<div class="input-group input-group-lg"><span class="input-group-addon"><span class="glyphicon glyphicon-envelope"></span></span>
<input name="email" type="text" placeholder="Email address" class="form-control">
</div>
<div class="input-group input-group-lg">
<textarea rows="5" name="comment" class="form-control"></textarea>
</div>
<input name="submitted" type="submit" class="btn btn-default">
</form>
<?php
}
?>