PHPMailer“无法访问文件:” [英] PHPMailer "Could Not Access File:"
本文介绍了PHPMailer“无法访问文件:”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用PHPMailer向我的服务器上存在的文件发送电子邮件。当我运行这个代码,我得到无法访问文件,电子邮件发送没有附件...这里是什么错误?
I am trying to email a file that exists on my server using PHPMailer. When I run this code, I get "Could not access file" and the email sends without the attachment... what is wrong here??
<html>
<title>Email Sent!</title>
<?php
include("menu.php");
include("sqlconnect.php");
require_once('../PHPMailer/class.phpmailer.php');
$path = $_POST['path'];
$filename = $_POST['filename'];
$newpath = "Library/WebServer/Documents/Inventory/".$path;
define('GUSER', 'xxxxxxx@gmail.com'); // GMail username
define('GPWD', 'xxxxxxx'); // GMail password
function smtpmailer($to, $from, $from_name, $subject, $body) {
global $error;
$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 0; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail
$mail->Host = 'smtp.gmail.com';
$mail->Port = 465;
$mail->Username = GUSER;
$mail->Password = GPWD;
$mail->SetFrom($from, $from_name);
$mail->Subject = $subject;
$mail->Body = $body;
$mail->AddAddress($to);
$attachtest = $mail->AddAttachment($newpath);
if(!$mail->Send()) {
$error = 'Mail error: '.$mail->ErrorInfo;
return false;
} else {
$error = 'Message sent!';
return true;
}
}
smtpmailer('xxxxxxx@me.com', 'xxxxxxxx@gmail.com', 'Name', 'test mail message', 'Hello World!');
?>
</html>
推荐答案
尝试将正确的路径传递到您的函数中, / p>
Try passing the correct path into your function like this
function smtpmailer($to, $from, $from_name, $subject, $body, $newpath)
并调用它像
smtpmailer('xxxxxxx@me.com', 'xxxxxxxx@gmail.com', 'Name', 'test mail message', 'Hello World!', $newpath);
这篇关于PHPMailer“无法访问文件:”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文