Why is PHPmailer not sending the attachment?

佐手、 提交于 2019-11-29 17:12:00

As I said in your other question, the first warning is due to you using $filename in line 10 of your script, without having assigned a value to it first:

$dir ="uploads/$filename"; // $filename has NOT been defined at this point.

As well, for your attachments, why not simply do:

foreach(array_keys($_FILES['files']['name']) as $key) {
   $source = $_FILES['files']['tmp_name'][$key]; // location of PHP's temporary file for this.
   $filename = $_FILES['files']['name'][$key]; // original filename from the client

   $mail->AddAttachment($source, $filename);
}

There's no need to do all the file copying, building your own paths, etc... Just directly attach the temporary file PHP creates for you, and name it with whatever the original filename was.

Your script is far more complicated than it needs to be.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!