Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/262.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在同一页面上提交表单时显示ajax成功或错误消息_Php_Jquery_Ajax - Fatal编程技术网

Php 在同一页面上提交表单时显示ajax成功或错误消息

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

我在DIV标签中获得了发送给apear的消息,但不确定如何将电子邮件地址发送到外部电子邮件数据库//myguestlist.com/mgl/formreceiver.php

这是HTML文件

第一个知道七频道布里斯班比赛的人 嘉年华:


你有没有试过
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;
});