I have a site with a webform, which when submitted sends an email. The form has a file upload which should then attach the file as an attachment to the email. I'm not getting any attachment.
I've created a hook for hook_mail_alter
and tried hardcoding any attachment to be sent but every email i get has no attachment.
function my_module_mail_alter(&$message) {
$file_content = file_get_contents('sites/default/files/tmp/test.pdf');
$message["params"]["attachments"] = array(
'filecontent' => $file_content,
'filename' => 'test.pdf',
'filemime' => 'application/pdf'
);
}
I've debugged the MailManager.php
just before the email is sent and the $message
variables param['attachement']
has the valid contents from the code above.
I've instaled modules: SMTP (so i can send emails from my local), MimeMail and enabled MailSystem The emails are being sent without any issue, but again never with an attachement.
I don't know what i'm doing wrong, any ideas?
Core: 8.6
$file_content
has the content,'sites/default/files/tmp/test.pdf'
it may not the correct location ?$file = file_load($fid); $message["params"]["attachments"][] =[ 'filepath' => $file->uri, ];