Created
September 28, 2018 07:01
-
-
Save pdfcrowd/a0a23dac017a1ec1a1d81afa5c8f3f3d to your computer and use it in GitHub Desktop.
Generate PDF using the Pdfcrowd API v2 and send it as an email attachment
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
// uses the PHP PEAR modules for sending MIME email | |
// http://pear.php.net/package/Mail | |
// http://pear.php.net/package/Mail_Mime | |
<?php | |
require 'pdfcrowd.php'; | |
require_once('Mail.php'); | |
require_once('Mail/mime.php'); | |
$client = new \Pdfcrowd\HtmlToPdfClient($username, $apikey); | |
$pdf = $client->convertString('Hello World'); | |
$to = "recipient@example.com"; | |
$from = "sender@example.com"; | |
$subject = "A test email with a PDF attachment"; | |
$txtbody = "Please find the pdf attached."; | |
// create a new instance of the Mail_Mime class | |
$mime = new Mail_Mime(); | |
$mime->setTXTBody($txtbody); | |
$mime->addAttachment($pdf, 'application/pdf', 'helloworld.pdf', false, 'base64'); | |
$smtpinfo["host"] = "your smtp server"; | |
$smtpinfo["port"] = "25"; | |
$smtpinfo["auth"] = true; | |
$smtpinfo["username"] = "smtp-username"; | |
$smtpinfo["password"] = "smtp-password"; | |
$smtpinfo["debug"] = false; | |
// build email message and save it in $body | |
$headers = array( | |
'From' => $from, | |
'Subject' => $subject); | |
$body = $mime->get(); | |
$hdrs = $mime->headers($headers); | |
$mail = &Mail::factory("smtp", $smtpinfo); | |
$mail->send($to, $hdrs, $body); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment