ImtMail.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. class ImtMail
  3. {
  4. function ImtMail()
  5. {
  6. }
  7. public static function sendMail( $to , $from, $reply, $subject, $message, $lang = 'fr', $contentName = null, $contentType = null, $content = null )
  8. {
  9. $boundaries = "_parties_".md5(uniqid (rand()));
  10. $to = "\"$to\" <$to>";
  11. $mime = "Date: ".date("D, j M Y G:i:s O")."\r\n";
  12. $mime .= "MIME-Version: 1.0\r\n";
  13. $mime .= "Content-Type: multipart/alternative;\r\n";
  14. $mime .= "\tboundary=\"$boundaries\"\r\n\r\n";
  15. if ($lang == 'fr' || $lang == 'FR')
  16. $mimeTxt = 'Ce message est au format MIME.';
  17. else
  18. $mimeTxt = 'This message is in MIME format.';
  19. $body = $mimeTxt . "\r\n\r\n" . "--" . $boundaries . "\r\n";
  20. $body .= "Content-Type: text/plain;\r\n";
  21. $body .= "\tcharset=\"iso-8859-1\"\r\n";
  22. $body .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
  23. $body .= $message . "\r\n";
  24. $body .= "--" . $boundaries . "\r\n";
  25. $body .= "Content-Type: text/html;\r\n";
  26. $body .= "\tcharset=\"iso-8859-1\"\r\n";
  27. $body .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
  28. $body .= $message . "\r\n";
  29. if ($contentName)
  30. {
  31. $attachment = "--" . $boundaries . "\r\n";
  32. $attachment .= "Content-Type: \"$contentType\"; name=\"$contentName\"\r\n";
  33. $attachment .= "Content-Transfer-Encoding: base64\r\n";
  34. $attachment .= "Content-Disposition: attachment; filename=\"$contentName\"\r\n\r\n";
  35. $attachment .= chunk_split(base64_encode($content));
  36. $attachment .= "\r\n\r\n\r\n";
  37. $body .= $attachment;
  38. }
  39. $body = $body . "--" . $boundaries . "--\r\n";
  40. $additionnalHeaders = "Reply-to: \"$reply\" <$reply>\r\nFrom: \"$from\" <$from>\r\n".$mime;
  41. return mail($to, $subject, $body, $additionnalHeaders);
  42. }
  43. }
  44. ?>