Guest User

Untitled

a guest
Jun 18th, 2018
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.57 KB | None | 0 0
  1. <?php
  2.  
  3. /*
  4. mail_advanced(
  5. array("Sender Name" => "sender@email.com"),
  6. array("user1@email.com","user2@gmail.com","user3@email.com"),
  7. "This is a subject",
  8. "This is an email body"
  9. );
  10.  
  11. mail_attachments(
  12. array("Sender Name" => "sender@email.com"),
  13. array("user1@email.com","user2@gmail.com","user3@email.com"),
  14. "This is a subject",
  15. "This is an email body",
  16. array(
  17. "File1" => "/path/to/file1.ext",
  18. "File2" => "/path/to/file2.ext"
  19. )
  20. );
  21. */
  22.  
  23. function mail_advanced($fromArray, $toArray, $subject, $message)
  24. {
  25. $to = implode(", ", $toArray);
  26.  
  27. $headers = "";
  28. foreach($fromArray as $key => $value)
  29. {
  30. $headers .= "From: " . $key . " < ".$value." >" . "\r\n";
  31. $headers .= "X-Sender: " . $key . " < " . $value . " >" . "\r\n";
  32. $headers .= "Return-Path: " . $value . "\r\n";
  33. }
  34. $headers .= 'X-Mailer: PHP/' . phpversion() . "\r\n";
  35. $headers .= "X-Priority: 1" . "\r\n";
  36. $headers .= "MIME-Version: 1.0" . "\r\n";
  37. $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
  38.  
  39. if(!mail($to,$subject,$message,$headers))
  40. {
  41. return false;
  42. }
  43.  
  44. return true;
  45. }
  46.  
  47. function mail_attachments($fromArray, $toArray, $subject, $message, $fileArray)
  48. {
  49. $to = implode(", ", $toArray);
  50.  
  51. $semi_rand = md5(time());
  52. $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
  53.  
  54. $headers = "";
  55. foreach($fromArray as $key => $value)
  56. {
  57. $headers .= "From: " . $key . " < ".$value." >" . "\r\n";
  58. $headers .= "X-Sender: " . $key . " < " . $value . " >" . "\r\n";
  59. $headers .= "Return-Path: " . $value . "\r\n";
  60. }
  61.  
  62. $headers .= 'X-Mailer: PHP/' . phpversion() . "\r\n";
  63. $headers .= "X-Priority: 1" . "\r\n";
  64.  
  65. $headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\"";
  66. $message = "--{$mime_boundary}\n" . "Content-Type: text/html; charset=\"UTF-8\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $message . "\n\n";
  67.  
  68. foreach($fileArray as $filename => $filepath)
  69. {
  70. if(is_file($filepath))
  71. {
  72. $message .= "--{$mime_boundary}\n";
  73. $fp = @fopen($filepath,"rb");
  74. $filesize = @filesize($filepath);
  75. $data = @fread($fp,$filesize);
  76. @fclose($fp);
  77. $data = chunk_split(base64_encode($data));
  78. $message .= "Content-Type: application/octet-stream; name=\"".$filename."\"\n";
  79. $message .= "Content-Description: ".$filename."\n";
  80. $message .= "Content-Disposition: attachment;\n" . " filename=\"".$filename."\"; size=".$filesize.";\n";
  81. $message .= "Content-Transfer-Encoding: base64\n\n" . $data . "\n\n";
  82. }
  83. }
  84.  
  85. $message .= "--{$mime_boundary}--";
  86.  
  87. if(!mail($to,$subject,$message,$headers))
  88. {
  89. return false;
  90. }
  91.  
  92. return true;
  93. }
  94.  
  95. ?>
Add Comment
Please, Sign In to add comment