How to send php mail attachment with original filename

Viewed 88

I send email with attachment, everything is working, but I get email with attachment temporary name. What is wrong with this code ?

foreach ($_FILES["file"]["name"] as $k => $v) {
        $tmp_name = $_FILES["file"]["tmp_name"][$k];
        $name = basename($_FILES["file"]["name"][$k]);
        $mail->AddAttachment($tmp_name,$name);
}

enter image description here

1 Answers

try doing this works for me

if (array_key_exists('filename', $_FILES))
            {
                 foreach ($_FILES["filename"]["name"] as $k => $v) 
                 {
                    $mail->addAttachment( $_FILES["filename"]["tmp_name"][$k], 
                    $_FILES["filename"]["name"][$k] );
                 }                
            }
Related