Normally we send files as attachments in the email if they are stored in the file system.
$file->uri = 'sites/default/files/file_name.pdf'; // File path $file->filename = 'file_name.pdf'; //File name $file->filemime = 'application/pdf'; //File mime type $params['attachments'] = $file; $mailManager->mail($module, $key, $to, $langcode, $params, NULL, $send);
But I have dynamically generated content.
$content = <?xml version="1.0"?> <root><element>element value</element></root>
I want to send it as an XML file attachment in the email. How can I do this?