You can use the stream called php://temp
Using MPDF
If you are using MPDF (version 7) you probably use Composer to install, then it should look like this:
require_once __DIR__ . '/vendor/autoload.php';
Then an example with mpdf:
$mpdf = new \Mpdf\Mpdf();
$mpdf->WriteHTML('Stack Overflow');
$mpdf->Output('php://temp', \Mpdf\Output\Destination::FILE);
And in Phpmailer use like this:
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
$mail = new PHPMailer(true);
try {
//Server settings
$mail->SMTPDebug = 0;
$mail->isSMTP();
$mail->Host = 'smtp1.example.com;smtp2.example.com'; //Configure o seu SMTP
$mail->SMTPAuth = true;
$mail->Username = '[email protected]'; // usuario
$mail->Password = 'secret'; // senha
$mail->SMTPSecure = 'tls'; // TLS se tiver criptografia
$mail->Port = 587; //Porta do SMTP
//Destinatários
$mail->setFrom('[email protected]');
//ADICIONA O ANEXO AQUI
$mail->addAttachment('php://temp', 'Arquivo.pdf');
$mail->isHTML(true);
$mail->Subject = 'ASSUNTO';
$mail->Body = 'Mensagem';
$mail->AltBody = 'mensagem para clientes de email que não usam HTML';
$mail->send();
echo 'Mensagem enviada';
} catch (Exception $e) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
}
Using FPDF
If you’re not using Poser and you’re using FPDF first import what you need:
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'path/to/PHPMailer/src/Exception.php';
require 'path/to/PHPMailer/src/PHPMailer.php';
require 'path/to/PHPMailer/src/SMTP.php';
require 'path/to/fpdf.php';
Then call the FDPF:
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial', 'B',16);
$pdf->Cell(40, 10, 'Stack Overflow!');
$pdf->Output('F', 'php://temp');
And in phpmailer is equal to the first example, it keeps so:
//ADICIONA O ANEXO AQUI
$mail->addAttachment('php://temp', 'Arquivo.pdf');
Hello Gabriel, managed to use the answer? Something is missing?
– Guilherme Nascimento
Actually, I changed my company until
– gabrielfalieri
But at the time came to test? Think that your doubt may be the doubt of future visitors to the site.
– Guilherme Nascimento
No, the demand went to someone else I don’t know
– gabrielfalieri
Get out of the company fast
– gabrielfalieri