简体   繁体   English

PHP sendmail表单正在发送空白电子邮件,如何修复Java脚本?

[英]PHP sendmail form is sending blank e-mail, how can I fix java script?

I had problem all day about sendmail.php. 我整天有关于sendmail.php的问题。 First I had proble to not receive e-mail I fix it than I start to receive e-mail blank. 首先,我有没有收到我要解决的电子邮件的问题,而不是开始收到空白的电子邮件。 I undestand the problem wasn't php code or html code, problem was java script wich is attached to contact-form. 我不明白问题不是php代码或html代码,问题是java脚本夹在contact-form上。

var form = $('#main-contact-form');
form.submit(function(event){
    event.preventDefault();
    var form_status = $('<div class="form_status"></div>');
    $.ajax({
        url: $(this).attr('action'),
        beforeSend: function(){
            form.prepend( form_status.html('<p><i class="fa fa-spinner fa-spin"></i> Email is sending...</p>').fadeIn() );
        }
    }).done(function(data){
        form_status.html('<p class="text-success">Thank you for contact us. As early as possible  we will contact you</p>').delay(3000).fadeOut();
    });
});

this is the code which is sending blank e-mail. 这是发送空白电子邮件的代码。 I read an answer similar problem and I understand that I should use this; 我读到类似问题的答案,并且我知道我应该使用它。

var form = $('.contact-form');
form.submit(function () {
    $this = $(this);
    $.post($(this).attr('action'),$(this).serialize(), function(data) {

When I changed recommended code to my code I start to receive e-mail with name topic and message but after clicking the "Send Now" botton page turn to white blank instead of giving message as "Thank you for contact us. As early as possible we will contact you" 当我将推荐的代码更改为我的代码时,我开始收到带有名称主题和消息的电子邮件,但是在单击“立即发送”后,botton页面变为白色空白,而不是显示“感谢您与我们联系。”我们将与您联系”

So I think I couldn't combine to correct code to mine. 因此,我想我无法结合使用正确的代码来进行挖掘。 Can anybody help me to add $.post($(this).attr('action'),$(this).serialize(), function(data) { to my scrpt? Thanks in advance 有人可以帮我添加$.post($(this).attr('action'),$(this).serialize(), function(data) {到我的scrpt吗?

You can always use your code but with two changes, add a "method" to your ajax request, and some data to send to the server. 您始终可以使用代码,但需要进行两次更改,向您的ajax请求添加“方法”,以及一些要发送到服务器的数据。 Also make sure you're working with POST values in the php file 还要确保您正在使用php文件中的POST值

    var form = $('#main-contact-form');
form.submit(function(event){
    event.preventDefault();
    var form_status = $('<div class="form_status"></div>');
    $.ajax({
        url: $(this).attr('action'),
        method: 'post',
        data: $(this).serialize(),
        beforeSend: function(){
            form.prepend( form_status.html('<p><i class="fa fa-spinner fa-spin"></i> Email is sending...</p>').fadeIn() );
        }
    }).done(function(data){
        form_status.html('<p class="text-success">Thank you for contact us. As early as possible  we will contact you</p>').delay(3000).fadeOut();
    });
});

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

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