Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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