Guest User

Guest User

  • Tech Writer
  • 2.1k
  • 473.7k

Failed to load pdf using php mail function

Mar 9 2023 10:51 AM

Hi Team

I am unable to view pdf and below is my logic for attaching pdf, please advice me i have been stuck with this issue for way to long. Advice me how to attach many docs after. When i try to open its said failed to load "Expected: application/pdf (.pdf); found: text/plain (.txt)"

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

   $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
   $content = file_get_contents($filenameee);
   $content = chunk_split(base64_encode($content));
   
   // a random hash will be necessary to send mixed content
   $separator = md5(time());
   
   // carriage return type (RFC)
   $eol = "\r\n";
   
    // main header (multipart mandatory)
   $headers = "From: ".$fromname." <".$fromemail.">" . $eol;
   $headers .= "MIME-Version: 1.0" . $eol;
   $headers .= "Content-Type: multipart/mixed; boundary=\"" . $separator . "\"" . $eol;
   $headers .= "Content-Transfer-Encoding: binary";
   $headers .= "This is a MIME encoded message." ;
    $headers .="Content-Length:  . filesize($filenameee)";
    $headers .="Accept-Ranges: bytes" ;
    @readfile($filenameee);

    $body .= "<tr><td style='border:none;'><strong>Monthly income:</strong> {$income}</td></tr>";
	$body .= "<tr><td></td></tr>";
	$body .= "<tr><td style='border:none;'><strong>Town:</strong> {$town}</td></tr>";
	$body .= "<tr><td></td></tr>";
	$body .= "<tr><td style='border:none;'><strong>Upload bankstatement </strong> {$bankstatement}</td></tr>";
	$body .= "<tr><td></td></tr>";
	$body .= "<tr><td style='border:none;'><strong>Upload payslip:</strong> {$payslip}</td></tr>";
	$body .= "<tr><td></td></tr>";
	$body .= "<tr><td colspan='2' style='border:none;'><strong></strong> </td></tr>";
	// message
  //$body = "--" . $separator . $eol;
  $body .= "Content-Type: text/plain; charset=\"iso-8859-1\"" . $eol;
  $body .= "Content-Transfer-Encoding: binary" . $eol;
  $body .= $message . $eol;
	// attachment
 $body .= "--" . $separator . $eol;
 $body .= "Content-Type: application/pdf; name=\"" . $filenameee . "\"" . $eol;
 $body .= "Content-Transfer-Encoding: binary" . $eol;
 $body .= 'Content-Disposition: inline; $filenameee="' . $filenameee . '"';
$body .= $content . $eol;

$body .= "</tbody></table>";
	
$body .= "</body></html>";
 
?>

 


Answers (1)