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/htmlrn", $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.
3
Answers
Turn out is the directory permission issue. So, change the upload directory to 755 and it works. Thanks for the helps.
Would something like this work? I think the way you are assigning values to the array variable might be incorrect?
$getAttachment = get_template_directory() . ‘/some.pdf’;
$attachment = array(“{$getAttachment}”);
corrected, sorry.
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