更改附件名称:wp_mail PHP
我正在使用wp_邮件发送邮件,邮件的格式在我的网站上。但当我附加一些文件时,名称类似于“phpr0vAqT”或“phpFO0ZoT” 发送邮件更改附件名称:wp_mail PHP,php,wordpress,email,attachment,names,Php,Wordpress,Email,Attachment,Names,我正在使用wp_邮件发送邮件,邮件的格式在我的网站上。但当我附加一些文件时,名称类似于“phpr0vAqT”或“phpFO0ZoT” 发送邮件 谢谢。您不能使用wp\U邮件更改附件名称 一种可能的解决办法是: 用正确的名称保存文件 用wp_邮件发送新文件 删除这些文件 您不能使用wp_mail更改附件名称 一种可能的解决办法是: 用正确的名称保存文件 用wp_邮件发送新文件 删除这些文件 上述方法是正确的,下面是一个如何在php/wp中实现这一点的示例。希望这有帮助 if(!empty($_FI
谢谢。您不能使用wp\U邮件更改附件名称 一种可能的解决办法是:
您不能使用wp_mail更改附件名称 一种可能的解决办法是:
上述方法是正确的,下面是一个如何在php/wp中实现这一点的示例。希望这有帮助
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;
}
完成附件后,你应该清理干净
unlink($attachment_file);
上述方法是正确的,下面是一个如何在php/wp中实现这一点的示例。希望这有帮助
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;
}
完成附件后,你应该清理干净
unlink($attachment_file);
要更改附件名称,应使用
phpmailer\u init
操作直接访问wp\u mail()中使用的phpmailer
实例,而不是将$files
作为函数参数传递:
function prefix_phpmailer_init(PHPMailer $phpmailer) {
$count = count($_FILES['fichier']['tmp_name']); //Count the number of files
for ($i = 0; $i < $count; $i++) { //loop on each file
if (empty($_FILES['fichier']['error'][$i]))
$phpmailer->addAttachment($_FILES['fichier']['tmp_name'][$i], $_FILES['fichier']['name'][$i]); //Pass both path and name
}
}
add_action('phpmailer_init', 'prefix_phpmailer_init');
wp_mail($to, $subject, $message, $headers);
remove_action('phpmailer_init', 'prefix_phpmailer_init');
函数前缀\u phpmailer\u init(phpmailer$phpmailer){
$count=count($_FILES['fichier']['tmp_name']);//计算文件数
对于每个文件上的($i=0;$i<$count;$i++){//循环
if(空($_文件['fichier']['error'][$i]))
$phpmailer->addAttachment($_FILES['fichier']['tmp_name'][$i],$_FILES['fichier']['name'][$i]);//传递路径和名称
}
}
添加操作('phpmailer_init','prefix_phpmailer_init');
wp_邮件($to、$subject、$message、$headers);
删除操作('phpmailer_init','prefix_phpmailer_init');
要更改附件名称,应使用phpmailer\u init
操作直接访问wp\u mail()中使用的phpmailer
实例,而不是将$files
作为函数参数传递:
function prefix_phpmailer_init(PHPMailer $phpmailer) {
$count = count($_FILES['fichier']['tmp_name']); //Count the number of files
for ($i = 0; $i < $count; $i++) { //loop on each file
if (empty($_FILES['fichier']['error'][$i]))
$phpmailer->addAttachment($_FILES['fichier']['tmp_name'][$i], $_FILES['fichier']['name'][$i]); //Pass both path and name
}
}
add_action('phpmailer_init', 'prefix_phpmailer_init');
wp_mail($to, $subject, $message, $headers);
remove_action('phpmailer_init', 'prefix_phpmailer_init');
函数前缀\u phpmailer\u init(phpmailer$phpmailer){
$count=count($_FILES['fichier']['tmp_name']);//计算文件数
对于每个文件上的($i=0;$i<$count;$i++){//循环
if(空($_文件['fichier']['error'][$i]))
$phpmailer->addAttachment($_FILES['fichier']['tmp_name'][$i],$_FILES['fichier']['name'][$i]);//传递路径和名称
}
}
添加操作('phpmailer_init','prefix_phpmailer_init');
wp_邮件($to、$subject、$message、$headers);
删除操作('phpmailer_init','prefix_phpmailer_init');
我会这么做的,有些人会改变wordpress的核心,但对未来的更新没有好处。谢谢比约恩的回答。是的,这似乎是解决这个问题的唯一办法…wordpress在这里做的很糟糕…至少他们可以给我们他们使用的phpmailer类所拥有的所有选项。我会这么做的,有些人会改变wordpress的核心,但对未来的更新没有好处。谢谢Bjorn的回答。是的,这似乎是解决这个问题的唯一办法…wordpress在这里做的很糟糕…至少他们可以给我们他们使用的phpMail类的所有选项。$\u文件['upload-attachment']['name']可以由客户端更改为“../etc/hosts”…$\u文件['upload-attachment']['name']可由客户端更改为“../etc/hosts”。。。