weixin_33736832 2011-05-06 08:28 采纳率: 0%
浏览 121

Wordpress AJAX发送电子邮件

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?

This is the 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. 
    }

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";
        }
    }
}

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.

  • 写回答

1条回答 默认 最新

  • derek5. 2011-05-11 14:53
    关注

    As you see you make:

    vardata = {'donorEmail':$('#email').val(),'action':'mail_action' };

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

    try calling $_POST['donorEmail'];

    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?