Posted By

llbbl on 05/25/07


Tagged

email php textmate mail txt html


Versions (?)

Who likes this?

14 people have marked this snippet as a favorite

luman
hudge
skywalker
JimiJay
chucktrukk
oli964
mrjthethird
traktorist
Jdub7
nb109
benvds
tapdrup
bobbym245
mecha


Send Mail Function (HTML TXT)


 / Published in: PHP
 

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

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: carouna on October 29, 2010

Hi there, This document is really helped in my case. Million of thanks for the code. Good job.

Thanks Carouna.

You need to login to post a comment.