D
D
Daniel2019-05-10 18:43:26
PHP
Daniel, 2019-05-10 18:43:26

Attach generated PDF file (blob) in phpmailer?

Good afternoon!
Using the library for creating a pdf document, I create the pdf itself.
5cd59b9d39d84520631193.png

const worker = html2pdf();
worker
      .set(opt)
      .from(text, "string")
      .output("blob")
      .then(pdf => {
        const formData = new FormData();
        formData.append("php", pdf);
        // console.log(pdf);

        var xhr = new XMLHttpRequest();
        xhr.open("POST", "mailer.php");
        xhr.send(formData);
      });

The output is a blob.
5cd59ba8db73e357294844.png
You need to attach it to the letter and send it.
Here is the letter code:
use PHPMailer\PHPMailer\PHPMailer;
  use PHPMailer\PHPMailer\Exception;

  require 'lib/src/Exception.php';
  require 'lib/src/PHPMailer.php';
  require 'lib/src/SMTP.php';

  $email = new PHPMailer();
  $email->CharSet = 'UTF-8';
  $email->SetFrom('[email protected]', 'Test'); //Name is optional
  $email->Subject   = 'Договор';
  $email->Body = 'Тестируем отправку почты';
  $email->AddAddress( '[email protected]' );

  return $email->Send();

Can you please tell me how it can be done in this case?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question