Support » Plugin: Mailgun for WordPress » Both parts of multipart emails being sent as html

  • When sending emails from WooCommerce everything works fine, the multipart email contains both a text/plain and text/html part that has plain text under the plain section and HTML text under the html section

    However once Mailgun is active then HTML appears under both the plain section and the html section so anyone viewing a plain text email gets a load of HTML code

    We are using the PAI route and have the latest version


Viewing 3 replies - 1 through 3 (of 3 total)
  • Sorry that should say API


    I have just discovered the same problem, and it’s not specific to WooCommerce; it’s all email sent from the WordPress instance through the Mailgun plugin.

    While viewing the raw message, there are certainly two MIME types, Content-Type: text/plain; charset="ascii" and Content-Type: text/html; charset="ascii", both with the same HTML content.

    I am currently focusing on the includes/wp-mail-api.php file to see if I can determine the problem…

    I found the problem.

    If the content type is already set to “text/html”, then lines 288-290 of includes/wp-mail-api.php will set both the text and HTML message bodies to the same value.

    Line 260 has a comment “…and *attempt* to strip tags and provide a text/plain version.” but there never is any HTML-to-text conversion.

    Further, the clever trick (lines 259-275) of trying to save the content body to a temp file and sniff the content type that way (in the absence of an explicit content type) isn’t very useful.

    For me, the easy fix was to incorporate the html2text PHP library, then change lines 285-291 to:

        if( $content_type == 'text/html' )
            $body['text'] = convert_html_to_text( $message );
            $body['html'] = $message;
Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.