Original report
I am using swiftmailer for the theme and mailjet for the transport.
all my other account emails are being sent but this one is not.
Summary
Module was tested with Swift Mailer and Symfony Mailer. A coding error was found: A non-existent attribute caused NULL to be passed as the language to the Mail API. This didn't cause an error with the Drupal or Swift Mailer, but did with the Symfony Mailer.
It was also found that hook_mail() is not implemented. A patch was submitted in issue #3275572: Implement hook_mail() and hook_mail is now implemented.
It's not clear if this is the cause of the original reported error but it's a good candidate. If it doesn't solve the problem, it has certainly changed the conditions that are causing it.
The issue submitter is asked to try the dev version and report the current problem status.
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | incorrect_body_format-2975515-2.patch | 716 bytes | kalpaitch |
Comments
Comment #2
kalpaitch commentedI'm having a similar issue with a mail handler I'm using which is reporting that the body is not in the correct format. And it does appear to be correct about that. For some reason the message body is formatted as a string.
Comment #3
dale42I applied the patch from comment #2 and got the error:
Looking at the
InviteByEmail->send()method:\Drupal::service('plugin.manager.mail')->mail(...)is used to create a $message array\Drupal::service('plugin.manager.mail')->getInstance(...)->mail(...)is used to send itThe message array format is different between the two. The mail backend call
\Drupal::service('plugin.manager.mail')->getInstance(...)->mail(...)expects the $message['body'] to be a string, not an array. The code inInviteByEmail->send()is using the correct format.The error reported in comment #2 must be coming from a different piece of code.
Comment #4
dale42To try reproducing the problem I installed the Symfony Mailer module. I got the following error:
InviteByEmail.php has the statement:
The Invite attribute
$invite->activeLangcodedoes not exist. This is why null is passed, producting the error.I did not get an error with the Swift Mailer module.
A working solution could be created by using the system language code.
However, there are other considerations.
The Mail API is used without a
hook_mail()implementation. The Mail API useshook_mail()to populate the subject and body of the message. The current code works around not havinghook_mail()by populating the subject and body after calling\Drupal::service('plugin.manager.mail')->mail(...)with the no-send option. After adding the subject and body the message is then sent by directly calling the mail backend with\Drupal::service('plugin.manager.mail')->getInstance(...)->mail(...).There's a problem with this implementation:
hook_mail_alter()is run when the $message array isn't fully populated.hook_mail_alter()is run in\Drupal::service('plugin.manager.mail')->mail(...). The current code populates the subject and body after calling\Drupal::service('plugin.manager.mail')->mail(...). There is no way for other modules to view or alter all of the message values.Regardless of the original problem, I think the current implementation needs changing in one of two ways:
hook_mail()is not requiredhook_mail()For me, option 2 is the preferable solution.
Regarding the original problems reported, more information is needed.
Comment #5
dale42Created a new issue for the hook_mail() discussion at #3275572: Implement hook_mail()
Comment #6
dale42Comment #7
dale42Comment #8
dale42The hook_mail code has been commited to the 8.x-1.x-dev branch. If this doesn't solve the mail issue, it certainly changes the conditions that would cause it.
Please try out the 8.x-1.x-dev version and let us know if the error is still occurring.
If the error is still happening, please check the Drupal error log at Administration > Reports > Recent log messages for an error message and send us a copy if you find one, along with any other information you think might be useful.
Comment #9
dale42