Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
uc_order_mail() splits the mail body of html mails up in multiple elements and this leads to some strange rendering behaviours (like escaped html). I think the bug comes from that hook_mail needs the body as an array. But one element in that array is what we need to output valid HTML.
See patch.
Comment | File | Size | Author |
---|---|---|---|
htmlmail.patch | 645 bytes | bjaxelsen | |
|
Comments
Comment #2
TR CreditAttribution: TR commentedSo I finally got around to looking at this ... I guess I don't exactly understand why there's a problem, so the proposed fix seems magical.
explode(), which we currently use, returns an array. So we currently *are* assigning an array to the 'body' element of the e-mail, just like the documentation says we should. Also, it says 'body' is by default an empty array, so we're not overwriting anything in there already.
As far as I can tell, your patch just puts everything including the embedded line separators into one array element, instead of what we currently do which is to split the body at \n separators then put these separate lines into separate array elements of the body and let drupal_mail() handle the separators. That's what the documentation says we should do. See https://api.drupal.org/api/drupal/core%21core.api.php/function/hook_mail...
The core contact.module (contact_mail() implements hook_mail()) is similar to uc_order_mail() in that it adds multiple lines to the body instead of putting everything on one line.
However, it wouldn't surprise me a bit to learn the documentation is outdated or wrong ... But I can't find a change notice that describes anything that affected what should go into the body.
Comment #3
bjaxelsen CreditAttribution: bjaxelsen at Fagkommunikation for BYG-ERFA commentedJust to clarify:
The problem I ran into was:
Because each newline (not each HTML elements) triggers a new subelement in the mail body, the HTML of each body element is no more correct HTML due to open tags and HTML gets escaped. This is a problem we need to solve.
If we look at contact_mail we have this code:
As you can see, the HTML part (the last element) is contained in a single subelement. So we don't get broken HTML here.
And in the API documentation, in hook_mail:
This is also an array, but the HTML is contained in a single array value. This is what I want to do.
So the problem is not that we need to put everything is one subelement, but it is that when we have a HTML structure (like a table element with rows and columns), we cannot split it up for every newline without breaking the HTML structure and causing problems.
Comment #5
TR CreditAttribution: TR commentedI must have missed seeing your reply ... Anyway, I've been using your patch for a year, and it works for me. Committed.
Thanks for finding this and supplying the patch.