我使用PHPMailer从表单发送带有多个附件的邮件。这是表格的一部分:
Attachment:<br />
<input type="file" name="attach1" id="attach1" />
<input type="file" name="attach2" id="attach2" />
<input type="file" name="attach3" id="attach3" />
当用户只附加一个或两个文件时,我在email.php中添加了一些条件:
if(!empty($_FILES['attach1'] ))
{
$mail->AddAttachment($_FILES['attach1']['tmp_name']); // bijlage 1
}
if(!empty($_FILES['attach2']))
{
$mail->AddAttachment($_FILES['attach2']['tmp_name']); // bijlage 2
}
if(!empty($_FILES['attach3']))
{
$mail->AddAttachment($_FILES['attach3']['tmp_name']); // bijlage 3
}
但是我仍然收到空输入字段上的消息“无法访问文件”。这些附件被正确地发送到电子邮件地址,即使与此消息。但是,当我只使用1到2个附件时,我想摆脱它。
发布于 2015-05-05 13:57:09
好的。这一行:
if(!empty($_FILES['attach3']))..
不是等于false
( $_FILES['attach3']
中的数组不是空的:它在$_FILES['attach3']['error']
和其他一些字段中有错误代码eq 4 (UPLOAD_ERR_NO_FILE
) ),当您只发送1和2个攻击时,在第三种情况下可以看到"could not access file"
的消息。您需要将支票更改为:
if(!empty($_FILES['attach1']['name'] ))....
if(!empty($_FILES['attach2']['name'] ))....
if(!empty($_FILES['attach3']['name'] ))....
发布于 2015-05-05 22:46:26
您这样做是错误的-您应该在访问$_FILES中的文件之前使用医生们和PHPMailer提供的示例代码。
https://stackoverflow.com/questions/30063273
复制