What is the reasoning behind setting the content type of every email, regardless of content, to text/html?
IMO, you should not be modifying the content type to text/html if the email has no HTML in it.
Thread Starter
Jld142
(@jld142)
Hello Jason,
My website sends out HTML emails in the following situations:
– new user registers
– user forgets password
– new comment on a users post
– new message received by user front end
My website only sends plains text emails from the contact 7 forms… It therefore IMO made sense to set all emails to be html, and force a specific to be plain text rather than keep default as plain text as default and then specify HTML for a majority.
Does this make sense ?
The plugin uses wp_mail() to send all emails, so whatever content type you set with wp_mail_content_type is going to effect the plugin’s emails.
So if you change the content type, you can send HTML emails for the plugin. You can format the email content accordingly. So you are not too far off track.
But to send one or the other based on the user’s ability to receive specific content types, you’d need to build in some kind of appropriate logic to make your determination of what the user can receive. That’s outside the plugin.
Whatever that logic is, I would say do it outside of your wp_mail_content_type filter because you’ll also need to filter the email content for whatever email you are sending for the plugin.
You can filter the plugin’s emails with wpmem_email_filter. Basically, what you need to filter with that is the main content so that you send an email containing HTML or text accordingly.
Then if the email is going to be HTML or text, set the content type accordingly.
Thread Starter
Jld142
(@jld142)
Hello Chad,
Apologies, either I have read your response incorrectly or you have misunderstood my requirement.
It is best practice to sent an HTML email with a plain text attachment. This allows a user to read the information if their client does not support HTML.
Sending either HTML or Plain text is not the issue. I would like to send both to maximise full compatibility.
See this URL:
https://litmus.com/blog/best-practices-for-plain-text-emails-a-look-at-why-theyre-important
It therefore IMO made sense to set all emails to be html, and force a specific to be plain text rather than keep default as plain text as default and then specify HTML for a majority.
Does this make sense ?
Not really 😉 I understand what you’re trying to do. But just because you change the content-type flag of an email from text to HTML, doesn’t mean the content of the email is going to change.
A text email with a content-type of text/html is still is a text email.
Do you see what I mean?
When a mail client receives a text/html email, this means it must render the content in an HTML viewer, rather than a text viewer, and what is the point of loading a HTML viewer when there is no HTML? It also means that plain clients that should be able to display your email, like the Apple Watch I mentioned to you earlier, will display nothing!
There are WordPress plugins that will actually change the content of your email to be HTML, and I think that’s what you want. Of course, they set the appropriate content type upon creation. https://ww.wp.xz.cn/plugins/wp-email-template/
Though this is mostly irrelevant to your request to have @cbutlerjr add multipart/alternative support to WP-Members 😉