fpdf - Send PDF via email

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


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');

Can you please demonstrate to me with sample code.

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

$mail = new PHPMailer();$mail = new PHPMailer();
$mail->Host = "smtp1.example.com;smtp2.example.com";
$mail->SMTPAuth = true;
$mail->Username = 'smtpusername';
$mail->Password = 'smtppassword';

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

$mail->Subject = "Your invoice";

$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.";
   echo "Error sending: " . $mail->ErrorInfo;;
   echo "Letter is sent";

Open in new window

petewinterAuthor Commented:
Many thanks
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.