Php email sending function, supporting html and plain text

Source: Internet
Author: User
Tags eol php email
Php email sending function, supporting html and plain text

  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. ?>


Send email, php, html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.