我使用PHPMailer从localhost发送电子邮件。我正在使用附件选项通过电子邮件发送图像。但它显示了以下错误信息:
错误消息:
Failed to move file to C:UsersWork StationAppDataLocalTemp3c3D24E.tmp
我的代码:
require '../PHPMailerAutoload.php';
$m = new PHPMailer();
$m->isSMTP();
$m->SMTPAuth = true;
//$m->SMTPDebug = 2;
$m->Host = gethostbyname('smtp.gmail.com');
$m->Username = 'username';
$m->Password = 'password';
$m->SMTPSecure = 'ssl';
$m->Port = 465;
$m->From = 'support@from.com';
$m->FromName = 'Shibbir Ahmed';
$m->addReplyTo($to);
$m->addAddress($to, 'Shibbir Ahmed');
//Attach multiple files one by one
if(isset($_FILES['userfile'])) {
for ($ct = 0; $ct < count($_FILES['userfile']['tmp_name']); $ct++) {
$uploadfile = tempnam(sys_get_temp_dir(), sha1($_FILES['userfile']['name'][$ct]));
$filename = $_FILES['userfile']['name'][$ct];
if (move_uploaded_file($_FILES['userfile']['tmp_name'][$ct], $uploadfile)) {
$m->addAttachment($uploadfile, $filename);
} else {
echo 'Failed to move file to ' . $uploadfile;
}
}
}
$m->Subject = $subject;
$m->Body = $message;
$m->AltBody = strip_tags($message, "<p>, <br>");
这意味着您的PHP配置(在PHP.ini中)指向一个无法写入的临时目录。sys_get_tmp_dir()
指向该位置,您可以使用sys_temp_dir
PHP.ini设置进行设置。检查upload_tmp_dir
设置也是值得的。
您可能在会话存储等其他方面也有问题。要么修复该位置的权限,使您有写访问权限,要么将其指向您有写权限的某个位置。