Guest User

Untitled

a guest
Apr 22nd, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.86 KB | None | 0 0
  1. <?php #-*- coding: utf-8 -*-
  2.  
  3.  
  4.  
  5. /***
  6. *
  7. * @return bool true if email sent, false otherwise
  8. */
  9. function email($to, $from, $subject, $html, $attachments=array(),
  10. $bcc=false, $reply=false )
  11. {
  12. foreach(array('to','bcc','from','reply','subject') as $varname)
  13. {
  14. /**
  15. * remove dangerous chars for headers from a string( \n \l \r )
  16. */
  17. $$varname = strtr($$varname,
  18. array("\n" => '',"\l" => '',"\r" => ''));
  19. }
  20.  
  21. /*
  22. Generate boundary & headers
  23. */
  24. $reply = $reply ? $reply : $from;
  25. $text = strip_tags($html);
  26.  
  27. $headers = array();
  28. $headers[] = "X-Priority: 1 (Higuest)";
  29. $headers[] = "X-MSMail-Priority: High";
  30. $headers[] = "Importance: High";
  31. $headers[] = 'From: '.$from;
  32. $headers[] = 'Return-Path: '.$reply;
  33. if($bcc) $headers[] = 'Bcc: '.$reply;
  34. $headers[] = 'MIME-Version: 1.0';
  35. $msg_boundary = '-------=part' . md5(uniqid(mt_rand()));
  36. $headers[] = 'Content-Type: multipart/mixed; boundary="'.$msg_boundary.'"';
  37. $headers[] = 'This is a multi-part message in MIME format.';
  38. $headers[] = '--'.$msg_boundary;
  39.  
  40. /*
  41. text
  42. */
  43.  
  44. $boundary = '-------=part' . md5(uniqid(mt_rand()));
  45. $headers[] = 'Content-Type: multipart/alternative; boundary="'.$boundary.'"';
  46.  
  47. $headers[] = '--'.$boundary;
  48. $headers[] = 'Content-Type: text/plain; charset="utf-8"';
  49. $headers[] = 'Content-Transfer-Encoding: quoted-printable';
  50. $headers[] = 'Content-Disposition: inline';
  51. $headers[] = "";
  52. $headers[] = $text;
  53. $headers[] = "";
  54.  
  55. /*
  56. html part
  57. */
  58. $headers[] = '--'.$boundary;
  59. $headers[] = 'Content-Type: text/html; charset="utf-8"';
  60. $headers[] = 'Content-Transfer-Encoding: quoted-printable';
  61. $headers[] = 'Content-Disposition: inline';
  62. $headers[] = "";
  63. $headers[] = $html;
  64. $headers[] = "";
  65.  
  66. $headers[] = '';
  67. $headers[] = '--'.$boundary.'--';
  68. $headers[] = '';
  69.  
  70. /*
  71. handle attachments
  72. */
  73. if( !is_array($attachments) )
  74. $attachments = array();
  75. foreach( $attachments as $file )
  76. {
  77. if(!file_exists($file))
  78. trigger_error('[email] file '.$file.' does not exits');
  79. $mimetype = mimetype($file);
  80. $name = urlize(basename($file));
  81.  
  82. $headers[] = '--'.$msg_boundary;
  83. $headers[] = 'Content-Type: '.$mimetype.'; name="'.$name.'"';
  84. $headers[] = 'Content-Transfer-Encoding: base64';
  85. $headers[] = 'Content-Disposition:inline; '
  86. .'filename="'.$name.'"';
  87.  
  88. $headers[] = '';
  89. $headers[] = chunk_split(base64_encode(file_get_contents($file)));
  90. $headers[] = '';
  91. }
  92. $headers[] = '';
  93. $headers[] = '--'.$msg_boundary.'--';
  94. $headers[] = '';
  95.  
  96. return mail($to,$subject,'',join("\n",$headers) );
  97. }
  98. //- email()
Add Comment
Please, Sign In to add comment