我正在尝试使用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";
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。