Support » Plugin: Post SMTP Mailer/Email Log » email attachments 403 forbidden

  • Resolved faramirezs



    I sell documents in my store. After payment, I send a confirmation email using Post SMTP with download links. The user can download without login. Recently we started to test woocommerce_email_attachments dedicated hook for send the documents not as a Link but as email attachtments to the order confirmation email.

    We used this hook, from here:

    add_filter( 'woocommerce_email_attachments', 'attach_downloadable_files_to_customer_completed_email', 10, 3 );
    function attach_downloadable_files_to_customer_completed_email( $attachments, $email_id, $order ) {
        if( isset( $email_id ) && $email_id === 'customer_completed_order' ){
            // Loop through order items
            foreach( $order->get_items() as $item ) {
                $product = $item->get_product(); // The product Object
                if ( $product->is_downloadable() && ( $downloads = $product->get_downloads() ) ) {
                    // Loop through product downloads
                    foreach( $downloads as $download ) {
                        $attachments[] = $download->get_file();
        return $attachments;

    I create a stage website of my site and I tested the hook. The code works, the email get the attachments with the confirmation order email.

    When I did the same in my production website, my customers rececived the confirmation email with empty files… the attachments were there but with 0 kb.

    Also PHP warnings saying that the URL of the downloable product was blocked, 403 forbidden

    The file URL is something like: wp-content/upload/woocommerce_upload/2020/02/file.docx

    PHP warning:
    file_get_contents( failed to open stream: HTTP request failed! HTTP/1.0 403 Forbidden

    post-smtp plugin

    in /home/xxxxxxxxxxxx/public_html/wp-content/plugins/post-smtp/Postman/Postman-Mail/PostmanMessage.php on line 515

    thank you in advance for your attention.

    In Woocommerce support and Stackoverflow

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Support Tim


    Hi @faramirezs,

    Escalating this to the developer @yehudah as he will be best fixed for a reply.

    Kind Regards,

    Plugin Author yehudah



    Looks like that in production something is blocking the file_get_contents function.

    the function is safe when you get file content from the local server, please check your hosting support why the request was blocked.

    Thread Starter faramirezs


    Thank you so much!

    The problem is solved:

    • In woocommerce_upload folder
    • Replace the .htaccess content with this:
    • order deny,allow
      deny from all
      allow from <your ip or server IP or hosting IP>
    • This reply was modified 1 month, 4 weeks ago by faramirezs.
    • This reply was modified 1 month, 4 weeks ago by faramirezs.
    Plugin Support Tim


    Thanks for feeding back, thread marked as resolved.

    Kind Regards,

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.