首頁  >  文章  >  後端開發  >  php發送郵件函數,支援html和普通文本

php發送郵件函數,支援html和普通文本

WBOY
WBOY原創
2016-07-25 08:43:09899瀏覽
  1. function send_mail($emailaddress, $fromaddress, $namefrom, $emailsubject, $body)
  2. {
  3. $eol="n";
  4. $mime_boundary=md5(time());
  5. # Common Headers
  6. $headers .= "From: $namefrom <$fromaddress>".$eol;
  7. $headers .= "Reply-To: $namefrom <$fromaddress>".$eol;
  8. $headers .= "Return-Path: $namefrom <$fromaddress>".$eol;
  9. // these two to set reply address
  10. $headers .= "Message-ID: <".$now." TheSystem@".$_SERVER['SERVER_NAME'].">".$eol;
  11. $headers .= "X-Mailer: PHP v".phpversion().$eol; // These two to help avoid spam-filters
  12. # Boundry for marking the split & Multitype Headers
  13. $headers .= 'MIME-Version: 1.0'.$eol;
  14. $headers .= "Content-Type: multipart/related; boundary="".$mime_boundary.""".$eol;
  15. $msg = "";
  16. # Setup for text OR html
  17. $msg .= "Content-Type: multipart/alternative".$eol;
  18. # Text Version
  19. $msg .= "--".$mime_boundary.$eol;
  20. $msg .= "Content-Type: text/plain; charset=iso-8859-1".$eol;
  21. $msg .= "Content-Transfer-Encoding: 8bit".$eol;
  22. $msg .= strip_tags(str_replace("
    ", "n", $body)).$eol.$eol;
  23. # HTML Version
  24. $msg .= "--".$mime_boundary.$eol;
  25. $msg .= "Content-Type: text/html; charset=iso-8859-1".$eol;
  26. $msg .= "Content-Transfer-Encoding: 8bit".$eol;
  27. $msg .= $body.$eol.$eol;
  28. # Finished
  29. $msg .= "--".$mime_boundary."--".$eol.$eol; // finish with two eol's for better security. see Injection.
  30. # SEND THE EMAIL
  31. // ini_set(sendmail_from,$fromaddress); // the INI lines are to force the From Address to be used !
  32. mail($emailaddress, $emailsubject, $msg, $headers);
  33. // ini_restore(sendmail_from);
  34. // echo "mail send";
  35. return 1;
  36. }
  37. ?>
复制代码

寄信, php, html


陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn