本文介绍了wp_mail返回true,但没有收到邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用wp_mail()来接收它是通过一个接触的形式在我的字preSS博客提交邮件。 wp_mail()返回true,但事情是我没有收到任何邮件。我也试图改变的邮件地址从Gmail,但没有运气到Hotmail。

阿贾克斯code。在我接触的模板

  $('#发送)。点击(函数(){
    //进行验证
    功能validateText(名字){
        VAR模式= /^[a-zA-Z'-.\s]+$/;
        如果(pattern.test(名)){
            返回true;
        }
        返回false;
    }
    //进行验证
    功能validateMail(邮件){
        VAR模式= /^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z]{2,3}$/;
        // VAR模式= /^\w+@[a-zA-Z_]+?\.[a-zA-Z]{2,3}$/;
        如果(pattern.test(邮件)){
            返回true;
        }
        返回false;
    }
    //从形式获取值
    变种名称= $('#姓名)VAL(),邮件= $('#mailid)VAL(),查询= $('#信息)VAL()错误= 1。;
    //进行验证
    如果(名称==||!(validateText(名称))){
        $('#姓名)addClass(错误)。
        错误= 0;
    }
    ////进行验证
    如果(邮件==||!(validateMail(邮件))){
        $('#mailid)addClass(错误)。
        错误= 0;
    }
    //进行验证
    如果(查询==){
        $('#信息)addClass(错误)。
        错误= 0;
    }
    如果(!错误){//如果验证失败
        返回false;
    }

    $('#请将SendAlert)显示()。
        $('#发送)HTML('发送...');
        $。员额(ajax_object.ajaxurl,{//使用AJAX POST方法发送数据
            动作:ajax_action,
            sendmail的:无,
            名称:名称,
            邮件:邮件,
            查询:查询
        },功能(数据){
            $('#发送)HTML(发送);
            警报(数据); //提醒响应
            返回false;
        });

   });
 

在functions.php中

 函数ajax_action_stuff(){
如果(使用isset($ _ POST ['sendmail的'])){

    功能set_html_content_type()
    {
    回归text / html的;
    }

    如果(使用isset($ _ POST ['名称'])及和放大器;使用isset($ _ POST ['邮件'])及和放大器;使用isset($ _ POST ['查询'])){

    $名称= $ _ POST ['名称'];
    $电子邮件= $ _ POST ['邮件'];
    $查询= $ _ POST ['查询'];
    $到='[email protected]';

    如果($名称==|| $电子邮件==|| $查询==){
        回声失败;
        返回false;
    }

    $主题=网站 - 从查询$名。
    $消息=你好,
        < P><强>名称< / STRONG>:。$名字< / P>
        < P><强>邮件和LT; / STRONG>:。$电子邮件< / P>
        < H3><强>查询< / H3>
        &其中; P>中$查询。&所述; / P>中;
    $头[] ='来自:[email protected]'。\ r \ N的;
    $头[] ='';

    的add_filter('wp_mail_content_type','set_html_content_type');
    $ mailsent = wp_mail($到,$主题,$消息,$头);
    remove_filter('wp_mail_content_type','set_html_content_type'); //重新设置内容类型,以避免冲突 -  HTTP://core.trac.word$p$pss.org/ticket/23578


    如果($ mailsent){
        回声$到;
    } 其他 {
        回声错误;
    }
   } 其他 {
    回声错误;
   }

 } 其他 {
    回声错误;
 }
 死();
   }
   add_action('wp_ajax_ajax_action','ajax_action_stuff');
   add_action('wp_ajax_nopriv_ajax_action','ajax_action_stuff');
 

解决方案

有您的电子邮件被标记为垃圾邮件的可能性,或者它只是你的电子邮件提供商不允许其到达您的收件箱,你通过SMTP发送?

你有SPF记录设置?如果您发送从您的网站的电子邮件,并有从标题设置为 @ gmail.com @ hotmail.com ,这将肯定不会在收件箱中到达的邮件不会从Gmail或Hotmail的服务器发起,它是从你的到来,所以它想的你正在尝试一些网络钓鱼攻击。

编辑:

这意味着该邮件已经离开你的服务器,这并不意味着它会到达您的收件箱,因为有您的服务器和您的收件箱之间的许多其他步骤,以及一些不同的东西可以去错在这个过程中。尝试测试了从:头,更改为 [email protected]

I am using wp_mail() to receive mails which is submitted through a contact form in my wordpress blog. wp_mail() returns true but the thing is i am not receiving any mails. I have also tried to change the mail address to hotmail from gmail but no luck.

Ajax code in my contact template

$('#send').click(function() {
    //For Validation
    function validateText(name) {
        var pattern = /^[a-zA-Z'-.\s]+$/;
        if (pattern.test(name)) {
            return true;
        }
        return false;
    }
    //For Validation
    function validateMail(mail) {
        var pattern = /^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z]{2,3}$/;
        //var pattern = /^\w+@[a-zA-Z_]+?\.[a-zA-Z]{2,3}$/;
        if (pattern.test(mail)) {
            return true;
        }
        return false;
    }
    //Getting values from the form
    var name = $('#name').val(), mail = $('#mailid').val(), query = $('#message').val(), error = 1;
    //For Validation
    if(name == "" || !(validateText(name))) {
        $('#name').addClass('error');
        error = 0;
    }
    ////For Validation
    if(mail == "" || !(validateMail(mail))) {
        $('#mailid').addClass('error');
        error = 0;
    }
    //For Validation
    if(query == "") {
        $('#message').addClass('error');
        error = 0;
    }
    if(!error) { // If validation fails
        return false;
    }

    $('#sendAlert').show();
        $('#send').html('Sending...');
        $.post(ajax_object.ajaxurl, { // Using ajax post method to send data
            action: 'ajax_action',
            sendmail: 'nothing',
            name: name,
            mail: mail,
            query: query
        }, function(data) {
            $('#send').html('Send');
            alert(data); // Alerting response
            return false;
        });

   });

In Functions.php

function ajax_action_stuff() {
if(isset($_POST['sendmail'])) {

    function set_html_content_type()
    {
    return 'text/html';
    }

    if(isset($_POST['name']) && isset($_POST['mail']) && isset($_POST['query'])) {

    $name = $_POST['name'];
    $email = $_POST['mail'];
    $query = $_POST['query'];
    $to = '[email protected]';

    if($name == "" || $email == "" || $query == "") {
        echo "Fail";
        return false;
    }

    $subject = "Website - Query from ".$name;
    $message = "Hi,
        <p><strong>Name</strong>:".$name."</p>
        <p><strong>Mail</strong>:".$email."</p>
        <h3><strong>Query</h3>
        <p>".$query."</p>";
    $headers[] = 'From: [email protected]'."\r\n";
    $headers[] = '';

    add_filter( 'wp_mail_content_type', 'set_html_content_type' );
    $mailsent = wp_mail( $to, $subject, $message, $headers);
    remove_filter( 'wp_mail_content_type', 'set_html_content_type' ); // reset content-type to to avoid conflicts -- http://core.trac.wordpress.org/ticket/23578


    if($mailsent) {
        echo $to;
    } else {
        echo 'error';
    }
   } else {
    echo 'error';
   }

 } else {
    echo 'error';
 }
 die();
   }
   add_action( 'wp_ajax_ajax_action', 'ajax_action_stuff' );
   add_action( 'wp_ajax_nopriv_ajax_action', 'ajax_action_stuff' );
解决方案

There is a possibility that your email is being marked as spam, or it's simply your email provider is not allowing it to reach your inbox, are you sending via SMTP?

Do you have SPF records setup? If you are sending an email from your website, and have the from header set as @gmail.com or @hotmail.com, this will surely not arrive in your inbox as the email is not originating from the gmail or hotmail servers, it's coming from yours, so it think's you are trying some phishing attack.

Edit:

That means the mail has left your server, it doesn't mean it'll arrive in your inbox, as there are many other steps between your server and your inbox, and a few different things could of went wrong in this process. Try testing out the From: header, change to [email protected]

这篇关于wp_mail返回true,但没有收到邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 18:29