It seems Swift Mailer has stopped working with Webform after "Allow email handler theme to be customized" was added.

With the following config set, emails that are sent from Webform always are blank when viewing the email:

Default Mail System: Formatter and Sender both set to "Swift Mailer".
Webform -> Edit Email notification handler: "Send email as HTML" is checked. "Theme to render this email" can be set to "Default" or the actual active theme name, both result in a blank email.

When the email is sent out, this appears in the error log: "Theme hook not found."

If I change the following config, the emails are no longer blank, but obviously are not using Swift Mailer:

Default Mail System: Formatter and Sender both set to "Default PHP mailer".

Webform + Swift Mailer was properly working with Webform dev-5.x 22b30e1. Not sure if this specific added feature broke support or something else in the latest updates.

Comments

cbildstein created an issue. See original summary.

jrockowitz’s picture

Status: Active » Needs review
StatusFileSize
new2.09 KB

The attached patch includes comments that describe the two issues/changes which caused unexpected regressions.

jrockowitz’s picture

#2998248: Create dedicate HTML template for HTML email addresses webform HTML emails being wrapped twice in an HTML template

cbildstein’s picture

Awesome, thanks for the quick turn around.

Confirmed patch now has Webform emails displaying correctly with Swift Mailer.

  • jrockowitz committed 335f513 on 8.x-5.x
    Issue #2998239 by jrockowitz: Swift Mailer no longer working after...
jrockowitz’s picture

Status: Needs review » Fixed
jrockowitz’s picture

Since this regression results in data loss, I tagged a new release.

weseze’s picture

Status: Fixed » Needs work

This is still an issue for any mailhandler that extends on swiftmailer...

I have a custom mailhandler built on top of swiftmailer and it still breaks.

jrockowitz’s picture

Status: Needs work » Needs review
StatusFileSize
new19.22 KB

To prevent the conflicts with Swift Mailer, I think we should change the 'theme' setting to be called 'theme_name'.

Status: Needs review » Needs work

The last submitted patch, 9: 2998239-9.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

jrockowitz’s picture

Status: Needs work » Needs review
StatusFileSize
new20.33 KB

Status: Needs review » Needs work

The last submitted patch, 11: 2998239-11.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

jrockowitz’s picture

Status: Needs work » Needs review
StatusFileSize
new24.37 KB

Status: Needs review » Needs work

The last submitted patch, 13: 2998239-13.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

jrockowitz’s picture

Status: Needs work » Needs review
StatusFileSize
new3.07 KB
new27.67 KB

Something is off with my patch's exported webform config. I am hoping this one is better.

weseze’s picture

Status: Needs review » Reviewed & tested by the community

The patch works. Setting to RTBC.

But I am still wondering why we need special processing for Swiftmailer?

          $dom = new \DOMDocument();
          @$dom->loadHTML($message['body']);
          $message['body'] = Html::serialize($dom);

          // SwiftMailer requires that the body be valid Markup.
          $message['body'] = Markup::create($message['body']);
          break;

Should webform really be interfering with the things Swiftmailer (or any mail handler for that matter) does?
Or is it actually Swiftmailer that is not handling its $message['body'] properly?

jrockowitz’s picture

I noticed that Swift Mailer wraps the email message in <html> and <body> tags. My code prevents messages from being wrapped twice. It is probably unneeded.

I took the approach that site builders could define <html> and <body> tags in the email message template which would be respected by the Webform's Mail sender

bygeoffthompson’s picture

jrockowitz, weseze, and cbildstein,

Thanks for the work here. This (#15) has resolved my issue with empty email body text on my Drupal site (8.6.1) with Webform (rc21) that uses Swift Mailer (via SMTP). My email_handler's default message text now includes the submission values as expected.

Cheers

jrockowitz’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new27.87 KB

Attached patch removes the code mentioned in #16.

weseze’s picture

Patch #19 works perfect!

The last remaining piece is still needed:

    if ($this->configuration['html']) {
      switch ($this->getMailSystemSender()) {
        case 'swiftmailer':
          // SwiftMailer requires that the body be valid Markup.
          $message['body'] = Markup::create($message['body']);
          break;
      }
    }

It's a shame we can't do without, but I think that would be a Swiftmailer issue, nothing webform can do about that... (also the reason why I work with an extended class that detects HTML markup and does this "Markup-switch-trick")

weseze’s picture

Status: Needs review » Reviewed & tested by the community
berdir’s picture

That Swiftmailer requires a Markup object is a (security) feature, not a bug. And it shouldn't hurt to always do that *if* you think that the input is safe.

Wondering a bit about this feature in general. Seems a bit overkill to be able to configure that separately for each webform and it overlaps with the setting of the mailsystem module. I'd be happy to help push that setting into core.

PS: Changes like this tend to be painful for distributions and modules that provide webform default configuration, because renaming/changing keys breaks them, the update function only helps with existing sites. So we (distribution maintainers) appreciate if you only those kind of configuration changes when really necessary :)

jrockowitz’s picture

@Berdir It is rare I have to change a property name but it felt like the 'theme' property which becomes a mail param was going to conflict with more than just Swift Mailer.

I agree that it…

Seems a bit overkill to be able to configure that separately for each webform and it overlaps with the setting of the mailsystem module.

The catch22 here is people may need to control how the webform's email message is themed and it is rendered with the EmailWebformHandler.

We could define a global default webform email theme name settings. I am not sure how many people are going to be using this feature.

jrockowitz’s picture

@Berdir For exported config (in distributions), I am really hoped that I could find a hook or event that could be used to update webform related config as it is being imported, sync'd, updated, etc...

@see #2996455: Make sure imported webform config is up-to-date

  • jrockowitz committed 8167307 on 8.x-5.x
    Issue #2998239 by jrockowitz, cbildstein: Swift Mailer no longer working...
jrockowitz’s picture

Status: Reviewed & tested by the community » Fixed

Everyone, thank you for your patience and feedback. I committed the latest patch.

Setting up a global default webform email theme name setting should be handled in a new ticket.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

guardian87’s picture

Could you provide some additional information about this one?

Has the problem been resolved now or not?
I am using the latest (5.2) version of webform, and from what I can see that patch #19 is included there.

However, in combination with Swiftmailer, HTML emails from webform is still broken and gives me a "theme hook not found" in the logs.

Am I missing something?

For now I am sending the webform submissions as plain text, which is a shame.

Many thanks.

jrockowitz’s picture

@guardian87 You probably need to create a new issue.

You might also want to post a general question about Webform and SwiftMailer support to https://drupal.stackexchange.com/questions/tagged/webforms

guardian87’s picture

huh?

Now why would I want to do that?
The issue that I am seeing is literally what is described in this issue.

There is a patch that claims to have fixed it, yet I am using the latest version of the webform module.

So this issue is the perfect place to report this imho.

Also there is this in #26

Setting up a global default webform email theme name setting should be handled in a new ticket.

Is this being addressed currently, as I don't see an issue in the queue for this? (or did I overlook?)

I am merely asking for clarification as I am still seeing this exact issue.

Many thanks again.

rang501’s picture

There is a bug somewhere because I'm seeing a similar issue - Swiftmailer theme hook is missing and HTML emails have a blank body. If I clear the cache, it works for some time.
This isn't probably Webform issue, probably Swiftmailer or Drupal core itself.

cola’s picture

@guardian87 any progress with your issue? we have the same, html is empty if you send it over swiftmailer.