Jump to content

This CODE!!


RON_ron

Recommended Posts

I'm not a PHP guy. Please explain what doses this piece of code mean. I'm trying to figureout how to send an attachment by generating a PDF in PHP.

 

$pdfdoc = $pdf->Output("", "S"); // what's this?

$attachment = chunk_split(base64_encode($pdfdoc)); //what's this?

 

:shrug:

Link to comment
Share on other sites

<?php
require("/fpd/fpdf.php");
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont("Arial","B",14);
$pdf->Cell(40,10, "this is a <strong class="highlight">pdf</strong> example");
$to = "abc@gmail.com"; 
$from = "BBQ"; 
$subject = "<strong class="highlight">send</strong> <strong class="highlight">email</strong> with <strong class="highlight">pdf</strong> attachment"; 
$message = "<p>Please see the attachment.</p>";
$separator = md5(time());
$eol = PHP_EOL;
$filename = "example.pdf";
$pdfdoc = $pdf->Output("", "S");
$attachment = chunk_split(base64_encode($pdfdoc));
$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;
$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."--";
mail($to, $subject, "", $headers);
mail($to, $subject, "", $headers);
?>

Link to comment
Share on other sites

As per fpdf.org

 

Output

string Output([string name, string dest])

 

Description

 

Send the document to a given destination: browser, file or string. In the case of browser, the plug-in may be used (if present) or a download ("Save as" dialog box) may be forced.

The method first calls Close() if necessary to terminate the document.

Parameters

 

name

The name of the file. If not specified, the document will be sent to the browser (destination I) with the name doc.pdf.

dest

Destination where to send the document. It can take one of the following values:

I: send the file inline to the browser. The plug-in is used if available. The name given by name is used when one selects the "Save as" option on the link generating the PDF.

D: send to the browser and force a file download with the name given by name.

F: save to a local file with the name given by name (may include a path).

S: return the document as a string. name is ignored.

Link to comment
Share on other sites

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.