<?php
if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "test@hotmail.com";
$email_subject = "Website boeking";
// validation expected data exists
if(!isset($_POST['naam-2']) ||
!isset($_POST['email-2']) ||
!isset($_POST['aankomst']) ||
!isset($_POST['vertrek']) ||
!isset($_POST['opmerkingen'])) {
died('Er zijn een paar fouten met je bericht! Probeer het opnieuw.');
}
$naam = $_POST['naam-2']; // required
$email_from = $_POST['email-2']; // required
$aankomst = $_POST['aankomst']; // required
$vertrek = $_POST['vertrek']; // required
$comments = $_POST['opmerkingen'];
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
$email_message = "Ontvangen bericht: \n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "Naam: ".clean_string($naam)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Aankomst datum: ".clean_string($aankomst)."\n";
$email_message .= "Vertrek datum: ".clean_string($vertrek)."\n\n";
$email_message .= "Bericht: \n".clean_string($comments)."\n";
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-to: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
?>
这是我在“ boeking-script.php”中使用的PHP代码
<form id="form-Boeking" name="form-Boeking" data-name="Boeking via website" method="POST" action="boeking-script.php">
<div class="form-text black">Naam *</div><input type="text" class="text-field w-input" maxlength="30" name="naam-2" data-name="naam-2" placeholder="Naam" id="Naam-2" required="">
<div class="form-text black">Email adres *</div><input type="email" class="text-field-2 w-input" maxlength="25" name="email-2" data-name="email-2" placeholder="Email adres" id="Email-adres-2" required="">
<div class="form-text black _50">Aankomst datum *</div>
<div class="form-text black _50 right">Vertrekdatum datum *</div>
<input type="text" class="text-field-2 _50 w-input" maxlength="10" name="aankomst" data-name="aankomst" placeholder="dd-mm-jjjj" id="Aankomst-2" required="">
<input type="text" class="text-field-2 _50 right w-input" maxlength="10" name="vertrek" data-name="vertrek" placeholder="dd-mm-jjjj" id="Vertrek" required="">
<div class="clear"></div>
<div class="form-text">Eventuele opmerkingen</div><textarea id="opmerkingen" name="opmerkingen" maxlength="300" placeholder="Opmerkingen" data-name="Opmerkingen 2" class="textarea"></textarea>
<div class="height-30"></div>
<input type="submit" value="Verstuur" data-wait="Even geduld..." class="button w-button">
</form>
这是我正在使用的表格,我也将这种方式用于联系表格(不同的文件,彼此分开),并且工作得很好。.所以我无法找出问题所在。
P.S。我知道代码有点乱,对此感到抱歉
答案 0 :(得分:0)
在表单代码中没有带有name="email"
的标记,因此在PHP代码中,当您尝试检查是否设置了email
参数时,该代码只会忽略整个代码。
您应该更改
if(isset($_POST['email'])) {
与
if(isset($_POST['email-2'])) {
在PHP代码的开头。