Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $view_html = FALSE;
- $view_pdf = FALSE;
- error_reporting(~E_STRICT);
- require_once( "vender/dompdf/dompdf/dompdf_config.inc.php" );
- require_once( "vender/swift/lib/swift_required.php" );
- function renderTemplate( $file, array $scope_array )
- {
- extract( $scope_array );
- ob_start();
- $old = error_reporting();
- error_reporting( 0 );
- require( $file );
- error_reporting( $old );
- $template_html = ob_get_contents();
- ob_end_clean();
- return $template_html;
- }
- $template_html = renderTemplate( "template.php", $_GET );
- if( $view_html ) {
- print $template_html;
- exit();
- }
- $dompdf = new DOMPDF();
- $dompdf->load_html( $template_html );
- $dompdf->render();
- $pdf_data = $dompdf->output();
- //debugging
- if( $view_pdf ) {
- header( "Content-Type: application/pdf" );
- print $pdf_data;
- exit();
- }
- $from_info = array(
- "email" => "softwareelves@gmail.com",
- "host" => "smtp.gmail.com",
- "port" => 465,
- "use_ssl" => TRUE,
- "username" => "softwareelves@gmail.com",
- "password" => "*PASSWORD*"
- );
- $to_array = array( "softwareelves@gmail.com" );
- $subject = "SUBJECT!";
- $body = <<<EOS
- BODY BODY BODY
- EOS;
- $content_type = "text/html";
- $attachment_file_name = "Results.pdf";
- $transport = Swift_SmtpTransport::newInstance( $from_info["host"], $from_info["port"] )
- ->setUsername( $from_info["username"] )
- ->setPassword( $from_info["password"] );
- if( $from_info["use_ssl"] ) {
- $transport->setEncryption( "ssl" );
- }
- $mailer = Swift_Mailer::newInstance( $transport );
- $message = Swift_Message::newInstance( $subject, $body, $content_type );
- $message->setFrom( $from_info["email"] );
- $message->setTo( $to_array );
- $message->attach( new Swift_Attachment( $pdf_data, $attachment_file_name, "application/pdf" ) );
- $result = $mailer->send( $message );
- if( $result !== ( count( $to_array ) ) ) {
- throw new Exception( "Failed to send to all emails" );
- }
- ?>
Add Comment
Please, Sign In to add comment