Fatal error with email notification if user has no email address

Created on 31 October 2024, 21 days ago

Problem/Motivation

Attempting to send a message to a user who doesn't have an email results in:

TypeError: Drupal\Core\Mail\Plugin\Mail\PhpMail::doMail(): Argument #1 ($to) must be of type string, null given, called in /var/www/html/web/core/lib/Drupal/Core/Mail/Plugin/Mail/PhpMail.php on line 124 in Drupal\Core\Mail\Plugin\Mail\PhpMail->doMail() (line 168 of core/lib/Drupal/Core/Mail/Plugin/Mail/PhpMail.php).

Drupal\Core\Mail\Plugin\Mail\PhpMail->mail(Array) (Line: 308)
Drupal\Core\Mail\MailManager->doMail('message_notify', 'private_message_notification', NULL, 'en', Array, NULL, 1) (Line: 181)
Drupal\Core\Mail\MailManager->Drupal\Core\Mail\{closure}() (Line: 638)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 182)
Drupal\Core\Mail\MailManager->mail('message_notify', 'private_message_notification', NULL, 'en', Array, NULL) (Line: 116)
Drupal\message_notify\Plugin\Notifier\Email->deliver(Array) (Line: 110)
Drupal\message_notify\Plugin\Notifier\MessageNotifierBase->send() (Line: 46)
Drupal\message_notify\MessageNotifier->send(Object) (Line: 132)
Drupal\private_message_notify\Service\PrivateMessageNotifier->notify(Object, Object) (Line: 21)
private_message_notify_private_message_new_message(Object, Object)
call_user_func_array(Object, Array) (Line: 416)
Drupal\Core\Extension\ModuleHandler->Drupal\Core\Extension\{closure}(Object, 'private_message_notify') (Line: 395)
Drupal\Core\Extension\ModuleHandler->invokeAllWith('private_message_new_message', Object) (Line: 423)
Drupal\Core\Extension\ModuleHandler->invokeAll('private_message_new_message', Array) (Line: 100)
Drupal\private_message\Entity\PrivateMessageThread->addMessage(Object) (Line: 86)
Drupal\private_message\Service\PrivateMessageThreadManager->addMessage() (Line: 63)
Drupal\private_message\Service\PrivateMessageThreadManager->saveThread(Object, Array, Object) (Line: 504)
Drupal\private_message\Form\PrivateMessageForm->save(Array, Object)
call_user_func_array(Array, Array) (Line: 129)
Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object) (Line: 67)
Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object) (Line: 597)
Drupal\Core\Form\FormBuilder->processForm('private_message_add_form', Array, Object) (Line: 326)
Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 73)
Drupal\Core\Controller\FormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 638)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 181)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 76)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 53)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 28)
Drupal\Core\StackMiddleware\ContentLength->handle(Object, 1, 1) (Line: 32)
Drupal\big_pipe\StackMiddleware\ContentLength->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 36)
Drupal\Core\StackMiddleware\AjaxPageState->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object, 1, 1) (Line: 741)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

Steps to reproduce

- Create a user with no email address
- Try to send a message to that user with uid 1 (for example) from /private-message/create
- Fatal error

Proposed resolution

TODO (probably add a check to ensure that the user has an email address, before sending the notification?).

Remaining tasks

TODO

User interface changes

TODO

API changes

TODO

Data model changes

TODO

🐛 Bug report
Status

Active

Version

3.0

Component

Code

Created by

🇧🇪Belgium herved

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024