0

I m new to php. I need to send the email with the pdf attachment.I m able to send an email with the attachment. But unable to open the pdf. I get the some error like this

Store information to the database(done), Sends the staff an email with the new customer information (done), and Send the customer a "thank you message" email with a pdf file attachment (not working). I mean, the customer does receive an email, but when he/she opens the pdf file, I get the following error message:

"Acrobat could not oen 'file_name' because it is either not a supported file type or because the file has been damaged(for example, it was sent as an email attachment and wasn't correctly decoded)..."

If someone could help me resolve this problem, that would be great. Thanks!

Here is my code:

$to = 'form@kronova.in, ' . $Email;
$subject = 'ABC :: Admission Form Details';
$repEmail = 'form@kronova.in';

$fileName = 'ABC-Admission.pdf';
$fileatt = $pdf->Output($fileName, 'E');
$attachment = chunk_split($fileatt);
$eol = PHP_EOL;
$separator = md5(time());

$headers = 'From: Principal abc <'.$repEmail.'>'.$eol;
$headers .= 'MIME-Version: 1.0' .$eol;
$headers .= "Content-Type: multipart/mixed; boundary=\"".$separator."\"";

$message = "--".$separator.$eol;
$message .= "Content-Transfer-Encoding: 7bit".$eol.$eol;
$message .= "Thanks for filling online application form. Your online admission registration number is E0000". mysql_insert_id() . "." .$eol;

$message .= "--".$separator.$eol;
$message .= "Content-Type: text/html; charset=\"iso-8859-1\"".$eol;
$message .= "Content-Transfer-Encoding: 8bit".$eol.$eol;

$message .= "--".$separator.$eol;
$message .= "Content-Type: application/pdf; name=\"".$fileName."\"".$eol; 
$message .= "Content-Transfer-Encoding: base64".$eol;
$message .= "Content-Disposition: attachment".$eol.$eol;
$message .= $attachment.$eol;
$message .= "--".$separator."--";

if (mail($to, $subject, $message, $headers)){
echo "Email sent";
}

else {
echo "Email failed";

}

user3377635
  • 153
  • 1
  • 5
  • 12
  • Sounds like an encoding problem. Hard to say what encoding you should use. But why are you using the mail() function? Use the wonderful and very very easy to implement and use [PHPMailer](https://github.com/PHPMailer/PHPMailer) class. Take a look at the example at the bottom of the linked page. With this class it is very easy to send complex emails like HTML-Mails or (in your case) Emails with attachments. – Maarkoize Apr 15 '14 at 12:28
  • possible duplicate of [PHP Send email with PDF attachment without creating the file?](http://stackoverflow.com/questions/2146591/php-send-email-with-pdf-attachment-without-creating-the-file) – PhoneixS Jul 03 '14 at 15:10

0 Answers0