У меня есть скрипт формы, который отправляет электронное письмо после его отправки. Javascript удаляет форму после ее отправки.
Но когда я отправляю свою форму, он показывает мне пустой.php файл.
Heres мой index.html код:
<!--Here is container with email subscription-->
<div class="container-fluid yellow-container bg-mail">
<div class="row-fluid">
<div class="span12">
<h2>Laat hier je email adres achter, zodat wij weten dat je van de partij bent</h2>
<p>Deze uitnodiging geldt voor jou en een relatie!</p>
<form action="save.php" id="subscribe-form" method="post" name="subscribe-form">
<input type="email" name="email" placeholder="Hier je emailadres" id="email" class="email required">
<button class="btn btn-inverse" id="submit" type="submit" value="Subscribe">Count me in!</button>
</form>
</div>
</div>
</div>
Код save.php:
<?php
if (isset($_POST['email'])) {
//Email information
$admin_email = "[email protected]";
$email = $_POST['email'];
//send email
mail($admin_email, "Inschrijving via Dukdalf", $email . " " . "heeft zich ingeschreven via de website", "Van:" . $email);
}
?>
Код javascript:
//Subscribe Form
if($('#subscribe-form').length && jQuery()) {
$('form#subscribe-form').submit(function() {
$('form#subscribe-form .error').remove();
var hasError = false;
$('.required').each(function() {
if(jQuery.trim($(this).val()) === '') {
var labelText = $(this).prev('label').text();
$(this).parent().append('<div class="error">Vul a.u.b. uw email in.'+labelText+'</div>');
$(this).addClass('inputError');
hasError = true;
} else if($(this).hasClass('email')) {
var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
if(!emailReg.test(jQuery.trim($(this).val()))) {
var labelText = $(this).prev('label').text();
$(this).parent().append('<div class="error">Vul a.u.b. een geldig email in.'+labelText+'</div>');
$(this).addClass('inputError');
hasError = true;
}
}
});
if(!hasError) {
$('form#subscribe-form input.submit').fadeOut('normal', function() {
$(this).parent().append('');
});
var formInput = $(this).serialize();
$.post($(this).attr('action'),formInput, function(data){
$('form#subscribe-form').slideUp("fast", function() {
$(this).before('<div class="error">Bedankt voor het inschrijven!</div>');
});
});
}
return false;
});
Спасибо за помощь заранее :)
он показывает вам вашу пустую страницу php, потому что вы после отправки электронной почты должны перенаправить пользователя куда-нибудь, возможно, с:
header('Location: http://www.example.com/');
exit;
С уважением, Марсело