Last active
February 15, 2020 21:18
-
-
Save pdfcrowd/2891593 to your computer and use it in GitHub Desktop.
generate a PDF using the Pdfcrowd API and send it as an email attachment (II.)
This file contains 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 | |
require 'pdfcrowd.php'; | |
try | |
{ | |
// generate a PDF file | |
$client = new Pdfcrowd($username, $apikey); | |
$pdf = $client->convertHtml("Hello World"); | |
//Deal with the email | |
$to = 'recipient@example.com'; | |
$from = 'sender@example.com'; | |
$subject = 'a PDF file for you'; | |
$content = 'Please find the file attached'; | |
$attachment = chunk_split(base64_encode($pdf)); | |
$filename = "myfile.pdf"; | |
$boundary =md5(date('r', time())); | |
$headers = "From: $from\r\nReply-To: $from"; | |
$headers .= "\r\nMIME-Version: 1.0\r\nContent-Type: multipart/mixed; boundary=\"_1_$boundary\""; | |
$message="This is a multi-part message in MIME format. | |
--_1_$boundary | |
Content-Type: multipart/alternative; boundary=\"_2_$boundary\" | |
--_2_$boundary | |
Content-Type: text/plain; charset=\"iso-8859-1\" | |
Content-Transfer-Encoding: 7bit | |
$content | |
--_2_$boundary-- | |
--_1_$boundary | |
Content-Type: application/pdf; name=\"$filename\" | |
Content-Transfer-Encoding: base64 | |
Content-Disposition: attachment | |
$attachment | |
--_1_$boundary--"; | |
mail($to, $subject, $message, $headers); | |
} | |
catch(PdfcrowdException $e) | |
{ | |
echo "Pdfcrowd Error: " . $e->getMessage(); | |
} | |
?> |
where is this file???? require 'pdfcrowd.php';
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello, I had the same probles as here.
http://pdfcrowd.com/forums/read.php?3,2112
please remove all whitespaces from end of lines