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";
}
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";
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With