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.
Problem/Motivation
Some of the form fields that are assigned in the email handler can contain special characters (single quote, double quote, less than, greater than).
Before sending the email the special characters get converted to HTML code. The preview however is fine.
Steps to reproduce
- You can use the "Basic email contact webform" provided with webform.
- Enter special characters in the Subject field and/or Your name field
- Optional check the preview (needs to be enabled prior for this contact form)
- Send/submit the form.
- Check the site email account or the submissions.
Comment | File | Size | Author |
---|---|---|---|
#23 | screenshot inbox.png | 49.55 KB | geroldk |
#22 | webform.webform.contact_html_encoded.yml | 3.76 KB | jrockowitz |
#21 | with #19.png | 127.72 KB | geroldk |
#21 | before #13 and #19.png | 122.75 KB | geroldk |
#20 | email_handler_field_s-2895140-19.patch | 18.16 KB | jrockowitz |
|
Comments
Comment #2
jrockowitz CreditAttribution: jrockowitz at The Big Blue House commentedWhat email module are you using?
@see [#2893655}
Comment #3
geroldk CreditAttribution: geroldk as a volunteer commentedI use Swiftmailer.
However, the message body is not affected by this and the special characters show up fine in the body (i.e. not in HTML code). I am using the latest dev that has the patch from @see #2893655: Swiftmailer stopped working applied.
Note that the HTML encoded special characters also show up under "results -> submissions". I am not sure, but this might be separate to emailing the form, indicating that it is potentially not a Swiftmailer related issue.
Comment #4
jrockowitz CreditAttribution: jrockowitz at The Big Blue House commentedI am able to replicate the issue by entering special characters in the default contact form's subject.
Comment #6
jrockowitz CreditAttribution: jrockowitz at The Big Blue House commentedComment #8
jrockowitz CreditAttribution: jrockowitz at The Big Blue House commentedI committed the patch. Please download the latest release to review.
Comment #9
geroldk CreditAttribution: geroldk as a volunteer commentedThat patch/latest dev fixes it for the "Subject" in the email, but that's not all.
I upload a sequence of screenshots showing the issue as a submission is created, previewed, submitted and viewed. Emails blanked from the images by me, used my own webform not the standard contact form. With reference to the screenshots uploaded:
1 Form filled in
Form filled in, all fields OK
2 Form preview
Form previewed, all fields OK
3 Debug info The debug info shown post submission:
First dot point: Subject not ok, From name not ok
Second dot point: Subject ok, From name not ok
4 Submission info The submission info as viewed in the results tab
From name not ok, To name not ok, Subject not ok
Email received (no screenshot)
Subject ok, From name not ok
Comment #10
jrockowitz CreditAttribution: jrockowitz at The Big Blue House commentedPlease export and upload an example of the broken form.
Comment #11
geroldk CreditAttribution: geroldk as a volunteer commentedUploaded a webform config. Not exactly the one that I used to create the screenshots, but very similar and it exhibits the same behaviour.
If you want to give it a go, then enter To and From email addresses and send/submit.
Comment #14
jrockowitz CreditAttribution: jrockowitz at The Big Blue House commentedThis is getting tricky. The main issue is that most tokens assume the output is HTML which is why the HTML characters are being encoded. An immediate fix is to use [webform_submission:values:subject:raw] in the subject.
Comment #16
jrockowitz CreditAttribution: jrockowitz at The Big Blue House commentedComment #18
jrockowitz CreditAttribution: jrockowitz at The Big Blue House commentedWow Drupal is stripping HTML tags from the subject.
@see http://cgit.drupalcode.org/drupal/tree/core/lib/Drupal/Core/Mail/MailMan...
Comment #20
jrockowitz CreditAttribution: jrockowitz at The Big Blue House commentedComment #21
geroldk CreditAttribution: geroldk as a volunteer commentedInstalled the latest dev (dev-5.x 8f1114e).
Changed all fields to show raw for submissions. Submission display ok.
Applied email_handler_field_s-2895140-13.patch, which didn't work at all. White screen when trying to view the form. Reversed patch.
Applied email_handler_field_s-2895140-19.patch.
Prior to applying patch -19 : Subject ok, From name not ok, To name not ok (see screenshot before #13 and #19)
After applying patch -19 : Subject not ok, From name not ok, To name not ok (see screenshot with #19)
Debug info shows that "&" have changed to "&" for subject which seems to stop this from being sent correctly.
"&" is in both cases displayed (before and after applying the -19 patch) for From name.
Unfortunately one step backwards, as subject was ok and isn't anymore.
Comment #22
jrockowitz CreditAttribution: jrockowitz at The Big Blue House commentedI think the issue is that you did not execute the database update which change the email tokens from [*:value] to [*:raw].
The attached form works as expected.
Comment #23
geroldk CreditAttribution: geroldk as a volunteer commentedThanks for sending through the form to test. It shows the same behaviour as the one that I have.
I have uploaded a screenshot of what it looks like when I receive the submission by email into my inbox. The sender name / reply to name are cut off where the special characters are and only the last portion of regular characters is displayed.
I guess I wasn't clear enough in the first place and got sidetracked by what the debug information is displaying, should have uploaded this screenshot a lot earlier.
Not sure if this is webform related or if this is a general thing that email "sender names" can't contain special chars.
Comment #24
geroldk CreditAttribution: geroldk as a volunteer commentedComment #25
jrockowitz CreditAttribution: jrockowitz at The Big Blue House commentedI think the new issue is related to #2896055: From header containing UTF-8 characters appears scrambled in emails.
The patch fixes a major issue and has test coverage. I am going to commit it and we should start working on #2896055: From header containing UTF-8 characters appears scrambled in emails.
Comment #27
jrockowitz CreditAttribution: jrockowitz at The Big Blue House commented