MailTransport.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. /**
  3. * Send mail using mail() function
  4. *
  5. * PHP 5
  6. *
  7. * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  8. * Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
  9. *
  10. * Licensed under The MIT License
  11. * Redistributions of files must retain the above copyright notice.
  12. *
  13. * @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
  14. * @link http://cakephp.org CakePHP(tm) Project
  15. * @package Cake.Network.Email
  16. * @since CakePHP(tm) v 2.0.0
  17. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  18. */
  19. /**
  20. * Mail class
  21. *
  22. * @package Cake.Network.Email
  23. */
  24. class MailTransport extends AbstractTransport {
  25. /**
  26. * Send mail
  27. *
  28. * @param CakeEmail $email CakeEmail
  29. * @return array
  30. */
  31. public function send(CakeEmail $email) {
  32. $eol = PHP_EOL;
  33. if (isset($this->_config['eol'])) {
  34. $eol = $this->_config['eol'];
  35. }
  36. $headers = $email->getHeaders(array('from', 'sender', 'replyTo', 'readReceipt', 'returnPath', 'to', 'cc', 'bcc'));
  37. $to = $headers['To'];
  38. unset($headers['To']);
  39. $headers = $this->_headersToString($headers, $eol);
  40. $message = implode($eol, $email->message());
  41. if (ini_get('safe_mode') || !isset($this->_config['additionalParameters'])) {
  42. if (!@mail($to, $email->subject(), $message, $headers)) {
  43. throw new SocketException(__d('cake_dev', 'Could not send email.'));
  44. }
  45. } elseif (!@mail($to, $email->subject(), $message, $headers, $this->_config['additionalParameters'])) {
  46. throw new SocketException(__d('cake_dev', 'Could not send email.'));
  47. }
  48. return array('headers' => $headers, 'message' => $message);
  49. }
  50. }