Source for file SendmailMailer.php

Documentation is available at SendmailMailer.php

  1. 1: <?php
  2. 2:  
  3. 3: /**
  4. 4:  * Nette Framework
  5. 5:  *
  6. 6:  * Copyright (c) 2004, 2009 David Grudl (http://davidgrudl.com)
  7. 7:  *
  8. 8:  * This source file is subject to the "Nette license" that is bundled
  9. 9:  * with this package in the file license.txt.
  10. 10:  *
  11. 11:  * For more information please see http://nettephp.com
  12. 12:  *
  13. 13:  * @copyright  Copyright (c) 2004, 2009 David Grudl
  14. 14:  * @license    http://nettephp.com/license  Nette license
  15. 15:  * @link       http://nettephp.com
  16. 16:  * @category   Nette
  17. 17:  * @package    Nette\Mail
  18. 18:  */
  19. 19:  
  20. 20:  
  21. 21:  
  22. 22: require_once dirname(__FILE__'/../Object.php';
  23. 23:  
  24. 24:  
  25. 25:  
  26. 26: /**
  27. 27:  * Sends e-mails via the PHP internal mail() function.
  28. 28:  *
  29. 29:  * @author     David Grudl
  30. 30:  * @copyright  Copyright (c) 2004, 2009 David Grudl
  31. 31:  * @package    Nette\Mail
  32. 32:  */
  33. 33: class SendmailMailer extends Object implements IMailer
  34. 34: {
  35. 35:  
  36. 36:     /**
  37. 37:      * Sends e-mail.
  38. 38:      * @param  Mail 
  39. 39:      * @return void 
  40. 40:      */
  41. 41:     public function send(Mail $mail)
  42. 42:     {
  43. 43:         $tmp clone $mail;
  44. 44:         $tmp->setHeader('Subject'NULL);
  45. 45:         $tmp->setHeader('To'NULL);
  46. 46:  
  47. 47:         $parts explode(Mail::EOL Mail::EOL$tmp->generateMessage()2);
  48. 48:         $linux strncasecmp(PHP_OS'win'3);
  49. 49:  
  50. 50:         Tools::tryError();
  51. 51:         $res mail(
  52. 52:             $mail->getEncodedHeader('To'),
  53. 53:             $mail->getEncodedHeader('Subject'),
  54. 54:             $linux str_replace(Mail::EOL"\n"$parts[1]$parts[1],
  55. 55:             $linux str_replace(Mail::EOL"\n"$parts[0]$parts[0]
  56. 56:         );
  57. 57:  
  58. 58:         if (Tools::catchError($msg)) {
  59. 59:             throw new InvalidStateException($msg);
  60. 60:  
  61. 61:         elseif (!$res{
  62. 62:             throw new InvalidStateException('Unable to send email.');
  63. 63:         }
  64. 64:     }
  65. 65:  
  66. 66: }