I've got a pretty simple website form that can take attachments. It sends to a gmail address using gmail's smtp. Everything is working great except that the file arrives as "noname" - no filename or extension. If you download the attachment and rename it with the correct filename, the file opens just fine.
I've tried adding more arguments to addAttachment() such as the filetype and the filename, but they don't show up in the email. When I click on "Show Original" in gmail, this is all I see in the attachment section (they don't change at all, no matter what arguments I use):
Content-Transfer-Encoding: base64
Content-Type: application/octet-stream
Content-Disposition: attachment
Here is the relevant part of my code:
require_once 'Mail.php';
require_once 'mime.php';
$ToEmail = '***@***.com';
$EmailSubject = '*** contact form';
$Filename = basename($_FILES['uploaded_file']['name']);
$host = "ssl://smtp.gmail.com";
$port = "465";
$username = "***@***.com";
$password = "***";
$MESSAGE_BODY = "Blah blah blah";
$Uploads_folder = "../uploads/";
$Filepath = $Uploads_folder.$Filename;
$tmp_path = $_FILES["uploaded_file"]["tmp_name"];
if(is_uploaded_file($tmp_path)) {
if(!copy($tmp_path, $Filepath)) {
echo 'Sorry, there was an error in uploading the file. Please go back and try again.';
exit();
}
}
$headers = array ('From' => $username,
'To' => $ToEmail,
'Subject' => $EmailSubject);
$mime = new Mail_mime();
$mime->setHTMLBody($MESSAGE_BODY);
$mime->addAttachment($Filepath);
$body = $mime->get();
$headers = $mime->headers($headers);
$smtp = Mail::factory('smtp',
array ('host' => $host,
'port' => $port,
'auth' => true,
'username' => $username,
'password' => $password));
$mail = $smtp->send($ToEmail, $headers, $body);
Any help is greatly appreciated!