简体   繁体   English

使用json发送电子邮件

[英]sending email by using json

i am trying to send email and the code working fine this part should be the reply after clicking on submit but when i click submit it this is what appears 我正在尝试发送电子邮件,并且代码工作正常,这部分应该是单击“提交”后的答复,但是当我单击“提交”时,这就是显示的内容

{"nameMessage":"","emailMessage":"","messageMessage":""} 

this is the part that is not working properly 这是无法正常工作的部分

var postdata = $('.contact-form form').serialize();
    $.ajax({
        type: 'POST',
        url: 'sendmail.php',
        data: postdata,
        dataType: 'json',
        success: function(json) {
            if(json.nameMessage != '') {
                $('.contact-form form .nameLabel').append(' - <span class="violet" style="font-size: 13px; font-style: italic"> ' + json.nameMessage + '</span>');
            }
            if(json.emailMessage != '') {
                $('.contact-form form .emailLabel').append(' - <span class="violet" style="font-size: 13px; font-style: italic"> ' + json.emailMessage + '</span>');
            }
            if(json.messageMessage != '') {
                $('.contact-form form .messageLabel').append(' - <span class="violet" style="font-size: 13px; font-style: italic"> ' + json.messageMessage + '</span>');
            }
            if(json.nameMessage == '' && json.emailMessage == '' && json.messageMessage == '') {
                $('.contact-form form').fadeOut('fast', function() {
                    $('.contact-form').append('<p><span class="violet">Thanks for contacting us!</span> We will get back to you very soon.</p>');
                });
            }
        }
    });
    return false;
});
});

Although your question is not very clear, What your code does is send a mail for contacting and your php sends error messages for name, email or message (if inappropriate) 尽管您的问题不是很清楚,但是您的代码的作用是发送一封邮件进行联系,而您的php发送的错误消息包括名称,电子邮件或消息(如果不合适)

So you are saying that you are receiving 所以你说你正在接受

{"nameMessage":"","emailMessage":"","messageMessage":""} 

as response for your ajax request, which should work perfectly, either your response from PHP is something else, you should check your network request and see whats coming as response, also check the data that is being sent. 作为对ajax请求的响应(应该可以正常工作),或者来自PHP的响应是另一回事,您应该检查网络请求并查看响应是什么,还要检查正在发送的数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM