Reputation: 31
I'm using the milon / Barcode Library to generate barcodes and I need to get this code and send it by email in a pdf using phpmailer.
When I use echo in the barcode, the code appears perfectly on the screen, but in the pdf only the html code of the boleto is returning.
$d = new DNS1D();
$d->setStorPath(__DIR__.'/cache/');
$codigo = intval($body->codigoDeBarra);
$codigobarra = $d->getBarcodeHTML($codigo, 'EAN13',6,50);
$layout = 'ticket<br>'.$codigobarra;
$pdf = new TCPDF();
$pdf->AddPage();
$pdf->Write(1, $layout);
$pdf->Output('/opt/lampp/htdocs/site/public/boletos/cobranca/'.$email.'-'.$datavencimento.'.pdf', 'F');
// Instantiation and passing `true` enables exceptions
$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 = 'host'; // Set the SMTP server to send through
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'email'; // SMTP username
$mail->Password = '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/site/public/boletos/cobranca/'.$email.'-'.$datavencimento.'.pdf';
//Recipients
$mail->addStringAttachment(file_get_contents($local), 'cobranca.pdf');
$mail->setFrom('[email protected]', 'Bank');
$mail->addAddress($email, $nome); // Add a recipient
// Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Account';
$mail->Body = 'Hi';
$mail->send();
Upvotes: 0
Views: 409
Reputation: 74
Try using the Mpdf Library when using barcodes. It has a reserved working functionality for what you want to acieve.Here's the link https://mpdf.github.io/reference/html-control-tags/barcode.html
Upvotes: 1