PageRenderTime 1807ms CodeModel.GetById 85ms RepoModel.GetById 40ms app.codeStats 0ms

/framework/experimental/mail/Mail.php

http://zoop.googlecode.com/
PHP | 73 lines | 58 code | 13 blank | 2 comment | 4 complexity | dda728d6f5f1a44a7f2701c0217c952f MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.1
  1. <?php
  2. // these should really call a common function
  3. // or there shoudl be just one function with another paramater or something
  4. class Mail
  5. {
  6. function text($to, $toName, $from, $fromName, $subject, $body)
  7. {
  8. $mail = new mailer();
  9. if( defined('mail_from') )
  10. {
  11. $mail->From = mail_from;
  12. $mail->AddReplyTo($from, $fromName);
  13. }
  14. else
  15. {
  16. $mail->From = $from;
  17. }
  18. $mail->FromName = $fromName;
  19. $mail->AddAddress($to, $toName);
  20. $mail->IsHTML(false);
  21. $mail->Subject = $subject;
  22. $mail->Body = $body;
  23. $result = $mail->Send();
  24. if(!$result)
  25. trigger_error("Message could not be sent. Mailer Error: " . $mail->ErrorInfo);
  26. }
  27. function html($to, $toName, $from, $fromName, $subject, $body)
  28. {
  29. $mail = new mailer();
  30. if( defined('mail_from') )
  31. {
  32. $mail->From = mail_from;
  33. $mail->AddReplyTo($from, $fromName);
  34. }
  35. else
  36. {
  37. $mail->From = $from;
  38. }
  39. $mail->FromName = $fromName;
  40. $mail->IsHTML(true);
  41. $mail->Subject = $subject;
  42. $mail->Body = $body;
  43. switch(gettype($to))
  44. {
  45. case 'string':
  46. $mail->AddAddress($to, $toName);
  47. break;
  48. case 'array':
  49. foreach($to as $toKey => $thisTo)
  50. $mail->AddAddress($thisTo, $toName[$toKey]);
  51. break;
  52. default:
  53. trigger_error('invalid type for address field');
  54. }
  55. if(!$mail->Send())
  56. {
  57. trigger_error("Message could not be sent. Mailer Error: " . $mail->ErrorInfo);
  58. }
  59. }
  60. }