wp_mail()方法在某些情况下不发送电子邮件

时间:2018-06-12 08:10:33

标签: php wordpress phpmailer

这是我通过wp_mail()方法

发送电子邮件的代码
$user_email = $_POST["user_email"];
$subject = 'Account is ready.';
$message = "Hello <b>$user_name</b>,a new account created for you and you need to create a password, <a href'http:example.com/account?email=$user_email'>click here</a>  to create a password and login.";

$headers[] = 'MIME-Version: 1.0';
$headers[] = 'Content-type: text/html; charset=iso-8859-1';

$mail = wp_mail($user_email, $subject, $message, $headers);
if($mail){
    echo 'Sent email to user.';
}
 else {
    echo 'Oops something went wrong to sending email.';
}

实际上这不起作用我的意思是不向用户发送电子邮件,同时修改wp_mail()这样的方法

$mail = wp_mail($user_email, $subject, $message);

这是有效的,它意味着它从未超过三个参数,但我需要为HTML添加$headers

我现在能做什么?

有任何建议吗?

由于

2 个答案:

答案 0 :(得分:0)

根据wp_mail docs,headers参数用于设置From,CC和BCC字段。它可能没有设置其他字段。

要设置内容类型和字符集,您需要使用其他功能,请参阅链接的文档。 邮件默认以纯文本形式发送,要以HTML格式发送,您还应该查阅链接文档,因为切换到HTML的方法也在那里。

答案 1 :(得分:-1)

您是否设置了WordPress面板中的SMTP设置,如果没有,您可以使用许多插件进行设置,您可以使用m fav插件 https://wordpress.org/plugins/post-smtp/ 尝试设置此插件,然后让我知道您是否仍然面临这些问题