Pulled from this answer https://stackoverflow.com/a/23849972/ (and having spent some time to find them a solution).
Sidenote: I upvoted the answer it was pulled from, just so you know.
"I assigned $_FILES['attachment']['tmp_name']
to a temporary variable and it worked!
Dont know why but that solved it for me.
Here's my code"
// Swiftmail commands ====================================
require_once('./swiftmailer/lib/swift_required.php');
$transport = Swift_SmtpTransport::newInstance('smtp.host.com', 587)
->setUsername('email@host.com')
->setPassword('pass');
$mailer = Swift_Mailer::newInstance($transport);
$message = Swift_Message::newInstance()
->setSubject($subject_temp)
->setFrom(array($from_email => $full_name))
->setTo(array('email@host.com' => 'Jack'))
->setBody($message_temp)
->attach(Swift_Attachment::fromPath($file_temp_name)
->setFilename($name_of_file));
$result = $mailer->send($message);
// Swiftmail commands ====================================
Where $file_temp_name = $_FILES['attachment']['tmp_name'];
and $name_of_file = basename($_FILES['attachment']['name']);
- So in turn (and was something I knew could be done), you would be using the temporarily stored file on the server and attaching it to the mail, which automatically gets deleted once it has been successfully served/processed.