WordPress的电子邮件将成为垃圾邮件

时间:2020-09-01 15:19:52

标签: wordpress smtp

我正在使用WP Mail SMTP插件。

function set_my_mail_content_type() {
    return "text/html";
}

function send_smtp_email( PHPMailer $phpmailer ) {
    $phpmailer->isSMTP();
    $phpmailer->Host       = WPMS_SMTP_HOST;
    $phpmailer->SMTPAuth   = WPMS_SMTP_AUTH;
    $phpmailer->Port       = WPMS_SMTP_PORT;
    $phpmailer->Username   = WPMS_SMTP_USER;
    $phpmailer->Password   = WPMS_SMTP_PASS;
    $phpmailer->SMTPSecure = WPMS_SSL;
    $phpmailer->From       = WPMS_SMTP_FROM;
    $phpmailer->FromName   = WPMS_SMTP_USER;
}

add_action( 'plugins_loaded', 'renderHTML' );

 function renderHTML(){
    $to = "nvillarejoupwork@gmail.com"; //sendto@example.com
    $subject = 'The subject';
    $body = 'The email body content';
    $headers = array('Content-Type: text/html; charset=UTF-8');
    add_filter( 'wp_mail_content_type','set_my_mail_content_type' );
    add_action( 'phpmailer_init', 'send_smtp_email' );
    wp_mail( $to, $subject, $body, $headers );
}

function send_smtp_email( PHPMailer $phpmailer ) {
    $phpmailer->isSMTP();
    $phpmailer->Host       = WPMS_SMTP_HOST;
    $phpmailer->SMTPAuth   = WPMS_SMTP_AUTH;
    $phpmailer->Port       = WPMS_SMTP_PORT;
    $phpmailer->Username   = WPMS_SMTP_USER;
    $phpmailer->Password   = WPMS_SMTP_PASS;
    $phpmailer->SMTPSecure = WPMS_SSL;
    $phpmailer->From       = WPMS_SMTP_FROM;
    $phpmailer->FromName   = WPMS_SMTP_USER;
}

上面有我的代码。它正在发送电子邮件,但它们将进入垃圾邮件文件夹。 我不知道为什么。 你能帮我吗?

1 个答案:

答案 0 :(得分:0)

此类常规内容将始终由较大的邮件提供商进行垃圾邮件过滤。您可以将Gmail中的电子邮件地址列入白名单,也可以尝试使用真实姓名和真实邮件。

另一个问题可能是电子邮件(FROM)和服务器的IP地址没有MX记录。在这种情况下,您可能需要使用SMTP插件。