I am able to attach a file using SwiftMailer with its name hardcoded. But what if the file is uploaded by a user from an HTML form's 'file' input type control and has to be sent with an email by a PHP script? How do I specify the file name in SwiftMailer?
Here is my code, the file upload portion:
//File upload
// Where the file is going to be placed
$target_path = "uploads/";
// Add the original filename to our target path.
//Result is "uploads/filename.extension"
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
echo "The file ". basename( $_FILES['uploadedfile']['name']).
" has been uploaded";
} else{
echo "There was an error uploading the file, please try again!";
}
//End of file upload
This is the file attaching portion:
//Create the attachment
$attachment = Swift_Attachment::fromPath('Plan.doc', $target_path);
Thank you!