I'm trying to generate a pdf with tcpdf in laravel and send it by email the content of that pdf will be a boleto. But there is an error when saving the pdf.
generate pdf
$pdf = new TCPDF();
$pdf->AddPage();
$pdf->Write(1, 'Hello world');
$pdf->Output('/techbank/public/boletos/cobranca/'.$email-$datavencimento.'.pdf', 'F');
send mail
$mail = new PHPMailer(true);
//Server settings
$mail->SMTPDebug = SMTP::DEBUG_SERVER; // Enable verbose debug output
$mail->isSMTP();
$mail->CharSet = 'UTF-8'; // Send using SMTP
$mail->Host = ''; // Set the SMTP server to send through
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = ''; // SMTP username
$mail->Password = ''; // SMTP password
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; // Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` encouraged
$mail->Port = 587; // TCP port to connect to, use 465 for `PHPMailer::ENCRYPTION_SMTPS` above
$local = '/opt/lampp/htdocs/techbank/public/boletos/cobranca/'.$email-$datavencimento.'pdf';
//Recipients
$mail->addStringAttachment(file_get_contents($local), 'cobranca.pdf');
$mail->setFrom('', 'title');
$mail->addAddress($email, $nome); // Add a recipient
// Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Cust';
$mail->Body = '
TEXT
$mail->send();
return redirect('cobrancas');
}catch (\Exception $e){
dd($e);
}
Error:
> The behavior of unparenthesized expressions containing both '.' and
> '+'/'-' will change in PHP 8: '+'/'-' will take a higher precedence
I believe the warning is in relation to this line.
$local = '/opt/lampp/htdocs/techbank/public/boletos/cobranca/'.$email-$datavencimento.'pdf';
It wants you to use parentheses to enclose what it believes to be a mathematical calculation.
$local = '/opt/lampp/htdocs/techbank/public/boletos/cobranca/'.($email-$datavencimento).'pdf';
Unless what you really mean is:
$local = '/opt/lampp/htdocs/techbank/public/boletos/cobranca/'.$email.'-'.$datavencimento).'pdf';
EDIT: The same issue is also present in the first code block.
$pdf->Output('/techbank/public/boletos/cobranca/'.$email-$datavencimento.'.pdf', 'F');
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.