字preSS AJAX发送电子邮件 [英] Wordpress AJAX sending email

查看:92
本文介绍了字preSS AJAX发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想企业发送电子邮件前提交的字preSS页的形式。我能够做AJAX部分和成功发送电子邮件。然而,电子邮件不是100%传递。我想知道为什么?

I'm trying to corporate sending email before submitted the form in wordpress page. I'm able to do the AJAX part and send email successfully. However, the email is not 100% delivered. I wonder why?

这是在code



    var data = {};
    data.donorEmail = $("#email").val();
    data.action = "mail_action";
    $("#donorSubmit").click(function(e){
        $.post('http://www.myurl.com/wp-admin/admin-ajax.php',data, onSuccess);
    });

    function onSuccess(results)
    {
        if( results == "00")
            document.forms['donorForm'].submit() // After the email is sent then submit the form to another website. 
    }

这是code中的functions.php

And this is the code in functions.php


add_action('wp_ajax_mail_action', 'sending_mail');
add_action('wp_ajax_nopriv_mail_action', 'sending_mail');

function sending_mail(){
    if(isset($_POST['email']))
    {
        $to = "myemail@mydomain.com";
        $subject = "Donation";
        $message = $_POST['email']; 

        if(mail($to, $subject, $message))
        {
            echo "0";
        }
    }
}

通过这个code我收到邮件的所有时间。但是,电子邮件的内容应该是用户的电子邮件不来的电子邮件的所有时间。有时它只是一个空白的内容。

With this code I receive the email all the time. However, the content of the email which should be the email of user doesn't come with the email all the time. Sometime it's just a blank content.

推荐答案

正如你看到你做:

VARDATA = {'donorEmail:$('#邮件)VAL(),动作:mail_action'};

但在你的PHP文件,你要求 $ _ POST [电子邮件] ,而不是 $的_ POST ['donorEmail'];

but in your php file you request the $_POST['email'] instead of $_POST['donorEmail'];

尝试调用 $ _ POST ['donorEmail'];

这篇关于字preSS AJAX发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆