Advertisement
Guest User

Untitled

a guest
Jul 16th, 2019
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 KB | None | 0 0
  1. <?php require_once ("dompdf/dompdf_config.inc.php");
  2.  
  3.  
  4. $dompdf= new DOMPDF();
  5. $dompdf->load_html(ob_get_clean());
  6. $dompdf->render();
  7. $pdf=$dompdf->output();
  8. $filename= $f['cod_cotizacion'].'-'.$f['nombreEmpresa'].'.pdf';
  9.  
  10. $dompdf->stream($filename,array("Attachment"=> 0));
  11. $dompdf->setPaper('A4','landscape');
  12.  
  13.  
  14. $body="Hola buena tarde";
  15. $mm = new Mail_mime("n");
  16. $mm->setTxtBody($body);
  17. $mm->addAttachment($pdf,'application/pdf','output.pdf', false);
  18.  
  19. $body = $mm->get();
  20. $headers = $mm->headers(array('From'=>$from,'Subject'=>$subject));
  21.  
  22. $mail =& Mail::factory('gabox-@hotmail.com');
  23. if($mail->send($to,$headers,$body)){
  24. echo "Se envio";
  25. }
  26.  
  27.  
  28. ?>
  29.  
  30. <?php
  31. //recipient
  32. $to = 'recipient@example.com';
  33.  
  34. //sender
  35. $from = 'sender@example.com';
  36. $fromName = 'CodexWorld';
  37.  
  38. //email subject
  39. $subject = 'PHP Email with Attachment by CodexWorld';
  40.  
  41. //attachment file path
  42. $file = "codexworld.pdf";
  43.  
  44. //email body content
  45. $htmlContent = '<h1>PHP Email with Attachment by CodexWorld</h1>
  46. <p>This email has sent from PHP script with attachment.</p>';
  47.  
  48. //header for sender info
  49. $headers = "From: $fromName"." <".$from.">";
  50.  
  51. //boundary
  52. $semi_rand = md5(time());
  53. $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
  54.  
  55. //headers for attachment
  56. $headers .= "nMIME-Version: 1.0n" . "Content-Type: multipart/mixed;n" . " boundary="{$mime_boundary}"";
  57.  
  58. //multipart boundary
  59. $message = "--{$mime_boundary}n" . "Content-Type: text/html; charset="UTF-8"n" .
  60. "Content-Transfer-Encoding: 7bitnn" . $htmlContent . "nn";
  61.  
  62. //preparing attachment
  63. if(!empty($file) > 0){
  64. if(is_file($file)){
  65. $message .= "--{$mime_boundary}n";
  66. $fp = @fopen($file,"rb");
  67. $data = @fread($fp,filesize($file));
  68.  
  69. @fclose($fp);
  70. $data = chunk_split(base64_encode($data));
  71. $message .= "Content-Type: application/octet-stream; name="".basename($file).""n" .
  72. "Content-Description: ".basename($file)."n" .
  73. "Content-Disposition: attachment;n" . " filename="".basename($file).""; size=".filesize($file).";n" .
  74. "Content-Transfer-Encoding: base64nn" . $data . "nn";
  75. }
  76. }
  77. $message .= "--{$mime_boundary}--";
  78. $returnpath = "-f" . $from;
  79.  
  80. //send email
  81. $mail = @mail($to, $subject, $message, $headers, $returnpath);
  82.  
  83. //email sending status
  84. echo $mail?"<h1>Mail sent.</h1>":"<h1>Mail sending failed.</h1>";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement