首页 > 解决方案 > 使用带附件的 wc_mail

问题描述

我有一封需要发送给第三方的自定义 WooCommerce 电子邮件。在这封电子邮件中,我必须添加一个附件。我试过了,wc_mail()但附件没有附加。

这是它的样子:

$attachment = array();
ob_start(); 
include('some-html-email-content.php');
$message = ob_get_clean();
$attachment[] = get_template_directory() . '/some.pdf';
wc_mail('xxx@example.com', 'some subject ', $message, "Content-Type: text/html\r\n", $attachment);

我可以毫无问题地收到电子邮件,只是附件没有。我做错了什么?

我不能使用woocommerce_email_attachments过滤器挂钩,因为此邮件未附加到任何常规的 woocommerce 邮件(新订单、流程、新用户等....)。

我也尝试过wp_mail()仍然无法通过。

标签: phpwordpressemailwoocommerceemail-attachments

解决方案


$attachment = array(  WP_PLUGIN_DIR . '/my-plugin/uploads/sample_photo_01.jpg' );

附件应始终使用绝对文件系统路径。根据附件所在的位置更改文件的位置/名称。

来源: http: //codex.wordpress.org/Function_Reference/wp_mail http://codex.wordpress.org/Plugin_API/Filter_Reference/wp_mail_content_type


推荐阅读