Learn How to generate PDF and send as attachment in PHP. Create PDF file using DomPDF and send PDF file as attachment with Email using PHPMailer. Convert HTML to PDF with Send email in PHP. Make PDF using Dompdf then send email with PDF as attachment.
For Source Code – …(read more)
Convert Word 2 PDF: Word to PDF Converter
Convert PowerPoint 2 PDF: PPT to PDF Converter
Convert Excel 2 PDF: Excel to PDF Converter
Convert an Image 2 PDF: Image to PDF Converter
Convert HTML 2 PDF: HTML to PDF Converter
More Tools: PDF Converter
I find dompdf the easiest to use for creating pdf docs in php. writing pdfs in html is so easy and simple
Hi, good job easy to follow video! One problem only, when I send the pdf I have the error failed to load pdf document. Any idea how to fix it? I mean the pdf is recieved and everything, just that it is not saved with correct format I think
<?php
//Import PHPMailer classes into the global namespace
//These must be at the top of your script, not inside a function
use PHPMailerPHPMailerPHPMailer;
use PHPMailerPHPMailerSMTP;
use PHPMailerPHPMailerException;
//Load Composer's autoloader
require 'vendor/autoload.php';
include 'config.php';
//Create an instance; passing `true` enables exceptions
function fetch_customer_data($conn)
{
$query = "SELECT * FROM users";
$statement = $conn->prepare($query);
$statement->execute();
$result = array($statement->fetch());
$output = '
<div class="table-responsive">
<table class="table table-striped table-bordered">
<tr>
<th>Name </th>
<th>lastname</th>
</tr>
';
foreach($result as $row)
{
$output .= '
<tr>
<td>'.$row["firstname"].'</td>
<td>'.$row["lastname"].'</td>
</tr>
';
}
$output .= '
</table>
</div>
';
return $output;
}
$html_code='';
$pdf='';
$mail = new PHPMailer(true);
$file_name='';
if(isset($_POST['send'])){
$file_name = md5(rand()) .'.xls';
$html_code .= fetch_customer_data($conn);
file_put_contents($file_name, $html_code);
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
try {
//Server settings
$mail->SMTPDebug = SMTP::DEBUG_SERVER; //Enable verbose debug output
$mail->isSMTP(); //Send using SMTP
$mail->Host = 'smtp.gmail.com'; //Set the SMTP server to send through
$mail->SMTPAuth = true; //Enable SMTP authentication
$mail->Username = 'xxxxxxxxxx'; //SMTP username
$mail->Password = 'xxxxxxxxxxxxxx'; //SMTP password
$mail->SMTPSecure = 'ssl'; //Enable implicit TLS encryption
$mail->Port = 465; //TCP port to connect to; use 587 if you have set `SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS`
//Recipients
$mail->setFrom('xxxxxxxxxx, 'Sitara');
$mail->addAddress($email);
//Attachments
//Optional name
//Content
$mail->addAttachment($file_name);
$mail->isHTML(true); //Set email format $mail->Subject = $subject;
$mail->Body= $message;
// $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
$mail->send();
echo 'Message has been sent';
}
catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
}
?>
this code run , but with attachment does not contain data . excel sheet only have table heading
please sir help me,sir, How to generate excesheet and send as attachment in PHP.
please sir help me,sir, How to generate excesheet and send as attachment in PHP.
sir, How to generate excesheet and send as attachment in PHP.
creating pdf but not sending and showing error
From where i can get dompdf/autoload.inc.php file?
Thank you for awesome video. I need help that i added data in mysql. I need to use your video code but email shoukd sent to one customer only. For example in db table 1 line have email address. I want to get that email and send his reservation detail to customer email which is already in DB table.
Hi
Webslesson
I try to incorporate this code but i am getting an error . What is this reason for this .
PHP Fatal error: Uncaught Error: Call to undefined function Dompdfmb_internal_encoding() in /home/stmarhgjhn/public_html/ovbs/pdfconverter/dompdf/src/Dompdf.php:274
Thanks in Advance
Ajit Kumar
Thanks boss
hi … any example for excel attachment?
Hello, is there a way in WPForms to save and send forms in PDF to my email account
thank you Steven H
Help appreciated. Thanks for sharing.
gracias amigo aprendi mucho
How to add image inside pdf?
Thanks nice tutorial I will adapt it to Codeigniter
Hello, how can we edit the script to display Unicode characters?
file is corrupted
hi sir please I want to send it by email in laravel
Sir ,one question how to increase the width and height of pdf file
Hyy sir .
Your tutorial is to much helping
thank You
hello, I have dowloaded the sourcecode and its converting data into pdf but its not sending the pdf to email address.. what to do?
Which php version?
thank you! the code works perfect. only class pdf is redundant because you could simply instantiate Dompdf by saying $pdf = new Dompdf();
falto la base de datos .sql para hacer ese ejemplo
Please make this video for codeigniter
It doesn't work for me! 🙁
How to add pdf file in PHP website and download
https://github.com/viralsolani/laravel-adminpanel
Kindly sir make videos on this package
Gracias desde México
Hello sir.. sir request. Can you make a tutorial on how to format pdf (coloring cell, size of cell, margin, inserting header and footer? Thanks much sir.. 🙂
please publish a tutorial on showing all respective data in a form using select box
i sir i have one question ,how to upload attachment like document file ,pdf etc using simple php mysql
i sir i have one question ,how to upload attachment like document file ,pdf etc using simple php mysql