PhpMailer, sent attachment as other name

Oto Shavadze picture Oto Shavadze · May 27, 2013 · Viewed 7.2k times · Source

I use phpmailer for sending email with attachment

    file = "/path/bla.csv";


    require 'class.phpmailer.php';
    $mail = new PHPMailer();
    // some oprtions here

    $mail->AddAttachment($file);

    $mail->Send();

So, if use this code, email is sended with attach file, and file name is: bla.csv

There is possible to change attach file name without renaming real file? that is, I need sent bla.csv file, but sent is as name some_other_name.csv

How to make this?

Answer

fab picture fab · May 27, 2013

Pass the desired name as second parameter

$mail->AddAttachment($file, "newName.csv");