Hi Team
I need some help, i am sending pdf email but the problem when inspect stack trace using logs. Im getting this problem and dont know how to fix it file_get_contents(FASHION SHOW.pdf): failed to open stream: No such file or directory in /home/acifinan/public_html/application.php on line 94
// application.php
--- Function to send email as attached is below
function send_pdf_to_user(){
if($_REQUEST['action'] == 'pdf_invoice' ){
require('application.php');
require_once('class.phpmailer.php');
$pdf=new PDF_HTML();
$pdf->SetFont('Arial','',11);
$pdf->AddPage();
$text = get_html_message($_REQUEST['Amount'], $_REQUEST['Purpose'], $_REQUEST['Voucher']);
if(ini_get('magic_quotes_gpc')=='1')
$text=stripslashes($text);
$pdf->WriteHTML($text);
$mail = new PHPMailer(); // defaults to using php "mail()"
$body = "";
$mail->AddReplyTo("[email protected]","Test Lernt");
$mail->SetFrom('[email protected]', 'Test Lernt');
$address = "[email protected]";
$mail->AddAddress($address, "ACI Finance");
$mail->Subject = "Application for a Loan";
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->MsgHTML($body);
$pdf->Output("Application Loan.pdf","F");
$path = "application.pdf";
$mail->AddAttachment($path, '', $encoding = 'base64', $type = 'application/pdf');
global $message;
if(!$mail->Send()) {
$message = "Application for a loan could not be send. Mailer Error: " . $mail->ErrorInfo;
} else {
$message = "Application for a loan is sent!";
}
}
}
// application.php query to the db and file format of the document with Content header
echo "after function";
$to = "[email protected]";
$from = $_REQUEST['email'];
$content = file_get_contents($filenameee);// main concerned is here
$content = chunk_split(base64_encode($content));
// main header (multipart mandatory)
$headers = "From: ".$from." <".$from.">" . $eol;
$headers .= "MIME-Version: 1.0" . $eol;
$headers .= "Content-Type: multipart/mixed; boundary=\"" . $separator . "\"" . $eol;
$headers .= "Content-Transfer-Encoding: 7bit" . $eol;
$headers .= "This is a MIME encoded message." . $eol;
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$subject = "Application Form";
// a random hash will be necessary to send mixed content
$separator = md5(time());
// carriage return type (RFC)
$eol = "\r\n";
Tuhin PaulPosted Mar 3, 2023, 10:40 PM
Hello,
Check that the file exists in the correct path and that you have provided the correct file name and path in the $path variable.
You can try adding the following code before the line where you are trying to attach the file to the email to check if the file exists and to print its path:
Also, make sure that you have the necessary permissions to read the file. You can check the file permissions using the following command in a terminal or command prompt:
If the file is not readable by the script, you may need to change the file permissions using the chmod command:
If you have confirmed that the file exists and is readable, and the error still persists, you can try using the absolute path to the file instead of a relative path. You can get the absolute path to the file using the realpath function:
I hope this helps! Let me know if you have any further questions.