Created
January 17, 2012 13:45
-
-
Save md2perpe/1626674 to your computer and use it in GitHub Desktop.
Mail a PDF from PHP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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('[email protected]', 'Ämnesrad', $mail, $headers); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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