Create a PDF and Send by Email in PHP

preview_player
Показать описание
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.

Рекомендации по теме
Комментарии
Автор

please sir help me, sir, How to generate excesheet and send as attachment in PHP.

sitararafaqat
Автор

please sir help me, sir, How to generate excesheet and send as attachment in PHP.

sitararafaqat
Автор

<?php
//Import PHPMailer classes into the global namespace
//These must be at the top of your script, not inside a function
use
use PHPMailer\PHPMailer\SMTP;
use

//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>



</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 = //SMTP username
$mail->Password = //SMTP password
$mail->SMTPSecure = 'ssl'; //Enable implicit TLS encryption
$mail->Port = 465; //TCP port to connect to; use 587 if you have set `SMTPSecure =

//Recipients
'Sitara');
$mail->addAddress($email);

//Attachments
//Optional name

//Content

$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

sitararafaqat
Автор

creating pdf but not sending and showing error

toxicviper
Автор

Halo..how to generate and automatic insert pdf file into mysql database using php with one button klik ??🙏

gustiaslian
Автор

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

davidgomez
Автор

From where i can get dompdf/autoload.inc.php file?

-ehtashamhaider
Автор

sir, How to generate excesheet and send as attachment in PHP.

sitararafaqat
Автор

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.

vickyyagami
Автор

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 Dompdf\mb_internal_encoding() in


Thanks in Advance
Ajit Kumar

ajitkumarkv
Автор

Você está de parabéns, tem me ajudado bastante nos meus estudos!

hrrelax
Автор

I find dompdf the easiest to use for creating pdf docs in php. writing pdfs in html is so easy and simple

jonathans
Автор

Hello, is there a way in WPForms to save and send forms in PDF to my email account

vendercentraldirectorylist
Автор

please sir make videos on referral and earn system using php

yera
Автор

hi ... any example for excel attachment?

akichoe
Автор

Hello sir..thank to you again.. :-) sir will you make import and export data on excel format to the mysqlbase. Thanks sir.

neiljohnramirez
Автор

you are awesome.
I hav a question--
I want to print my submitted form.
webpage is in php mysql.
after submit, it should show company name address and customer name and total amount in pdf form. customer will print that pdf.
do you hav any vid.
please suggest me.

parthaceo
Автор

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.. :-)

neiljohnramirez
Автор

thank you! the code works perfect. only class pdf is redundant because you could simply instantiate Dompdf by saying $pdf = new Dompdf();

claudiubanu
Автор

Thanks nice tutorial I will adapt it to Codeigniter

rafaelsanchez