Problem with attachment in email


I am trying to send an attachment in email using following code:

//Get a JMail instance
             $mail = &JFactory::getMailer();
             $mail->setSender(array($from, $fromname));
             //Are we sending the email as HTML?
              // Recipient emailId
              // Attachment file
               $mail->addAttachment($_FILES['intro']['tmp_name'], $_FILES['intro']['name'], $encoding, $_FILES['intro']['type']);

It works fine, but the issue is that the file is sent with temp name and no extension whatsover and not with original name and extension, however, if i access the file it opens fine.

What am i doing wrong here, please suggest!


You’ll need to encode the attachment file type.

That should then work fine.

I’ve already used encoding as:

$encoding =‘base64’;

and used it here:

$mail->addAttachment($_FILES[‘intro’][‘tmp_name’], $_FILES[‘intro’][‘name’], $encoding, $_FILES[‘intro’][‘type’]);

It’s the file type encoding that you need to set up.

Try searching for Content-Type:

For example for PDF’s I use:

$fileatt_type = "application/octet-stream";

You’ll then need to pass that in the headers of the email.

I tried this one as well:

$mail->addAttachment($_FILES[‘resume’][‘tmp_name’], $_FILES[‘resume’][‘name’], $encoding, $type = “application/octet-stream”);