<?php
require $_SERVER['DOCUMENT_ROOT'].'/pdf/phpmailer/class.phpmailer.php';
require $_SERVER['DOCUMENT_ROOT'].'/vendor/autoload.php';
$to = "vijaychauhanssn@gmail.com";
$from = "vijaychauhanssn@gmail.com";
$subject = "sunject here";
$message = "<p>Msg here</p>";
$stylesheet = file_get_contents($_SERVER['DOCUMENT_ROOT'].'/assets/css/pdf.css');
$html = '<div id="printablearea">
<div class="container1" >
body content here
</div>
</div>';
$mpdf = new \Mpdf\Mpdf(['tempDir' => sys_get_temp_dir().DIRECTORY_SEPARATOR.'mpdf','default_font' => 'Arial', 'format' => 'A4']);
$mpdf->autoScriptToLang = true;
$mpdf->autoLangToFont = true;
$mpdf->WriteHTML($stylesheet, 1);
$mpdf->WriteHTML($html);
//call watermark content aand image
//$mpdf->SetWatermarkText('rajsahumahasabha.com');
$mpdf->showWatermarkText = true;
$mpdf->watermarkTextAlpha = 0.1;
//$mpdf->Output("invoice.pdf", 'F');
//$mpdf->Output();
// a random hash will be necessary to send mixed content
$separator = md5(time());
// carriage return type (we use a PHP end of line constant)
$eol = PHP_EOL;
// attachment name
$filename = "invoice.pdf";
// encode data (puts attachment in proper format)
$pdfdoc = $mpdf->Output("", "S");
//$pdf->Output();
$attachment = chunk_split(base64_encode($pdfdoc));
// main header
$headers = "From: ".$from.$eol;
$headers .= "MIME-Version: 1.0".$eol;
$headers .= "Content-Type: multipart/mixed; boundary=\"".$separator."\"";
// no more headers after this, we start the body! //
$body = "--".$separator.$eol;
$body .= "Content-Transfer-Encoding: 7bit".$eol.$eol;
//$body .= "This is a MIME encoded message.".$eol;
// message
$body .= "--".$separator.$eol;
$body .= "Content-Type: text/html; charset=\"iso-8859-1\"".$eol;
$body .= "Content-Transfer-Encoding: 8bit".$eol.$eol;
$body .= $message.$eol;
// attachment
$body .= "--".$separator.$eol;
$body .= "Content-Type: application/octet-stream; name=\"".$filename."\"".$eol;
$body .= "Content-Transfer-Encoding: base64".$eol;
$body .= "Content-Disposition: attachment".$eol.$eol;
$body .= $attachment.$eol;
$body .= "--".$separator."--";
// send message
mail($to, $subject, $body, $headers);
exit;
?>