Custom coding to send email

Created on 16 July 2017, over 7 years ago
Updated 11 May 2023, over 1 year ago

I wrote a few liner scripts to send out an email but kept getting error "message body empty" and "reply-to not set".

Can anyone have a look at the code below and advise?


$mailManager = \Drupal::service('plugin.manager.mail');
$module = 'module';
$key = 'key';
$to = 'email@abc.com;
$langcode = 'en';

$params = array(
  'body' => 'test',
  'subject' => 'Website Information Request',
);
$params['headers']['reply-to'] = $from;


$mailManager->mail($module, $key, $to, $langcode, $params, NULL, true);

πŸ’¬ Support request
Status

Closed: won't fix

Version

1.0

Component

Code

Created by

πŸ‡²πŸ‡ΎMalaysia karv

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.

  • πŸ‡ΊπŸ‡ΈUnited States bwoods

    The reason why it works for @ahmadhalah is because of the values used for "module" and "key." Those reference the test email send through the SMTP configuration. So the errors that the OP is seeing are due to that, and due to the SMTP module not being referenced properly in the mail service.

Production build 0.71.5 2024