Skip to content

Instantly share code, notes, and snippets.

@md2perpe
Created January 17, 2012 13:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save md2perpe/1626674 to your computer and use it in GitHub Desktop.
Save md2perpe/1626674 to your computer and use it in GitHub Desktop.
Mail a PDF from PHP
<?php
// Läs in PDF-dokument och konvertera till base64
$pdf = file_get_contents('test.pdf');
$b64 = base64_encode($pdf);
// Läs in mail-mall
ob_start();
include 'mail-tpl.php';
$mail = ob_get_clean();
$headers = <<<end_text
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary="this-is-my-separator"
end_text;
// Skicka mail
mail('user@domain.com', 'Ämnesrad', $mail, $headers);
Detta mail är i MIME-format. Använd ett mailprogram som klarar av MIME-formatet och bifogade filer.
--this-is-my-separator
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 8bit
Här kommer huvudmeddelandet.
--this-is-my-separator
Content-Type: application/pdf;
name="test.pdf"
Content-Transfer-Encoding: base64
Content-Disposition: inline;
filename="test.pdf"
<?php echo $b64 ?>
--this-is-my-separator--
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment