使用wp_mail发送的电子邮件格式

时间:2014-04-17 05:02:19

标签: php wordpress-plugin html-email wordpress

我想以html表的形式发送格式化的电子邮件。我正在使用wp_mail发送电子邮件。

我想知道格式化是如何工作的?现在我没有对内容类型进行任何更改。如果电子邮件编辑器不使用html支持而只使用纯文本,那么使用标记发送的电子邮件会产生什么影响。我希望在这两种情况下都能正确格式化电子邮件。

3 个答案:

答案 0 :(得分:1)

您可以在wp_mail功能之前添加过滤器,然后将其删除。

add_filter( 'wp_mail_content_type', 'set_html_content_type' );
@wp_mail( 'email', 'subject', 'message');
remove_filter( 'wp_mail_content_type', 'set_html_content_type' );

您需要添加以下功能,这些功能已在上述代码中使用的过滤器中调用。

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

有关此过滤器的详细信息,请参阅codex:http://codex.wordpress.org/Plugin_API/Filter_Reference/wp_mail_content_type

答案 1 :(得分:0)

您可以在wordpress中使用add_filter()进行HTML格式化。

像这样:

add_filter('wp_mail_content_type',create_function('', 'return "text/html";'));

wp_mail( $to, $subject, $message, $headers );

这对你有帮助......

答案 2 :(得分:0)

您可以在此处添加模板电子邮件:

1。包括您的模板

include_once(get_template_directory().'/emails/demo.php');

2。向文件模板添加功能

function email_template($id){

....
return $body;
}

* id是您可以输入任何内容的模板电子邮件的可变输入。

3。将您的email_template()的输出放入电子邮件

$body= email_template($varibles);
wp_mail('example@site.com','subject',$body);

很遗憾,您发送的模板电子邮件没有任何插件和外部代码!

S F我的英语!