Do you only want to send the file as an attachment or do you want to upload and store it in the page content directory as well?
Currently your upload
action moves the uploaded file to the content directory but there is no configuration of the email
action to send this file as an attachment, too. To send the file as an attachment, change the $email->attachment != null
part of the phpmailer
service to something like this:
if (!isset($_FILES['file']) || $_FILES['file']['error'] !== UPLOAD_ERR_OK) {
throw new Error('The file was not uploaded correctly!');
}
$mail->addAttachment($_FILES['file']['tmp_name'], $_FILES['file']['name']);
Note that this is a rather fragile approach since the file
field name is hard coded in the email service. It also assumes that the email
action is performed before the upload
action, otherwise the file would no longer be fund because it was already moved to the page content directory.
If you only want to send the file as an attachment and not store it in the page content directory as well, simply remove the upload
action.