Die()阻止wp_mail发送邮件

时间:2016-10-04 00:33:47

标签: wordpress email woocommerce

我在woocommerce中有一个简单的注册表格,它应该向注册用户发送电子邮件,但这不会发生。以下是发送表单的代码:

$(".submitbtn").click(function() {
    $('#result').html('<img src="'+ajax_script.loading_img+'" class="loader" />').fadeIn();
    var input_data = $('#wp_signup_form').serialize();
    input_data += '&action=et_register_action';
    $.ajax({
        type: "GET",
        dataType: "JSON",
        url: ajax_script.ajax_url,
        data: input_data,
        success: function(response){
            response = JSON.parse(response);
            console.log(response);
            $('.loader').remove();
            if(response.status == 'error') {
                var msgHtml = '<span class="error">' + response.msg + '</span>';
                $('<div>').html(msgHtml).appendTo('div#result').hide().fadeIn('slow');

            } else {
                var msgHtml = '<span class="success">' + response.msg + '</span>';
                $('<div>').html(msgHtml).appendTo('div#result').hide().fadeIn('slow');
                $('#wp_signup_form').find("input[type=text], input[type=password], textarea").val("");
            }
        }
    });
    return false;
});

这是注册处理程序的摘录:

if ( is_wp_error($status) ) {
    $return['status'] = 'error';
    $return['msg'] = __( "Username already exists. Please try another one.", ETHEME_DOMAIN );
    echo json_encode($return);
}
else {
    $from = get_bloginfo('name');
    $from_email = get_bloginfo('admin_email');
    $headers = 'From: ' . $from . " <" . $from_email . ">\r\n";
    $headers .= "MIME-Version: 1.0\r\n";
    $headers .= "Content-Type: text/html; charset=UTF-8\r\n";
    $subject = __("Registration successful", ETHEME_DOMAIN);
    $message = et_registration_email($username);
    wp_mail($email, $subject, $message, $headers);
    $return['status'] = 'success';
    $return['msg'] = __("Please check your email for login details.", ETHEME_DOMAIN);
    echo json_encode($return);
}
die();

死亡()让我发疯!

  • 如果我保留,页面加载完美,用户就会被添加到列表中但没有邮件到达。
  • 如果我删除它,添加了用户,邮件正确到达但是json字符串附加了'0',所以我无法读取它。

我发现wp_ajax.php以die(0);结束,因此在任何ajax输出的末尾附加一个'0'。一个人应该通过将die()放在自己的代码中来解决这个问题,但是如何?我也尝试使用usleep(800000),但仍然没有工作。

邮件正常工作,所以我不想安装任何第三方插件。 任何帮助都非常感谢。

编辑: 几个小时后,邮件到达发件人邮件地址:

host outbound.mailspamprotection.com [96.127.176.250]
SMTP error from remote mail server after end of data:
550 A URL in this email (8theme . com) is listed on https://spamrl.com/. Please resolve and retry

如果删除die()

,该邮件怎么可能无法识别为垃圾邮件?

2 个答案:

答案 0 :(得分:0)

请尝试使用import java.util.Random; public class NickName_1 { public static void main(String[] args) { java.util.Scanner scanner = new java.util.Scanner(System.in); int letterNum = 6; Random rn = new Random(); char letter1 = (char) (rn.nextInt(26) + 'a'); char letter2 = (char) (rn.nextInt(26) + 'a'); char[] vowels = { 'a', 'e', 'i', 'o', 'u' }; char vowel; while (true) { //Ask user for word's length and store it System.out.println(); System.out.print("Please enter the length of the word in letters: "); letterNum = scanner.nextInt(); vowel = vowels[(int)(Math.random() * 5)]; for (int i = 0; i < (letterNum / 3); i++) { letter1 = (char) (rn.nextInt(26) + 'a'); letter2 = (char) (rn.nextInt(26) + 'a'); vowel = vowels[(int)(Math.random() * 5)]; // if letter1 or letter2 equal a vowel then regenerate letters if (letter1 == 'a' || letter1 == 'u' || letter1 == 'i' || letter1 == 'e' || letter1 == 'o' || letter2 == 'a' || letter2 == 'u' || letter2 == 'i' || letter2 == 'e' || letter2 == 'o') { letter1 = (char) (rn.nextInt(26) + 'a'); letter2 = (char) (rn.nextInt(26) + 'a'); } System.out.print(letter1 + "" + vowel + "" + letter2); } } } } 。可能是某些其他钩子或处理程序需要触发,并且在wp_die()周围使用wp的包装器允许它们执行此操作。

WP Codex Entry:https://codex.wordpress.org/Function_Reference/wp_die

摘录自die

wp-includes/functions.php.

答案 1 :(得分:0)

尝试exit;。或wp_die();