使用SwiftMailer和PHP检索要附加到电子邮件的文件名

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了使用SwiftMailer和PHP检索要附加到电子邮件的文件名脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
我昨天问了这个问题并得到了一个建议并使用了它,但由于某种原因它没有用.
因此,我需要检索用户HTML表单上传到我的服务器文件名称.我需要将此文件附加到由 PHP / SwiftMailer发送的邮件中.
这是我的代码,文件上传部分:

//File upload

// Where the file is going to be placed 
$target_path = "uploads/";

// Add the original filename to our target path.  
//Result is "uploads/filename.extension" 
$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!";
}   

//End of file upload

这是文件附加部分:

//Create the attachment
$attachment = Swift_Attachment::FromPath($_FILES['uploadedfile']['tmp_name']);

为什么不从服务器获取文件
这是错误消息,看起来它正在尝试在错误的目录中找到该文件

谢谢!

解决方法

使用:

$attachment = Swift_Attachment::fromPath($target_path);

这是因为您已将文件从其临时位置移动,$_FILES [‘uploadedfile’] [‘tmp_name’]返回使用move_uploaded_file移动文件之前的路径.这假设$target_path在swift邮件程序代码的范围内

脚本宝典总结

以上是脚本宝典为你收集整理的使用SwiftMailer和PHP检索要附加到电子邮件的文件名全部内容,希望文章能够帮你解决使用SwiftMailer和PHP检索要附加到电子邮件的文件名所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。