phpMailer发送附件名称,而不是附件 [英] phpMailer sending attachment name, not attachment
本文介绍了phpMailer发送附件名称,而不是附件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个名称为"file1"的文件上传字段,并在phpmailer脚本中包含代码:
Hi I have a file upload field with name="file1" and code in a phpmailer script:
if (isset($_FILES['file1']))
{
$file1_path = $_FILES['file1']['tmp_name'];
$file1_name = $_FILES['file1']['name'];
$file1_type = $_FILES['file1']['type'];
$file1_error = $_FILES['file1']['error'];
$mail->AddAttachment($file1_path);
}
由于某种原因,它像php45we34一样附加(每个时间差异似乎是其临时名称路径,而不是实际文件)
And for some reason, it attached like php45we34 (each time diff, seems that its the temp name path, not the actual file)
有帮助吗?
推荐答案
我建议您在添加附件之前使用move_uploaded_file函数.
I suggest you to use function move_uploaded_file before adding attachment.
这是示例代码,它将文件从服务器上某个位置的临时位置移出
This is sample code that will move file from temporary location somewhere at your server
$target_path = "uploads/";
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
echo "The file ". basename( $_FILES['uploadedfile']['name']).
" has been uploaded";
} else{
echo "There was an error uploading the file, please try again!";
}
之后,AddAttachment应该可以正常工作.
After that AddAttachment should work fine.
$mail->AddAttachment(basename($target_path . $_FILES['uploadedfile']['name']));
这篇关于phpMailer发送附件名称,而不是附件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文