php - 使用带附件的 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()
仍然无法通过。
解决方案
$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
推荐阅读
- ruby-on-rails - Javascript 函数无法按预期工作
- php - 邮递员返回'????' 阿拉伯名字的输出
- angular - Angular:带有ajax调用响应建议的文本字段
- c# - 在 C# SQL Server 中使用内连接(在 C# ADO.NET 中使用 SQL 查询和内连接从多个表中检索数据)
- php - 如何进行客户端和服务器端验证?
- xcode - 带有推送通知的 Xamarin.iOS 应用程序:开发期间的配置文件无效
- python - Python Selenium - 在网站中搜索数据表值
- three.js - Threejs模型设置位置为(0, 0, 0),但场景显示不是(0, 0, 0)
- python - 在 keras 中训练 CNN 进行文本分类时出错“ValueError:输入 0 与层不兼容”
- serilog - Serilog 事件未保存