- Issue created by @coretex
- ๐ช๐ธSpain juandels3 Seville
The same error happened to me. When downgrading to version 2.0.1 the error is not reproduced.
- ๐ฉ๐ชGermany dercheffe Sersheim, Germany
Same Issue here. IMO this is a major or even critical bug because it breaks user experience massively
- ๐บ๐ธUnited States MegaKeegMan
Glad to find this issue, as I was also about to report it. It doesn't look like there is any reason this function needs to return an array, since the results are not actually used for anything besides to check if the array returned is empty. Additionally, I can see where some of the confusion is coming from. The mail function, run on line 622 of the .module, is documented to return a bool. However, the implementation that I am seeing from my current sites mailer is called in the MailManagerReplacement class of the symfony_mailer contrib module. So there seems to be a lot of confusion even deeper around whether or not we should be dealing with an array or a bool. I am not sure yet where exactly this confusion stems from, whether this a core change that contrib modules haven't caught up with or whether there are just a few implementations doing it wrong. My best guess so far is that everything should be moving in the direction of the mail function returning a bool, and then any of the code that does anything with the result of the mail function should be updated accordingly. Of course ensuring that our mailers are implementing the mail function correctly. There is also the possibility that the mail function is just documented incorrectly. If anyone has any background knowledge on this, that would be great.
- ๐บ๐ธUnited States MegaKeegMan
For what it's worth, the MailInterface class in Drupal core hasn't been touched for 3 years, and indicates that the mail function should return a bool, see https://git.drupalcode.org/project/drupal/-/blob/11.x/core/lib/Drupal/Co...
I have a quick because I don't enaough time to thing it through :
$mail = \Drupal::service('plugin.manager.mail')->mail('user_registrationpassword', $op, $account->getEmail(), $langcode, $params, $site_mail);
//$output = $mail['result'] ?? [];
$output = $mail['result'] ? $mail : [];- ๐บ๐ธUnited States MegaKeegMan
Unfortunately, that won't work in the cases where a $mail contains a boolean, which I think it should. But I'd really like to hear a maintainers thoughts on how they want to handle this, and if there is any history behind this.
- ๐บ๐ธUnited States MegaKeegMan
I created a simple patch, which should work for anyone using a mailer that incorrectly implements the mail function, like the symfony_mailer contrib module. If Your are using another mailer that correctly implements the mail function, and the mail function returns a boolean as per the Drupal core mail interface, then this patch is not for you.
With that being said, it should be pretty easy to re-patch for that, and I think that patch should also exist.
Unfortunately I don't have a list of which mailer modules do what.
- ๐ฌ๐งUnited Kingdom JeremySkinner
We've also run into this issue, which is causing our CI to fail. We've rolled back to 2.0.1 for now. Any chance of getting a new release with a fix for this as it breaks on all versions of Drupal 10.
- First commit to issue fork.
- Assigned to Grimreaper
- Issue was unassigned.
- Status changed to Needs review
4 months ago 9:21pm 22 August 2024 - ๐ซ๐ทFrance Grimreaper France ๐ซ๐ท
Here is the patch from MR for Composer usage.
I got to the same conclusions of @megakeegman.
MR is a slightly more advanced to handle cases.
Thanks for the review.
- ๐จ๐ฆCanada noah
We're using Mailgun to send email, and we're seeing the problem both with and without the patch because the Mailgun module returns
Mailgun\Model\Message\SendResponse
rather than an array or a boolean. I looked for documentation to see if there's a โrightโ type for$return['result']
, but couldn't find anything. I did find that the email_contact module dealt with the same issue just by checking if$return['result']
is empty rather than expecting a specific type:https://www.drupal.org/project/email_contact/issues/3468210 ๐ Form displays sending error when using Mailgun module even though it sends correctly. Fixed
Would that be a reasonable option here?
- ๐จ๐ฆCanada noah
I've updated the MR to check if
$mail['return']
is empty, rather than expecting a specific type, which should make it more flexible and compatible with, e.g. the Mailgun module. Updated patch attached. - ๐ง๐ชBelgium gorkagr
Same error making the site a bit unusable for us (at least is local and we did not deploy it yet).
MR works fine.
Best - Status changed to Needs work
about 1 month ago 6:18am 11 November 2024 - First commit to issue fork.
- ๐ฆ๐บAustralia VladimirAus Brisbane, Australia
Based on mail() function documentation, it only can return an array.
Please review. - ๐บ๐ธUnited States MegaKeegMan
I did not recognize that there was a difference between MailManagerInterface and MailInterface: https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Mail%21Ma...
- ๐ณ๐ฑNetherlands coretex Deurne
The issue is fixed with the last MR changes from VladimirAus.
- ๐ท๐บRussia Andrew Answer Novosibirsk
Hi,
I debugged the problem and find out that Drupal return 1 (just 1) from mail() function, so I replace null coalescing operator with its equivalent isset() according to PHP documentation, and add array [] to the first option (see patch).
The bug is gone. D10.3.10, user_registrationpassword 2.0.2.
- ๐บ๐ธUnited States ElusiveMind Nashville, TN
I think this will work. But since the calling function on 339 doesn't care about a return value and 554 is just looking for a value, should the return of the function be a bool and the returns refactored accordingly? Happy to do it, but thought it may be a better way to go.
- ๐บ๐ธUnited States ElusiveMind Nashville, TN
Patch #17 worked for me on v2.0.2 and drupal 11.0.9
It is also, in my opinion, the correct way to fix this. Verified working.