I'm trying to do this, but the attachment is not sent, just the email.
$fileName = 'Arquivo'.date('d-m-Y H-i').'.xlsx';
$directory = $_SERVER['DOCUMENT_ROOT'].'/local/plugin/exports/'.$fileName;
# Envia e-mail para o supervisor
$userMail = $DB->get_record('user', ['id' => 2]);
email_to_user(
$userMail,
$userMail,
'Assunto',
'Mensagem',
'Mensagem',
$directory,
$fileName
);
Using email_to_user
is it possible?