Email attachment helper
Categories
Component ID
2871918
Component name
Email attachment helper
Component type
module
Maintenance status
Development status
Component security advisory coverage
not-covered
Downloads
230
Component created
Component changed
Component body
This is a module for developers who want to attach files programmatically to emails send from Drupal 8. This module doesn't send emails but rather intercepts emails from other emails. If an 'attachment' key is present in the $params array, it will be converted into an actual MIME attachment.
This module has no configuration options.
Example code to put into your module:
$params = [
'attachment' => [
'filecontent' =>
'Your attachment contents. ' .
'You could use file_get_contents() instead of this string.',
'filename' => 'attached_filename_how_recipients_see_it.txt',
'filemime' => 'text/plain',
],
// further params as needed by your hook_mail
];
$mail_manager = Drupal::service('plugin.manager.mail');
$result = $mail_manager->mail($your_module, $your_key, $to, $lang, $params);
