PhpMailer,发送附件作为其他名称

OTA*_*TAR 8 php email phpmailer

我使用phpmailer发送带附件的电子邮件

    file = "/path/bla.csv";


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

    $mail->AddAttachment($file);

    $mail->Send();
Run Code Online (Sandbox Code Playgroud)

因此,如果使用此代码,则使用附件文件发送电子邮件,文件名为: bla.csv

有没有重命名真实文件可以更改附件文件名?也就是说,我需要发送bla.csv文件,但发送的是名称some_other_name.csv

怎么做到这个?

fab*_*fab 17

将所需名称作为第二个参数传递

$mail->AddAttachment($file, "newName.csv");
Run Code Online (Sandbox Code Playgroud)