Pass email address in options

Created on 3 August 2020, almost 4 years ago
Updated 17 January 2024, 5 months ago

Problem/Motivation

I would like to send emails, using message template, to our Simplenews newsletter subscribers. Some may or may not have accounts. I only have their email addresses. So, I wish to pass the email address to the message create command.

Steps to reproduce

Currently to send notification of new node posted to account members, I use this:

$message = Message::create([
'template' => $message_template,
'uid' => $uid,
]);

if ($message->hasField('field_node_reference')) {
$message->set('field_node_reference', $node);
}

$message->save();
$notifier = \Drupal::service('message_notify.sender');
$notifier->send($message);

Proposed resolution

I am wondering if I can add something like the following in order to send so a specific email address:

$message = Message::create([
'template' => $message_template,
'uid' => $uid,
'mail' => 'sendto@email.com',
]);

or

$message->set('mail', 'sendto@email.com';

Is there a way to do this, and if so, how?

πŸ’¬ Support request
Status

Closed: works as designed

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States SomebodySysop

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.69.0 2024