PHPmail函数中的“无法访问文件:" [英] “Could Not Access File:” in PHPmail function

查看:397
本文介绍了PHPmail函数中的“无法访问文件:"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用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.can anyone guide me how to fix this

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

这篇关于PHPmail函数中的“无法访问文件:"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆