PWaddict Posted October 14, 2022 Share Posted October 14, 2022 Hi, is it possible to force ProcessWire to send all outgoing emails with HTML instead of Plain Text? Password Reset error email for example is sent as plain text. Link to comment Share on other sites More sharing options...
teppo Posted October 14, 2022 Share Posted October 14, 2022 If you're looking for a generic catch-all solution, there's one approach that I can think of: hooking before WireMail::send and checking if $event->object->bodyHTML is empty but $event->object->body filled, in which case you could generate the "bodyHTML" property based on the "body" property. I've never tried this, but at least this is where I'd start. Looking at ProcessForgotPassword code, there's no obvious way (config setting, hook, etc.) to make it send all messages as HTML, and I would assume that same applies to various other core (and non-core) modules as well, so your best bet is to hook directly into the class responsible for sending the message(s). Basically something like this: wire()->addHookBefore('WireMail::send', function(HookEvent $event) { if ($event->object->body && !$event->object->bodyHTML) { $event->replace = true; wireMail( $event->object->to, $event->object->from, $event->object->subject, $event->object->body, "<p>" . nl2br($event->object->body) . "</p>" ); } }); 2 Link to comment Share on other sites More sharing options...
PWaddict Posted October 14, 2022 Author Share Posted October 14, 2022 Thank you for the hint. Here is what I did and it seems it does the job. $wire->addHookBefore('WireMail::send', function(HookEvent $event) { $WireMail = $event->object; if(!$WireMail->bodyHTML && $WireMail->body) { $forcehtml = nl2br($WireMail->body); // nl2br — Inserts HTML line breaks before all newlines in a string $WireMail->bodyHTML($forcehtml); } }); 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now