Search code examples
phpwordpressemailattachmentnames

Change names of attachments : wp_mail PHP


I'm using wp_mail to send mails with a form which is on my website. But when i attach some files, names are like "phpr0vAqT" or "phpFO0ZoT".

$files = array(); //Array pour les fichiers
$count = count(array_filter($_FILES['fichier']['name'])); //Compte le nombre de fichiers

        for($i=0;$i<$count;$i++){ //boucle sur chaque fichier

            array_push($files, $_FILES['fichier']['tmp_name'][$i]); //insere le fichier dans l'array $files

         }

I think the issue is coming from the : ['tmp_name'] , but i don't know what can i change because wp_mail need a path.

Then, i'm doing this :

wp_mail($to, $subject, $message, $headers, $files);

to send the mail.

Thanks.


Solution

  • You cannot change attachment names with wp_mail.

    A possible solution is:

    1. save the files with the correct name.
    2. send the new files with wp_mail.
    3. remove the files.