2011-03-01 16:47:05 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Send mail using mail() function
|
|
|
|
*
|
|
|
|
* PHP 5
|
|
|
|
*
|
|
|
|
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
2012-03-13 02:46:46 +00:00
|
|
|
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2011-03-01 16:47:05 +00:00
|
|
|
*
|
|
|
|
* Licensed under The MIT License
|
|
|
|
* Redistributions of files must retain the above copyright notice.
|
|
|
|
*
|
2012-03-13 02:46:46 +00:00
|
|
|
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2011-03-01 16:47:05 +00:00
|
|
|
* @link http://cakephp.org CakePHP(tm) Project
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Network.Email
|
2011-03-01 16:47:05 +00:00
|
|
|
* @since CakePHP(tm) v 2.0.0
|
|
|
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2011-12-08 15:35:02 +00:00
|
|
|
* Send mail using mail() function
|
2011-03-01 16:47:05 +00:00
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Network.Email
|
2011-03-01 16:47:05 +00:00
|
|
|
*/
|
|
|
|
class MailTransport extends AbstractTransport {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Send mail
|
|
|
|
*
|
2011-07-29 03:56:10 +00:00
|
|
|
* @param CakeEmail $email CakeEmail
|
2011-08-26 00:31:18 +00:00
|
|
|
* @return array
|
2012-03-04 16:18:20 +00:00
|
|
|
* @throws SocketException When mail cannot be sent.
|
2011-03-01 16:47:05 +00:00
|
|
|
*/
|
|
|
|
public function send(CakeEmail $email) {
|
2011-04-13 03:34:23 +00:00
|
|
|
$eol = PHP_EOL;
|
|
|
|
if (isset($this->_config['eol'])) {
|
|
|
|
$eol = $this->_config['eol'];
|
2011-03-01 16:47:05 +00:00
|
|
|
}
|
2011-08-26 00:31:18 +00:00
|
|
|
$headers = $email->getHeaders(array('from', 'sender', 'replyTo', 'readReceipt', 'returnPath', 'to', 'cc', 'bcc'));
|
2011-03-01 18:24:38 +00:00
|
|
|
$to = $headers['To'];
|
|
|
|
unset($headers['To']);
|
2011-08-26 00:31:18 +00:00
|
|
|
$headers = $this->_headersToString($headers, $eol);
|
2011-04-04 03:37:29 +00:00
|
|
|
$message = implode($eol, $email->message());
|
2012-09-09 13:32:50 +00:00
|
|
|
|
|
|
|
$params = null;
|
|
|
|
if (!ini_get('safe_mode')) {
|
|
|
|
$params = isset($this->_config['additionalParameters']) ? $this->_config['additionalParameters'] : null;
|
2011-08-26 00:31:18 +00:00
|
|
|
}
|
2012-09-09 13:32:50 +00:00
|
|
|
|
|
|
|
$this->_mail($to, $email->subject(), $message, $headers, $params);
|
2011-08-26 00:31:18 +00:00
|
|
|
return array('headers' => $headers, 'message' => $message);
|
2011-03-01 16:47:05 +00:00
|
|
|
}
|
|
|
|
|
2012-09-09 13:32:50 +00:00
|
|
|
/**
|
|
|
|
* Wraps internal function mail() and throws exception instead of errors if anything goes wrong
|
|
|
|
*
|
|
|
|
* @param string $to email's recipient
|
|
|
|
* @param string $subject email's subject
|
|
|
|
* @param string $message email's body
|
|
|
|
* @param string $headers email's custom headers
|
|
|
|
* @param string $params additional params for sending email
|
|
|
|
* @throws SocketException if mail could not be sent
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
protected function _mail($to, $subject, $message, $headers, $params = null) {
|
2012-11-14 09:00:15 +00:00
|
|
|
//@codingStandardsIgnoreStart
|
2012-09-09 13:32:50 +00:00
|
|
|
if (!@mail($to, $subject, $message, $headers, $params)) {
|
|
|
|
throw new SocketException(__d('cake_dev', 'Could not send email.'));
|
|
|
|
}
|
2012-11-14 09:00:15 +00:00
|
|
|
//@codingStandardsIgnoreEnd
|
2012-09-09 13:32:50 +00:00
|
|
|
}
|
|
|
|
|
2011-03-01 16:47:05 +00:00
|
|
|
}
|