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!

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

报告相同问题?

悬赏问题

  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)