PHP 7 FPDF Script to Send Email With PDF File as Attachment Using PHPmailer Library in Browser Full Project For Beginners

  • Post author:
  • Post category:PHP
  • Post comments:0 Comments




You can use PHPMailer with FPDF . It works properly without any hassle. You need to change parameter for $pdf->Output . Download and copy class.phpmailer.php and PHPMailerAutoload.php to your work folder. Attach class.phpmailer.php below or above require('html2pdf.php'); . I have done this before so this will work. According to your code this should work.

function send_pdf_to_user(){
    if($_REQUEST['action'] == 'pdf_invoice' ){
        $pdf=new PDF_HTML();

        $text = get_html_message($_REQUEST['eventid'], $_REQUEST['userid']);

        $mail = new PHPMailer(); // defaults to using php "mail()"
        $body = "This is test mail by monirul";

        $mail->AddReplyTo("","Test Lernt");
        $mail->SetFrom('', 'Test Lernt');

        $address = "";
        $mail->AddAddress($address, "Abdul Kuddos");       
        $mail->Subject    = "Test Invoice";       
        $mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test

        //documentation for Output method here:       
        $pdf->Output("Test Invoice.pdf","F");
        $path = "Walter Lernt Invoice.pdf";

        $mail->AddAttachment($path, '', $encoding = 'base64', $type = 'application/pdf');
        global $message;
        if(!$mail->Send()) {
          $message =  "Invoice could not be send. Mailer Error: " . $mail->ErrorInfo;
        } else {
          $message = "Invoice sent!";


Leave a Reply