Problem with attachment in email

Hi,

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


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

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!

Thanks,
Kul.

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”);