doujiong3146 2015-02-28 11:50
浏览 44
已采纳

为什么wp_mail()函数返回'false'?

I have a contact form that gets from ajax parameters and uses them to send emails. The function is located in functions.php of my child theme for twentyfifteen:

// Contact form  Ajax 

add_action('wp_ajax_nopriv_submit_contact_form', 'submit_contact_form'); 

function submit_contact_form(){

    if(isset($_POST['email'])) {

        $email = $_POST['email'];       
        $email_to = "wawd@company.pro";

        $email_subject = "You have a new email from $email via yyy.com website";
        $message = $_POST['text']; 

        if( wp_mail( $email_to, $email_subject, $message ) ) {
            // the message was sent...
            echo 'The test message was sent. Check your email inbox.';
        } else {
            // the message was not sent...
            echo 'The message was not sent!';
        };



//      wp_mail( $email_to, $email_subject, $message );
        header("Content-Type: application/json", true);
        echo json_encode( array("AJAX" => "Success") );
        die();

    }
}





error_reporting(E_ALL);
ini_set("display_errors", 1);

I'm getting a response of the message was not sent! AJAX: "Success".

Why my function isn't working? Do I have to include something in my php file? I var_dumped the parameters that I get from ajax, the are all displayed fine in the response with a status code of Status Code:200 OK.

  • 写回答

1条回答 默认 最新

  • dseslyh6662605 2015-03-01 09:19
    关注

    I installed a package called "PostFix" which is responsible for sending emails from an Ubuntu server (which is the servers Linux I use), and it solved the problem!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 YOLO检测微调结果p为1
  • ¥20 求快手直播间榜单匿名采集ID用户名简单能学会的
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题