Posted By

sybrex on 10/08/10


Tagged

mail encoding


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

sybrex
jplr


Mime mail


 / Published in: PHP
 

  1. function mime_mail($name_from, // Sender name
  2. $email_from, // Sender email
  3. $name_to, // Receiver name
  4. $email_to, // Receiver email
  5. $data_charset, // data encoding
  6. $send_charset, // letter encoding
  7. $subject, // email subject
  8. $body // email text
  9. )
  10. {
  11. $to = mime_header_encode($name_to, $data_charset, $send_charset) . ' <' . $email_to . '>';
  12. $subject = mime_header_encode($subject, $data_charset, $send_charset);
  13. $from = mime_header_encode($name_from, $data_charset, $send_charset) . ' <' . $email_from . '>';
  14. if ($data_charset != $send_charset)
  15. {
  16. $body = iconv($data_charset, $send_charset, $body);
  17. }
  18. $headers = "From: $from
  19. ";
  20. $headers .= "Content-type: text/html; charset=$send_charset
  21. ";
  22.  
  23. return mail($to, $subject, $body, $headers);
  24. }
  25.  
  26. function mime_header_encode($str, $data_charset, $send_charset)
  27. {
  28. if ($data_charset != $send_charset)
  29. {
  30. $str = iconv($data_charset, $send_charset, $str);
  31. }
  32. return '=?' . $send_charset . '?B?' . base64_encode($str) . '?=';
  33. }

Report this snippet  

You need to login to post a comment.