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!

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

报告相同问题?

悬赏问题

  • ¥100 有人会搭建GPT-J-6B框架吗?有偿
  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名