1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17:
18: App::uses('AbstractTransport', 'Network/Email');
19:
20: 21: 22: 23: 24:
25: class MailTransport extends AbstractTransport {
26:
27: 28: 29: 30: 31: 32: 33:
34: public function send(CakeEmail $email) {
35: $eol = PHP_EOL;
36: if (isset($this->_config['eol'])) {
37: $eol = $this->_config['eol'];
38: }
39: $headers = $email->getHeaders(array('from', 'sender', 'replyTo', 'readReceipt', 'returnPath', 'to', 'cc', 'bcc'));
40: $to = $headers['To'];
41: unset($headers['To']);
42: foreach ($headers as $key => $header) {
43: $headers[$key] = str_replace(array("\r", "\n"), '', $header);
44: }
45: $headers = $this->_headersToString($headers, $eol);
46: $subject = str_replace(array("\r", "\n"), '', $email->subject());
47: $to = str_replace(array("\r", "\n"), '', $to);
48:
49: $message = implode($eol, $email->message());
50:
51: $params = isset($this->_config['additionalParameters']) ? $this->_config['additionalParameters'] : null;
52: $this->_mail($to, $subject, $message, $headers, $params);
53:
54: $headers .= $eol . 'Subject: ' . $subject;
55: $headers .= $eol . 'To: ' . $to;
56: return array('headers' => $headers, 'message' => $message);
57: }
58:
59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69:
70: protected function _mail($to, $subject, $message, $headers, $params = null) {
71: if (ini_get('safe_mode')) {
72:
73: if (!@mail($to, $subject, $message, $headers)) {
74: $error = error_get_last();
75: $msg = 'Could not send email: ' . (isset($error['message']) ? $error['message'] : 'unknown');
76: throw new SocketException($msg);
77: }
78: } elseif (!@mail($to, $subject, $message, $headers, $params)) {
79: $error = error_get_last();
80: $msg = 'Could not send email: ' . (isset($error['message']) ? $error['message'] : 'unknown');
81:
82: throw new SocketException($msg);
83: }
84: }
85:
86: }
87: