Jump to content

Recommended Posts

Posted

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.

Posted

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>"
                );
        }
});
  • Like 2
Posted

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);
  }

});

 

  • Like 1
  • PWaddict changed the title to [SOLVED] Force HTML on all outgoing emails?

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...