Итак, я пытаюсь создать контактную форму с помощью html и php-скрипта. Я делал это в прошлом (с шаблонами), и все кажется прекрасным, но я попытался создать его самостоятельно, и по некоторым причинам он не загружает скрипт при отправке его на страницу html (действие формы и т. Д. Все правильно) Im guessing он должен быть связан с php, см. код ниже. Любая помощь будет признателен:Форма контакта PHP-скрипт не загружается?
<?php
if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "[email protected]";
$email_subject = "Test form";
function died($error) {
// your error code can go here
echo "We are very sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
// validation expected data exists
if(!isset($_POST['teamname']) ||
!isset($_POST['yourname']) ||
!isset($_POST['secondname']) ||
!isset($_POST['address']) ||
!isset($_POST['postcode']) ||
!isset($_POST['youremail']) ||
!isset($_POST['phone']) ||
!isset($_POST['otherplayername1']) ||
!isset($_POST['otherplayername2']) ||
!isset($_POST['otherplayername3']) ||
!isset($_POST['otherplayername4']) ||
!isset($_POST['otherplayername5']) ||
!isset($_POST['otherplayername6']) ||
!isset($_POST['otherplayername7']) ||
!isset($_POST['location']) ||
{
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$teamname = $_POST['teamname']; // required
$yourname = $_POST['yourname']; // required
$secondname = $_POST['secondname']; // not required
$address = $_POST['address']; // not required
$postcode = $_POST['postcode']; // required
$your-email = $_POST['youremail']; // required
$phone = $_POST['phone']; // not required
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-][email protected][A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$youremail)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$yourname)) {
$error_message .= 'The First Name you entered does not appear to be valid.<br />';
}
if(!preg_match($string_exp,$teamname)) {
$error_message .= 'The Team Name you entered does not appear to be valid.<br />';
}
if(!preg_match($string_exp,$postcode)) {
$error_message .= 'The Post Code you entered does not appear to be valid.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Form details below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "First Name: ".clean_string($teamname)."\n";
$email_message .= "First Name: ".clean_string($yourname)."\n";
$email_message .= "Last Name: ".clean_string($secondname)."\n";
$email_message .= "Address: ".clean_string($address)."\n";
$email_message .= "Postcode: ".clean_string($postcode)."\n";
$email_message .= "email: ".clean_string($youremail)."\n";
$email_message .= "phone: ".clean_string($phone)."\n";
$email_message .= "other player 1: ".clean_string($otherplayername1)."\n";
$email_message .= "other player 2: ".clean_string($otherplayername2)."\n";
$email_message .= "other player 3: ".clean_string($otherplayername3)."\n";
$email_message .= "other player 4: ".clean_string($otherplayername4)."\n";
$email_message .= "other player 5: ".clean_string($otherplayername5)."\n";
$email_message .= "other player 6: ".clean_string($otherplayername6)."\n";
$email_message .= "other player 7: ".clean_string($otherplayername7)."\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);
?>
<!-- include your own success html here -->
Thank you for contacting us. We will be in touch with you very soon.
You can choose to play either on the day or through Paypal (please bring your Paypal reference with you on the match day)
<?php
}
?>
EDIT: Обновленный Php и добавил HTML
Вот и мой HTML форма:
<form name="contactform" method="post" action="contact.php">
<input type="text" name="teamname" value="" size="40" placeholder="Team Name"/><br>
<input type="text" name="yourname" value="" size="40" placeholder="Your Name"/><br>
<input type="text" name="secondname" value="" size="40" placeholder="Last Name"/><br>
<input type="text" name="address" value="" size="40" placeholder="Address"/><br>
<input type="text" name="postcode" value="" size="40" placeholder="Postcode"/><br>
<input type="email" name="youremail" value="" size="40" placeholder="Email"/><br>
<input type="tel" name="phone" value="" size="40" placeholder="Phone Number"/><br>
</div>
<input type="text" name="otherplayername1" value="" size="40" placeholder="Other Players Name 1"/><br>
<input type="text" name="otherplayername2" value="" size="40" placeholder="Other Players Name 2"/><br>
<input type="text" name="otherplayername3" value="" size="40" placeholder="Other Players Name 3"/><br>
<input type="text" name="otherplayername4" value="" size="40" placeholder="Other Players Name 4"/><br>
<input type="text" name="otherplayername5" value="" size="40" placeholder="Other Players Name 5"/><br>
<input type="text" name="otherplayername6" value="" size="40" placeholder="Other Players Name 6"/><br>
<input type="text" name="otherplayername7" value="" size="40" placeholder="Other Players Name 7"/><br>
<input type="text" name="location" value="" size="40" placeholder="Location"/></span><br><br>
<input type="checkbox" /> <a target="_blank" style="color: #fff;">I confirm that I accept the Cash Leagues Rules and Regulations.</a>
<input type="submit" value="Send" action="contact.php"/></form>
Какая ошибка вы получаете? – Florian
он просто загружает пустой экран без сообщения об ошибке или sucess – Dave
См. Мой ответ;) http://stackoverflow.com/a/29895760/3394281 – Florian