Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using wc_mail with attachment

I have a custom WooCommerce email that needs to send to the third party. In this email, I have to add an attachment. I tried with wc_mail() but the attachment not attached.

Here is how it look likes:

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

I can receive the email without any problem, only the attachment is not there. What did I done wrong?

I can't use woocommerce_email_attachments filter hook, because this mail isn't attached to any regular woocommerce mail (new order, process, new user etc....).

I also tried with wp_mail() still I cannot make it through.

like image 826
dev-jim Avatar asked Jun 25 '26 14:06

dev-jim


1 Answers

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

Attachments should always use the absolute filesystem path. Change location/name of file based on where the attachment is located.

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

like image 174
Aliqua Avatar answered Jun 28 '26 02:06

Aliqua