Php 在同一页面上提交表单时显示ajax成功或错误消息
我在DIV标签中获得了发送给apear的消息,但不确定如何将电子邮件地址发送到外部电子邮件数据库//myguestlist.com/mgl/formreceiver.php 这是HTML文件 第一个知道七频道布里斯班比赛的人 嘉年华:Php 在同一页面上提交表单时显示ajax成功或错误消息,php,jquery,ajax,Php,Jquery,Ajax,我在DIV标签中获得了发送给apear的消息,但不确定如何将电子邮件地址发送到外部电子邮件数据库//myguestlist.com/mgl/formreceiver.php 这是HTML文件 第一个知道七频道布里斯班比赛的人 嘉年华: 你有没有试过console.log(json.message)?原谅我,我不是一个真正的编码员,我该怎么说呢?如果你不是编码员,你怎么能这样编码?将console.log(json.message)放入if(json.valid==0)和else中,使用chro
你有没有试过
console.log(json.message)
?原谅我,我不是一个真正的编码员,我该怎么说呢?如果你不是编码员,你怎么能这样编码?将console.log(json.message)
放入if(json.valid==0)和else
中,使用chrome时按f12并检查控制台
method="post" id="mf528c0a39d76be"> <input class="mailchimp-input"
input="" name="PatronEmail" id="mf528c0a39d76be_PatronEmail"
placeholder="Enter your email..." type="text"> <button type="submit"
class="btn"><span class="singup-image"><img src="img/send.png"
alt="send email"></span><span class="singup-text">Send</span></button>
</form>
<div class="success-message"></div>
<div class="error-message"></div>
</div>
<?php
// Enter the email where you want to receive the notification when someone subscribes
$emailTo = 'wbriton@brc.com.au';
$subscriber_email = ($_POST['PatronEmail']);
if(!isEmail($subscriber_Email)) {
$array = array();
$array['valid'] = 0;
$array['message'] = 'Insert a valid email address!';
echo json_encode($array);
}
else {
$array = array();
$array['valid'] = 1;
$array['message'] = 'Thanks for your subscription!';
echo json_encode($array);
// Send email
$subject = 'New Subscriber!';
$body = "You have a new subscriber!\n\nEmail: " . $subscriber_email;
// uncomment this to set the From and Reply-To emails, then pass the $headers variable to the "mail" function below
//$headers = "From: ".$subscriber_email." <" . $subscriber_email . ">" . "\r\n" . "Reply-To: " . $subscriber_email;
mail($emailTo, $subject, $body);
}
$('.subscribe form').submit(function() {
var postdata = $('.subscribe form').serialize();
$.ajax({
type: 'POST',
url: 'php/sendmail.php',
data: postdata,
dataType: 'json',
success: function(json) {
if(json.valid == 0) {
$('.success-message').hide();
$('.error-message').hide();
$('.error-message').html(json.message);
$('.error-message').fadeIn();
}
else {
$('.error-message').hide();
$('.success-message').hide();
$('.subscribe form').hide();
$('.success-message').html(json.message);
$('.success-message').fadeIn();
}
}
});
return false;
});