awesomemotive / wp-mail-logging

:envelope: Logs each email sent by WordPress.
49 stars 26 forks source link

Resend Breaks Email #166

Open slyvioborin opened 1 year ago

slyvioborin commented 1 year ago

If you resend the email by using the button on the Email Log page, it breaks the email sent. While the first email sent is normal, resent email is raw HTML.

donmhico commented 1 year ago

@slyvioborin - Thank you for creating this issue. Can you provide more information? Like what PHP version and WordPress version were you using? I tried reproducing with the emails sent by WooCommerce and WPForms plugins and unfortunately I can't reproduce the issue.

It will be awesome if you can provide your steps to reproduce the issue.

slyvioborin commented 1 year ago

@donmhico thanks for your reply

PHP version: 8.0.28 Wordpress version: 6.2 Language: tr_TR WP Mail Logging Version: 1.11.0 WP Mail SMTP Version: 3.8.0

Reproduction steps: Send test email from "Email Test" page in WP Mail SMTP plugin test email sent normally (everything good) view the mail sent from "Email Log" page in WP Mail Logging page. use resend button (sends the previous email as plain text (all html codes as plain text))

donmhico commented 1 year ago

@slyvioborin - Thank you for your response and for providing the steps to reproduce. We're able to replicate the issue.

The issue is not with WP Mail Logging. How WP Mail Logging works is that it captures the mail sent via wp_mail filter. Then it re-uses the captured headers when re-sending the email (see here).

In the case of WP Mail SMTP, the email test doesn't explicitly add the Content-Type: text/html in the headers and just uses wp_mail_content_type filter to set the content type. The email is still sent as HTML because when this filter is activated, the $phpmailer object's content type is set to HTML but the Content-Type: text/html is not added in the headers.

So when wp_mail hook from WP Mail Logging captures the test email from WP Mail SMTP, it does not have the Content-Type: text/html header. So when we resend it, it does not know that the test email is an HTML.

The good news is this issue should only affect emails that was sent without Content-Type: text/html header. If you test this with WooCommerce, the resend will work as intended.

We also are fixing this issue on WP Mail SMTP's side.