fpdf - Send PDF via email

I am using code from this website to convert html code to a PDF:

http://www.fpdf.org/

I have found this code to send the pdf by email, but not sure how to use it:

$mail = new PHPMailer();
...
$doc = $pdf->Output('', 'S');
$mail->AddStringAttachment($doc, 'doc.pdf', 'base64', 'application/pdf');
$mail->Send();

Can you please demonstrate to me with sample code.

i.e. Instead of opening the PDF it send via email from a form submission?
petewinterAsked:
Who is Participating?
 
KalpanConnect With a Mentor Commented:
Please refer the following code

<?php
require("class.phpmailer.php");
$mail = new PHPMailer();$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = "smtp1.example.com;smtp2.example.com";
$mail->SMTPAuth = true;
$mail->Username = 'smtpusername';
$mail->Password = 'smtppassword';

$mail->From="mailer@example.com";
$mail->FromName="My site's mailer";
$mail->Sender="mailer@example.com";
$mail->AddReplyTo("replies@example.com", "Replies for my site");

$mail->AddAddress("email@example.com");
$mail->Subject = "Your invoice";

$mail->IsHTML(false);
$mail->AddAttachment('files/invoice-user-1234.pdf', 'invoice.pdf'); // attach files/invoice-user-1234.pdf, and rename it to invoice.pdf
$mail->Body = "Please find your invoice attached.";
if(!$mail->Send())
{
   echo "Error sending: " . $mail->ErrorInfo;;
}
else
{
   echo "Letter is sent";
}
?>

Open in new window

0
 
petewinterAuthor Commented:
Many thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.