Php email sending function, supporting html and plain text
- Function send_mail ($ emailaddress, $ fromaddress, $ namefrom, $ emailsubject, $ body)
- {
- $ Eol = "\ n ";
- $ Mime_boundary = md5 (time ());
-
- # Common Headers
- $ Headers. = "From: $ namefrom <$ fromaddress>". $ eol;
- $ Headers. = "Reply-To: $ namefrom <$ fromaddress>". $ eol;
- $ Headers. = "Return-Path: $ namefrom <$ fromaddress>". $ eol;
- // These two to set reply address
- $ Headers. = "Message-ID: <". $ now. "TheSystem @". $ _ SERVER ['server _ name']. ">". $ eol;
- $ Headers. = "X-Mailer: PHP v". phpversion (). $ eol; // These two to help avoid spam-filters
-
- # Boundry for marking the split & Multitype Headers
- $ Headers. = 'Mime-Version: 1.0 '. $ eol;
- $ Headers. = "Content-Type: multipart/related; boundary = \" ". $ mime_boundary." \ "". $ eol;
-
- $ Msg = "";
-
-
- # Setup for text OR html
- $ Msg. = "Content-Type: multipart/alternative". $ eol;
-
- # Text Version
- $ Msg. = "--". $ mime_boundary. $ eol;
- $ Msg. = "Content-Type: text/plain; charset = iso-8859-1". $ eol;
- $ Msg. = "Content-Transfer-Encoding: 8bit". $ eol;
- $ Msg. = strip_tags (str_replace ("
"," \ N ", $ body). $ eol. $ eol;
-
- # HTML Version
- $ Msg. = "--". $ mime_boundary. $ eol;
- $ Msg. = "Content-Type: text/html; charset = iso-8859-1". $ eol;
- $ Msg. = "Content-Transfer-Encoding: 8bit". $ eol;
- $ Msg. = $ body. $ eol. $ eol;
-
- # Finished
- $ Msg. = "--". $ mime_boundary. "--". $ eol. $ eol; // finish with two eol's for better security. see Injection.
-
- # SEND THE EMAIL
- // Ini_set (sendmail_from, $ fromaddress); // the INI lines are to force the From Address to be used!
- Mail ($ emailaddress, $ emailsubject, $ msg, $ headers );
-
- // Ini_restore (sendmail_from );
- // Echo "mail send ";
- Return 1;
- }
-
- ?>
|
Send email, php, html