Posted By


tclancy on 12/15/09

Tagged


Statistics


Viewed 813 times
Favorited by 0 user(s)

Debug Mail Wrapper Class


/ Published in: PHP
Save to your folder(s)

Just a simple wrapper class that makes sure mail doesn't get sent out when the constant DEBUG_MODE is set to true


Copy this code and paste it in your HTML
  1. <?
  2. class SystemEmail
  3. {
  4. var $_to;
  5. var $_subject;
  6. var $_message;
  7. var $_additional_headers = array();
  8.  
  9. function SystemEmail($to, $subject, $message, $from = false)
  10. {
  11. $this->_to = $to;
  12. $this->_subject = $subject;
  13. $this->_message = $message;
  14.  
  15. if ($from)
  16. {
  17. $this->_additional_headers[] = $from;
  18. }
  19. }
  20.  
  21. function set_html()
  22. {
  23. $this->_additional_headers[] = 'MIME-Version: 1.0' . "
  24. ";
  25. $this->_additional_headers[] = 'Content-type: text/html; charset=iso-8859-1' . "
  26. ";
  27. }
  28.  
  29. function send()
  30. {
  31. $headers = "";
  32. if (count($this->_additional_headers) > 0)
  33. {
  34. foreach ($this->_additional_headers as $header)
  35. {
  36. $headers .= $header;
  37. }
  38. $headers = substr($headers, 0, strlen($headers)- 2);
  39. }
  40.  
  41. if (DEBUG_MODE)
  42. {
  43. $this->_message = sprintf("Originally sent to: %s\n\n%s", $this->_to, $this->_message);
  44. $this->_to = ADMIN_EMAIL;
  45. }
  46. @mail($this->_to, $this->_subject, $this->_message, $headers);
  47. }
  48. }
  49. ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.