Problem/Motivation
When a comment reply is posted and one of the thread's "Replies to my comment" subscribers (COMMENT_NOTIFY_COMMENT) is a registered user whose account has no email address, _comment_notify_mailalert() passes a NULL recipient to the mail manager. On Drupal 11, Drupal\Core\Mail\Plugin\Mail\PhpMail::doMail() type-hints $to as string, so this throws and aborts the whole comment save — the commenter gets a 500 and their comment is lost:
TypeError: Drupal\Core\Mail\Plugin\Mail\PhpMail::doMail(): Argument #1 ($to) must be of type string, null given, called in core/lib/Drupal/Core/Mail/Plugin/Mail/PhpMail.php on line 123 (line 168 of core/lib/Drupal/Core/Mail/Plugin/Mail/PhpMail.php).
Anonymous subscribers are already forced to supply an email by comment_notify_comment_validate(), so the gap is specifically registered accounts with an empty mail (common on sites migrated from older Drupal, or programmatically-created users).
In _comment_notify_mailalert() the watcher loop resolves the recipient as:
$mail = !empty($recipient_user->getEmail()) ? $recipient_user->getEmail() : $alert->getAuthorEmail();For a registered subscriber with no account email (and no stored anonymous author email) $mail is NULL, and there is no guard before \Drupal::service('plugin.manager.mail')->mail('comment_notify', 'comment_notify_mail', $mail, ...), so NULL reaches PhpMail::doMail(). The pre-D11 mail system tolerated a NULL $to; D11's stricter type hint does not. (strtolower($mail) a few lines up also emits a PHP 8.1+ deprecation on NULL.) The entity-author branch is already guarded by !empty($author_email); only the watcher branch is affected.
Steps to reproduce
- Enable Comment Notify; enable it for a content type; include "Replies to my comment" in Available alerts.
- As user A — a registered user whose account email is empty — post a comment on a node and choose "Replies to my comment".
- As user B, post a reply in that thread.
- On save →
TypeError, comment is not saved.
Proposed resolution
Skip subscribers whose resolved email is empty, before attempting to send:
$mail = !empty($recipient_user->getEmail()) ? $recipient_user->getEmail() : $alert->getAuthorEmail(); // A registered subscriber may have no email address on their account, and the // mail manager requires a string recipient (D11 PhpMail::doMail() type-hints // $to as string). Skip such subscribers instead of passing NULL. if (empty($mail)) { continue; }
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | 3607949-2-comment_notify-skip-empty-recipient.patch | 773 bytes | jhan1112 |
Issue fork comment_notify-3607949
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
jhan1112 commentedA simple patch...
Comment #3
gnugetComment #6
gnuget