Blame view
sendEstimateEmail.php
3.27 KB
|
670b6d6f8
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
<?php
// include autoloader
require_once 'dompdf/autoload.inc.php';
$reEmail = $_POST['reEmail'];
if (isset($_POST["reEmail"]) && !empty($_POST["reEmail"])){
$reEmail = filter_var($reEmail, FILTER_SANITIZE_EMAIL);
}
else{
exit("Must input the received email address");
}
$htmlData = $_POST['htmlData'];
$htmlData =
'<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/><style>font-family: ms-gothic, DejaVu Sans, serif;</style></head><body>'.$htmlData.'</body></html>';
// reference the Dompdf namespace
use Dompdf\Dompdf;
// instantiate and use the dompdf class
$dompdf = new Dompdf();
$dompdf->loadHtml($htmlData);
//$dompdf->set_option('isFontSubsettingEnabled', true);
// (Optional) Setup the paper size and orientation
// Defautl DPi 96. So A4 dimension will 794x1123
$dompdf->setPaper('A4', 'landscape');
// Render the HTML as PDF
$dompdf->render();
// Output the generated PDF to Browser
//$dompdf->stream();
// Output the generated PDF (1 = download and 0 = preview)
//$dompdf->stream("codex",array("Attachment"=>0));
$output = $dompdf->output();
require 'PHPMailer/PHPMailerAutoload.php';
//SMTP time zone set
date_default_timezone_set('Etc/UTC');
///
///Send mail by using gmail smtp
///
//Create a new PHPMailer instance
$mail = new PHPMailer;
//Tell PHPMailer to use SMTP
$mail->isSMTP();
//Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
$mail->SMTPDebug = 0;
//Ask for HTML-friendly debug output
$mail->Debugoutput = 'html';
//Set the hostname of the mail server
$mail->Host = 'smtp.gmail.com';
// use
// $mail->Host = gethostbyname('smtp.gmail.com');
// if your network does not support SMTP over IPv6
//Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
$mail->Port = 587;
//Set the encryption system to use - ssl (deprecated) or tls
$mail->SMTPSecure = 'tls';
//Whether to use SMTP authentication
$mail->SMTPAuth = true;
//Username to use for SMTP authentication - use full email address for gmail
$mail->Username = "naitce@gmail.com";
//Password to use for SMTP authentication
$mail->Password = "Xinchaocacban";
//Set who the message is to be sent from
$mail->setFrom('noreply@timesfun.net', '3D House');
//Set an alternative reply-to address
//$mail->addReplyTo('replyto@example.com', 'First Last');
//Set who the message is to be sent to
$mail->addAddress($reEmail, '');
//Set the subject line
$mail->Subject = 'An estimation table from 3D House';
//Read an HTML message body from an external file, convert referenced images to embedded,
//convert HTML into a basic plain-text alternative body
$mail->msgHTML(file_get_contents('mailContent.html'), dirname(__FILE__));
//Replace the plain text body with one created manually
$mail->AltBody = 'Please get file in attachment';
//Attach an image file
$mail->AddStringAttachment($output, '3DHouse-Estimation.pdf', 'base64', 'application/pdf');
//$mail->addAttachment($output,'application/pdf','3DHouse-Estimation.pdf', false);
//$mail->addAttachment('images/phpmailer_mini.png');
//send the message, check for errors
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Email is sent!";
}
?>
|