skip to Main Content

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


  1. Chosen as BEST ANSWER

    Turn out is the directory permission issue. So, change the upload directory to 755 and it works. Thanks for the helps.


  2. 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.

    Login or Signup to reply.
  3. $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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search