Jump to content

html content pdf is not displaying pdf when viewed using php mail


Recommended Posts

Hi Team

I have tried to create send email using php mail function and attach one file, but the issue i am facing now pdf document is only shown on html content not displaying it as a pdf and need some around 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 = 'gcobani.mkontwana@agilelimitless.org.za'; //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;

?>

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.