“Could Not Access File:” in PHPmail function

人走茶凉 提交于 2019-12-06 03:48:10

This works:

$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";
}

You added your parameters the wrong way:

public function addAttachment($path, $name = '', $encoding = 'base64', $type = '', $disposition = 'attachment')

So this would be the way to go:

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