PHPmail函数中的“无法访问文件:”
作者:互联网
我正在尝试使用PHPMailer通过电子邮件发送我服务器上存在的文件.当我运行此代码时,我得到“无法访问文件”,电子邮件发送没有附件.任何人都指导我如何解决这个问题
$checkyes=$_POST['check'];
$date = date('Y-m-d');
$my_path ="/data/data/www/fms/pricelists/$checkyes{$date}.xls";
include "class.phpmailer.php"; // include the class file name
$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
//$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail
$mail->Host = "mail.authsmtp.com";
$mail->Port = "25"; // or 587
$mail->IsHTML(true);
$mail->Username = "xxxx";
$mail->Password = "xxxxxxx";
$mail->SetFrom("xxxxxxxxx");
$mail->Subject = $sub1;
$mail->Body = $text_mail;
$mail->AddAddress("xxx@xxxxxx.com");
$mail->AddAddress("xxxxxxx@gmail.com");
$mail->AddAttachment($my_file, $my_path);
if(!$mail->Send()){
echo "Mailer Error: " . $mail->ErrorInfo;
}
else{
echo "Message has been sent";
}
解决方法:
这有效:
$my_path ="/data/data/www/fms/pricelists/example.xls";
include "class.phpmailer.php"; // include the class file name
$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
//$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail
$mail->Host = "mail.authsmtp.com";
$mail->Port = "25"; // or 587
$mail->IsHTML(true);
$mail->Username = "xxxx";
$mail->Password = "xxxxxxx";
$mail->SetFrom("xxxxxxxxx");
$mail->Subject = $sub1;
$mail->Body = $text_mail;
$mail->AddAddress("xxx@xxxxxx.com");
$mail->AddAddress("xxxxxxx@gmail.com");
$mail->AddAttachment($my_path);
if(!$mail->Send()){
echo "Mailer Error: " . $mail->ErrorInfo;
}
else{
echo "Message has been sent";
}
标签:email-attachments,php,email,phpmailer 来源: https://codeday.me/bug/20190825/1717348.html