• Resolved faramirezs

    (@faramirezs)


    Hi!!

    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 https://a.cl.ly/8LubPx2O

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

    PHP warning:
    file_get_contents(https://mywebsite.com/wp-content/uploads/woocommerce_uploads/2xxx/xx/file25022021-bxxg5x.docx): 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)
  • Hi @faramirezs,

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

    Kind Regards,
    Tim

    @faramirezs
    Hi,

    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

    (@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 3 years, 7 months ago by faramirezs.
    • This reply was modified 3 years, 7 months ago by faramirezs.

    Thanks for feeding back, thread marked as resolved.

    Kind Regards,
    Tim

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘email attachments 403 forbidden’ is closed to new replies.