Hey there! any question in your mind? Ask It Now!.

Popular Categories





how to send email in PDF format on submit a button

+5 votes
1,177 views
asked in Programming by mannu (990 points)
I am using core php and want to send all content in PDF format by email on submit a button.how can I do this???
Thanks for help.

1 Answer

+1 vote
answered by amit_pammu Expert (5,030 points)
change it according to your code,,!!
<?php
// download fpdf class (http://fpdf.org)
require("/fpd/fpdf.php");
// fpdf object
$pdf = new FPDF();
// generate a simple PDF (for more info, see http://fpdf.org/en/tutorial/)
$pdf->AddPage();
$pdf->SetFont("Arial","B",14);
$pdf->Cell(40,10, "this is a pdf example");
// email stuff (change data below)
$to = "target@domain.com"; 
$from = "me@domain.com"; 
$subject = "send email with pdf attachment"; 
$message = "<p>Please see the attachment.</p>";
// a random hash will be necessary to send mixed content
$separator = md5(time());
// carriage return type (we use a PHP end of line constant)
$eol = PHP_EOL;
// attachment name
$filename = "example.pdf";
// encode data (puts attachment in proper format)
$pdfdoc = $pdf->Output("", "S");
$attachment = chunk_split(base64_encode($pdfdoc));
// main header (multipart mandatory)
$headers = "From: ".$from.$eol;
$headers .= "MIME-Version: 1.0".$eol; 
$headers .= "Content-Type: multipart/mixed; boundary=\"".$separator."\"".$eol.$eol; 
$headers .= "Content-Transfer-Encoding: 7bit".$eol;
$headers .= "This is a MIME encoded message.".$eol.$eol;
// message
$headers .= "--".$separator.$eol;
$headers .= "Content-Type: text/html; charset=\"iso-8859-1\"".$eol;
$headers .= "Content-Transfer-Encoding: 8bit".$eol.$eol;
$headers .= $message.$eol.$eol;
// attachment
$headers .= "--".$separator.$eol;
$headers .= "Content-Type: application/octet-stream; name=\"".$filename."\"".$eol; 
$headers .= "Content-Transfer-Encoding: base64".$eol;
$headers .= "Content-Disposition: attachment".$eol.$eol;
$headers .= $attachment.$eol.$eol;
$headers .= "--".$separator."--";
// send message
mail($to, $subject, "", $headers);
?>

Related Questions

+2 votes
1 answer 150 views
+4 votes
5 answers 756 views
+2 votes
1 answer 171 views
+5 votes
1 answer 224 views
+6 votes
1 answer 254 views
+1 vote
1 answer 776 views
0 votes
1 answer 9,887 views
+2 votes
3 answers 303 views
asked in Programming by jatin Expert (3,823 points)
+4 votes
1 answer 653 views

Not a Member yet?

Ask to Folks Login

My Account
450 Folks are online
2 members and 448 guest online
Your feedback is highly appreciated