更改附件名称:wp_mail PHP

时间:2018-06-05 13:39:06

标签: php wordpress email attachment names

我正在使用wp_mail发送带有我网站上的表单的邮件。但是当我附加一些文件时,名称就像“phpr0vAqT”或“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

         }

我认为问题来自:['tmp_name'],但我不知道我能改变什么,因为wp_mail需要一个路径。

然后,我这样做:

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

发送邮件。

感谢。

3 个答案:

答案 0 :(得分:2)

您无法使用wp_mail更改附件名称。

可能的解决方案是:

  1. 使用正确的名称保存文件。
  2. 使用wp_mail发送新文件。
  3. 删除文件。

答案 1 :(得分:2)

以上方法是正确的,这是一个如何在php / wp中执行此操作的示例。希望这会有所帮助!

boolean

在完成附件后,您应该清理

if(!empty($_FILES['upload-attachment']['tmp_name'])){
            //rename the uploaded file
            $file_path = dirname($_FILES['upload-attachment']['tmp_name']);
            $new_file_uri = $file_path.'/'.$_FILES['upload-attachment']['name'];
            $moved = move_uploaded_file($_FILES['upload-attachment']['tmp_name'], $new_file_uri);
            $attachment_file = $moved ? $new_file_uri : $_FILES['upload-attachment']['tmp_name'];
            $attachments[] = $attachment_file;
 }

答案 2 :(得分:0)

要更改附件名称,您应该使用pipeline { agent { node { label 'jenkins_managed_windows' } } stages { stage('SonarQube Analysis') { steps { powershell "dotnet sonarscanner begin /k:project-key /d:sonar.branch.name=$env:BRANCH_NAME" } } stage('Build') { steps { powershell 'dotnet build' } } stage('SonarQube End') { steps { powershell 'dotnet sonarscanner end' } } } } 操作直接访问dotnet sonarscanner begin /k:project-key /d:sonar.branch.name=org.jenkinsci.plugins.workflow.cps.EnvActionImpl@54ee3a8:BRANCH_NAME 中使用的powershell 'dotnet sonarscanner begin /k:project-key /d:sonar.branch.name=$env:BRANCH_NAME' 实例,而不是将dotnet sonarscanner begin /k:project-key /d:sonar.branch.name=$env:BRANCH_NAME 作为函数参数传递:

phpmailer_init
相关问题