Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

“Could Not Access File:” in PHPmail function

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("[email protected]");
    $mail->AddAddress("[email protected]");

    $mail->AddAttachment($my_file, $my_path);
     if(!$mail->Send()){
     echo "Mailer Error: " . $mail->ErrorInfo;
    }
    else{
     echo "Message has been sent";
    }
like image 705
arok Avatar asked Mar 20 '23 21:03

arok


1 Answers

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("[email protected]");
$mail->AddAddress("[email protected]");

$mail->AddAttachment($my_path);
if(!$mail->Send()){
 echo "Mailer Error: " . $mail->ErrorInfo;
}else{
 echo "Message has been sent";
}
like image 123
Pedro Lobito Avatar answered Mar 29 '23 05:03

Pedro Lobito