Guest User

Guest User

  • Tech Writer
  • 2.1k
  • 452.8k

file size stat failed in file upload using php mail

Mar 10 2023 10:48 AM

Hi Team

I cant seem to upload and display pdf attachment and need some help, here is my logic below;

<?php
$filenameee = $_FILES['id']['name'];

 $message = "Name: ". $fname . $lname . "\r\n Email: " . $email . "\r\n Cell Number: " . $number . "\r\n Monthly Income: " . $income . "\r\n Loan Amount: " . $amount . "\r\n Town:" . $town . "\r\n id :.$filenameee.";
   
   $subject ="Application Form";
   $fromname ="ACI FINANCE";
   $fromemail = $email; //if u dont have an email create one on your cpanel
   $mailto = '[email protected]'; //the email which u want to recv this email


// Define the message body
$body = '--'.$separator.$eol;
$body .= 'Content-Type: text/plain; charset="iso-8859-1"'.$eol;
$body .= 'Content-Transfer-Encoding: 8bit'.$eol.$eol;
$body .= $message.$eol;

    // Define the first attachment
$filenameee = 'public_html/PHPMailer/path/to/attachment1/id.pdf';
$file_size = filesize($filenameee);
$file_name = basename($filenameee);
$handle = @fopen($filenameee, 'rb');
$content = @fread($handle, $file_size);
@fclose($handle);
$attachment = chunk_split(base64_encode($content));
$body .= '--'.$separator.$eol;
$body .= 'Content-Type: application/pdf; name="'.$file_name.'"'.$eol;
$body .= 'Content-Transfer-Encoding: base64'.$eol;
$body .= 'Content-Disposition: attachment; filename="'.$file_name.'"'.$eol.$eol;
$body .= $attachment.$eol;
$body .= '--'.$separator.'--'.$eol;

?>