Q:

Sending attachments with PHPmailer - returns .dat file

Hopefully someone out there can point out what I've missed!
I have a script which I took from PHPMailer's Github example here which I placed in my page, and updated the HTML.
Although the image uploads fine and the email comes through, the file attachment is a .dat file instead of the correct extension.
Here's my PHP in case something I've changed isn't as it should be:
if (array_key_exists('userfile', $_FILES)) {

$uploadfile = tempnam(sys_get_temp_dir(), sha1($_FILES['userfile']['name']));
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {

    require 'PHPMailerAutoload.php';
    $mail = new PHPMailer;
    $mail->setFrom('my@email.com', 'Competitions');
    $mail->addAddress('jg@email.com', 'JG');
    $mail->Subject = 'Competition Entry';
    $mail->msgHTML("My message body");

    $mail->addAttachment($uploadfile, 'Competiton Entry Attachment');
    if (!$mail->send()) {
        $err[] = "Mailer Error - didn't send email" . $mail->ErrorInfo;
    } else {
        $done[] = "Message sent!";
    }

} else {
    $err[] = 'Failed to move file to ' . $uploadfile;
}

}

Many thanks in advance

A:

Change
$mail->addAttachment($uploadfile, 'Competiton Entry Attachment');

To
$name = $_FILES['userfile']['name'];

$ext = end((explode(".", $name)));

$mail->addAttachment($uploadfile, 'Competiton Entry Attachment.'.$ext);

