EmailLib.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628
  1. <?php
  2. App::uses('CakeEmail', 'Network/Email');
  3. App::uses('CakeLog', 'Log');
  4. if (!defined('BR')) {
  5. define('BR', '<br />');
  6. }
  7. /**
  8. * Convenience class for internal mailer.
  9. * Adds some nice features and fixes some bugs:
  10. * - enbale embedded images in html mails
  11. * - allow setting domain for CLI environment
  12. * - allow setting private config data from configs (instead of email.php)
  13. * - enable easier attachment adding
  14. * - extensive logging and error tracing
  15. *
  16. * TODO: cleanup and more tests
  17. *
  18. * @author Mark Scherer
  19. * @license MIT
  20. * 2012-03-30 ms
  21. */
  22. class EmailLib extends CakeEmail {
  23. /**
  24. * Domain for messageId generation.
  25. * Needs to be manually set for CLI mailing as env('HTTP_HOST') is empty
  26. *
  27. * @var string
  28. */
  29. protected $_domain = null;
  30. protected $_log = null;
  31. protected $_debug = null;
  32. public $error = '';
  33. # for multiple emails, just adjust these "default" values "on the fly"
  34. public $deliveryMethod = 'mail';
  35. public $layout = 'external'; # usually 'external' (internal for admins only)
  36. # with presets, only TO/FROM (depends), subject and message has to be set
  37. public $presets = array(
  38. 'user' => '',
  39. 'admin' => '',
  40. );
  41. public $options = array();
  42. public $complex = null; # if Controller is available, and layout/elements can be switched...
  43. public function __construct($config = null) {
  44. if ($config === null) {
  45. $config = 'default';
  46. }
  47. $this->_domain = env('HTTP_HOST');
  48. if (empty($this->_domain)) {
  49. $this->_domain = php_uname('n');
  50. }
  51. parent::__construct($config);
  52. $this->resetAndSet();
  53. }
  54. /**
  55. * quick way to send emails to admin
  56. * App::uses() + EmailLib::systemEmail()
  57. *
  58. * Note: always go out with default settings (e.g.: SMTP even if debug > 0)
  59. * @return bool $success
  60. * 2011-10-31 ms
  61. */
  62. public static function systemEmail($subject, $message = 'System Email', $transportConfig = null) {
  63. $class = __CLASS__;
  64. $instance = new $class($transportConfig);
  65. $instance->to(Configure::read('Config.admin_email'));
  66. $instance->from(Configure::read('Config.admin_email'));
  67. if ($subject !== null) {
  68. $instance->subject($subject);
  69. }
  70. if (is_array($message)) {
  71. $instance->viewVars($message);
  72. $message = null;
  73. } elseif ($message === null && array_key_exists('message', $config = $instance->config())) {
  74. $message = $config['message'];
  75. }
  76. if (true || $send === true) {
  77. return $instance->send($message);
  78. }
  79. return $instance;
  80. }
  81. public function layout($layout = false) {
  82. if ($layout !== false) {
  83. $this->_layout = $layout;
  84. }
  85. return $this;
  86. }
  87. /**
  88. * @param string $file: absolute path
  89. * @param string $filename (optional)
  90. * 2011-11-02 ms
  91. */
  92. public function addAttachment($file, $name = null) {
  93. if (!empty($name)) {
  94. return $this->addAttachments(array($name=>$file));
  95. }
  96. return $this->addAttachments($file);
  97. }
  98. /**
  99. * @param string $file: absolute path
  100. * @param string $filename (optional)
  101. * @return mixed ressource $EmailLib or string $contentId
  102. * 2011-11-02 ms
  103. */
  104. public function addEmbeddedAttachment($file, $name = null, $contentId = null) {
  105. $fileInfo = array();
  106. $fileInfo['file'] = realpath($file);
  107. $fileInfo['mimetype'] = $this->_getMime($file);
  108. $fileInfo['contentId'] = $contentId ? $contentId : str_replace('-', '', String::uuid()) . '@' . $this->_domain;
  109. if (empty($name)) {
  110. $name = basename($file);
  111. }
  112. $file = array($name=>$fileInfo);
  113. $res = $this->addAttachments($file);
  114. if ($contentId === null) {
  115. return $fileInfo['contentId'];
  116. }
  117. return $res;
  118. }
  119. protected function _getMime($filename) {
  120. if (function_exists('finfo_open')) {
  121. $finfo = finfo_open(FILEINFO_MIME);
  122. $mimetype = finfo_file($finfo, $filename);
  123. finfo_close($finfo);
  124. } else {
  125. //TODO: improve
  126. $ext = pathinfo($filename, PATHINFO_EXTENSION);
  127. switch ($ext) {
  128. case "zip": $mime="application/zip"; break;
  129. case "ez": $mime="application/andrew-inset"; break;
  130. case "hqx": $mime="application/mac-binhex40"; break;
  131. case "cpt": $mime="application/mac-compactpro"; break;
  132. case "doc": $mime="application/msword"; break;
  133. case "bin": $mime="application/octet-stream"; break;
  134. case "dms": $mime="application/octet-stream"; break;
  135. case "lha": $mime="application/octet-stream"; break;
  136. case "lzh": $mime="application/octet-stream"; break;
  137. case "exe": $mime="application/octet-stream"; break;
  138. case "class": $mime="application/octet-stream"; break;
  139. case "so": $mime="application/octet-stream"; break;
  140. case "dll": $mime="application/octet-stream"; break;
  141. case "oda": $mime="application/oda"; break;
  142. case "pdf": $mime="application/pdf"; break;
  143. case "ai": $mime="application/postscript"; break;
  144. case "eps": $mime="application/postscript"; break;
  145. case "ps": $mime="application/postscript"; break;
  146. case "smi": $mime="application/smil"; break;
  147. case "smil": $mime="application/smil"; break;
  148. case "xls": $mime="application/vnd.ms-excel"; break;
  149. case "ppt": $mime="application/vnd.ms-powerpoint"; break;
  150. case "wbxml": $mime="application/vnd.wap.wbxml"; break;
  151. case "wmlc": $mime="application/vnd.wap.wmlc"; break;
  152. case "wmlsc": $mime="application/vnd.wap.wmlscriptc"; break;
  153. case "bcpio": $mime="application/x-bcpio"; break;
  154. case "vcd": $mime="application/x-cdlink"; break;
  155. case "pgn": $mime="application/x-chess-pgn"; break;
  156. case "cpio": $mime="application/x-cpio"; break;
  157. case "csh": $mime="application/x-csh"; break;
  158. case "dcr": $mime="application/x-director"; break;
  159. case "dir": $mime="application/x-director"; break;
  160. case "dxr": $mime="application/x-director"; break;
  161. case "dvi": $mime="application/x-dvi"; break;
  162. case "spl": $mime="application/x-futuresplash"; break;
  163. case "gtar": $mime="application/x-gtar"; break;
  164. case "hdf": $mime="application/x-hdf"; break;
  165. case "js": $mime="application/x-javascript"; break;
  166. case "skp": $mime="application/x-koan"; break;
  167. case "skd": $mime="application/x-koan"; break;
  168. case "skt": $mime="application/x-koan"; break;
  169. case "skm": $mime="application/x-koan"; break;
  170. case "latex": $mime="application/x-latex"; break;
  171. case "nc": $mime="application/x-netcdf"; break;
  172. case "cdf": $mime="application/x-netcdf"; break;
  173. case "sh": $mime="application/x-sh"; break;
  174. case "shar": $mime="application/x-shar"; break;
  175. case "swf": $mime="application/x-shockwave-flash"; break;
  176. case "sit": $mime="application/x-stuffit"; break;
  177. case "sv4cpio": $mime="application/x-sv4cpio"; break;
  178. case "sv4crc": $mime="application/x-sv4crc"; break;
  179. case "tar": $mime="application/x-tar"; break;
  180. case "tcl": $mime="application/x-tcl"; break;
  181. case "tex": $mime="application/x-tex"; break;
  182. case "texinfo": $mime="application/x-texinfo"; break;
  183. case "texi": $mime="application/x-texinfo"; break;
  184. case "t": $mime="application/x-troff"; break;
  185. case "tr": $mime="application/x-troff"; break;
  186. case "roff": $mime="application/x-troff"; break;
  187. case "man": $mime="application/x-troff-man"; break;
  188. case "me": $mime="application/x-troff-me"; break;
  189. case "ms": $mime="application/x-troff-ms"; break;
  190. case "ustar": $mime="application/x-ustar"; break;
  191. case "src": $mime="application/x-wais-source"; break;
  192. case "xhtml": $mime="application/xhtml+xml"; break;
  193. case "xht": $mime="application/xhtml+xml"; break;
  194. case "zip": $mime="application/zip"; break;
  195. case "au": $mime="audio/basic"; break;
  196. case "snd": $mime="audio/basic"; break;
  197. case "mid": $mime="audio/midi"; break;
  198. case "midi": $mime="audio/midi"; break;
  199. case "kar": $mime="audio/midi"; break;
  200. case "mpga": $mime="audio/mpeg"; break;
  201. case "mp2": $mime="audio/mpeg"; break;
  202. case "mp3": $mime="audio/mpeg"; break;
  203. case "aif": $mime="audio/x-aiff"; break;
  204. case "aiff": $mime="audio/x-aiff"; break;
  205. case "aifc": $mime="audio/x-aiff"; break;
  206. case "m3u": $mime="audio/x-mpegurl"; break;
  207. case "ram": $mime="audio/x-pn-realaudio"; break;
  208. case "rm": $mime="audio/x-pn-realaudio"; break;
  209. case "rpm": $mime="audio/x-pn-realaudio-plugin"; break;
  210. case "ra": $mime="audio/x-realaudio"; break;
  211. case "wav": $mime="audio/x-wav"; break;
  212. case "pdb": $mime="chemical/x-pdb"; break;
  213. case "xyz": $mime="chemical/x-xyz"; break;
  214. case "bmp": $mime="image/bmp"; break;
  215. case "gif": $mime="image/gif"; break;
  216. case "ief": $mime="image/ief"; break;
  217. case "jpeg": $mime="image/jpeg"; break;
  218. case "jpg": $mime="image/jpeg"; break;
  219. case "jpe": $mime="image/jpeg"; break;
  220. case "png": $mime="image/png"; break;
  221. case "tiff": $mime="image/tiff"; break;
  222. case "tif": $mime="image/tiff"; break;
  223. case "djvu": $mime="image/vnd.djvu"; break;
  224. case "djv": $mime="image/vnd.djvu"; break;
  225. case "wbmp": $mime="image/vnd.wap.wbmp"; break;
  226. case "ras": $mime="image/x-cmu-raster"; break;
  227. case "pnm": $mime="image/x-portable-anymap"; break;
  228. case "pbm": $mime="image/x-portable-bitmap"; break;
  229. case "pgm": $mime="image/x-portable-graymap"; break;
  230. case "ppm": $mime="image/x-portable-pixmap"; break;
  231. case "rgb": $mime="image/x-rgb"; break;
  232. case "xbm": $mime="image/x-xbitmap"; break;
  233. case "xpm": $mime="image/x-xpixmap"; break;
  234. case "xwd": $mime="image/x-xwindowdump"; break;
  235. case "igs": $mime="model/iges"; break;
  236. case "iges": $mime="model/iges"; break;
  237. case "msh": $mime="model/mesh"; break;
  238. case "mesh": $mime="model/mesh"; break;
  239. case "silo": $mime="model/mesh"; break;
  240. case "wrl": $mime="model/vrml"; break;
  241. case "vrml": $mime="model/vrml"; break;
  242. case "css": $mime="text/css"; break;
  243. case "html": $mime="text/html"; break;
  244. case "htm": $mime="text/html"; break;
  245. case "asc": $mime="text/plain"; break;
  246. case "txt": $mime="text/plain"; break;
  247. case "rtx": $mime="text/richtext"; break;
  248. case "rtf": $mime="text/rtf"; break;
  249. case "sgml": $mime="text/sgml"; break;
  250. case "sgm": $mime="text/sgml"; break;
  251. case "tsv": $mime="text/tab-separated-values"; break;
  252. case "wml": $mime="text/vnd.wap.wml"; break;
  253. case "wmls": $mime="text/vnd.wap.wmlscript"; break;
  254. case "etx": $mime="text/x-setext"; break;
  255. case "xml": $mime="text/xml"; break;
  256. case "xsl": $mime="text/xml"; break;
  257. case "mpeg": $mime="video/mpeg"; break;
  258. case "mpg": $mime="video/mpeg"; break;
  259. case "mpe": $mime="video/mpeg"; break;
  260. case "qt": $mime="video/quicktime"; break;
  261. case "mov": $mime="video/quicktime"; break;
  262. case "mxu": $mime="video/vnd.mpegurl"; break;
  263. case "avi": $mime="video/x-msvideo"; break;
  264. case "movie": $mime="video/x-sgi-movie"; break;
  265. case "asf": $mime="video/x-ms-asf"; break;
  266. case "asx": $mime="video/x-ms-asf"; break;
  267. case "wm": $mime="video/x-ms-wm"; break;
  268. case "wmv": $mime="video/x-ms-wmv"; break;
  269. case "wvx": $mime="video/x-ms-wvx"; break;
  270. case "ice": $mime="x-conference/x-cooltalk"; break;
  271. }
  272. if (empty($mime)) {
  273. $mime = 'application/octet-stream';
  274. }
  275. $mimetype = $mime;
  276. }
  277. return $mimetype;
  278. }
  279. public function preset($type = null) {
  280. # testing only:
  281. //pr ($this->Email);
  282. //pr ($this);
  283. }
  284. /**
  285. * test for a specific error
  286. * @param code: 4xx, 5xx, 5xx 5.1.1, 5xx 5.2.2, ...
  287. * @return boolean $status (TRUE only if this specific error occured)
  288. * 2010-06-08 ms
  289. */
  290. public function hasError($code) {
  291. if (!empty($this->errors)) {
  292. foreach ($this->errors as $error) {
  293. if (substr($error, 0, strlen($code)) == (string)$code) {
  294. return true;
  295. }
  296. }
  297. }
  298. return false;
  299. }
  300. public function validates() {
  301. if (!empty($this->Email->subject)) {
  302. return true;
  303. }
  304. return false;
  305. }
  306. /**
  307. * Domain as top level (the part after @)
  308. *
  309. * @param string $domain Manually set the domain for CLI mailing
  310. * @return mixed
  311. * @throws SocketException
  312. */
  313. public function domain($domain = null) {
  314. $this->_domain = $domain;
  315. return $this;
  316. }
  317. /**
  318. * Get list of headers
  319. *
  320. * ### Includes:
  321. *
  322. * - `from`
  323. * - `replyTo`
  324. * - `readReceipt`
  325. * - `returnPath`
  326. * - `to`
  327. * - `cc`
  328. * - `bcc`
  329. * - `subject`
  330. *
  331. * @param array $include
  332. * @return array
  333. */
  334. public function getHeaders($include = array()) {
  335. if ($include == array_values($include)) {
  336. $include = array_fill_keys($include, true);
  337. }
  338. $defaults = array_fill_keys(array('from', 'sender', 'replyTo', 'readReceipt', 'returnPath', 'to', 'cc', 'bcc', 'subject'), false);
  339. $include += $defaults;
  340. $headers = array();
  341. $relation = array(
  342. 'from' => 'From',
  343. 'replyTo' => 'Reply-To',
  344. 'readReceipt' => 'Disposition-Notification-To',
  345. 'returnPath' => 'Return-Path'
  346. );
  347. foreach ($relation as $var => $header) {
  348. if ($include[$var]) {
  349. $var = '_' . $var;
  350. $headers[$header] = current($this->_formatAddress($this->{$var}));
  351. }
  352. }
  353. if ($include['sender']) {
  354. if (key($this->_sender) === key($this->_from)) {
  355. $headers['Sender'] = '';
  356. } else {
  357. $headers['Sender'] = current($this->_formatAddress($this->_sender));
  358. }
  359. }
  360. foreach (array('to', 'cc', 'bcc') as $var) {
  361. if ($include[$var]) {
  362. $classVar = '_' . $var;
  363. $headers[ucfirst($var)] = implode(', ', $this->_formatAddress($this->{$classVar}));
  364. }
  365. }
  366. $headers += $this->_headers;
  367. if (!isset($headers['X-Mailer'])) {
  368. $headers['X-Mailer'] = self::EMAIL_CLIENT;
  369. }
  370. if (!isset($headers['Date'])) {
  371. $headers['Date'] = date(DATE_RFC2822);
  372. }
  373. if ($this->_messageId !== false) {
  374. if ($this->_messageId === true) {
  375. $headers['Message-ID'] = '<' . str_replace('-', '', String::UUID()) . '@' . $this->_domain . '>';
  376. } else {
  377. $headers['Message-ID'] = $this->_messageId;
  378. }
  379. }
  380. if ($include['subject']) {
  381. $headers['Subject'] = $this->_subject;
  382. }
  383. $headers['MIME-Version'] = '1.0';
  384. if (!empty($this->_attachments) || $this->_emailFormat === 'both') {
  385. $headers['Content-Type'] = 'multipart/mixed; boundary="' . $this->_boundary . '"';
  386. } elseif ($this->_emailFormat === 'text') {
  387. $headers['Content-Type'] = 'text/plain; charset=' . $this->charset;
  388. } elseif ($this->_emailFormat === 'html') {
  389. $headers['Content-Type'] = 'text/html; charset=' . $this->charset;
  390. }
  391. $headers['Content-Transfer-Encoding'] = $this->_getContentTransferEncoding();
  392. return $headers;
  393. }
  394. /**
  395. * Apply the config to an instance
  396. *
  397. * @param CakeEmail $obj CakeEmail
  398. * @param array $config
  399. * @return void
  400. * @throws ConfigureException When configuration file cannot be found, or is missing
  401. * the named config.
  402. */
  403. protected function _applyConfig($config) {
  404. if (is_string($config)) {
  405. if (!class_exists('EmailConfig') && !config('email')) {
  406. throw new ConfigureException(__d('cake_dev', '%s not found.', APP . 'Config' . DS . 'email.php'));
  407. }
  408. $configs = new EmailConfig();
  409. if (!isset($configs->{$config})) {
  410. throw new ConfigureException(__d('cake_dev', 'Unknown email configuration "%s".', $config));
  411. }
  412. $config = $configs->{$config};
  413. }
  414. $this->_config += $config;
  415. if (!empty($config['charset'])) {
  416. $this->charset = $config['charset'];
  417. }
  418. if (!empty($config['headerCharset'])) {
  419. $this->headerCharset = $config['headerCharset'];
  420. }
  421. if (empty($this->headerCharset)) {
  422. $this->headerCharset = $this->charset;
  423. }
  424. $simpleMethods = array(
  425. 'from', 'sender', 'to', 'replyTo', 'readReceipt', 'returnPath', 'cc', 'bcc',
  426. 'messageId', 'domain', 'subject', 'viewRender', 'viewVars', 'attachments',
  427. 'transport', 'emailFormat'
  428. );
  429. foreach ($simpleMethods as $method) {
  430. if (isset($config[$method])) {
  431. $this->$method($config[$method]);
  432. unset($config[$method]);
  433. }
  434. }
  435. if (isset($config['headers'])) {
  436. $this->setHeaders($config['headers']);
  437. unset($config['headers']);
  438. }
  439. if (array_key_exists('template', $config)) {
  440. $layout = false;
  441. if (array_key_exists('layout', $config)) {
  442. $layout = $config['layout'];
  443. unset($config['layout']);
  444. }
  445. $this->template($config['template'], $layout);
  446. unset($config['template']);
  447. }
  448. $this->transportClass()->config($config);
  449. }
  450. /**
  451. * Set the body of the mail as we send it.
  452. * Note: the text can be an array, each element will appear as a seperate line in the message body.
  453. * @param string/array: message
  454. * LEAVE empty if you use $this->set() in combination with templates
  455. */
  456. public function send($message = null) {
  457. $this->_log = array(
  458. 'to' => $this->_to,
  459. 'from' => $this->_from,
  460. 'sender' => $this->_sender,
  461. 'replyTo' => $this->_replyTo,
  462. 'cc' => $this->_cc,
  463. 'subject' => $this->_subject,
  464. 'cc' => $this->_cc,
  465. 'transport' => $this->_transportName
  466. );
  467. # prep images for inline
  468. /*
  469. if ($this->_emailFormat !== 'text') {
  470. if ($message !== null) {
  471. $message = $this->_prepMessage($message);
  472. } else {
  473. $this->_htmlMessage = $this->_prepMessage($this->_htmlMessage);
  474. }
  475. }
  476. */
  477. try {
  478. $this->_debug = parent::send($message);
  479. } catch (Exception $e) {
  480. $this->error = $e->getMessage();
  481. if (Configure::read('debug') > 0 || env('REMOTE_ADDR') == '127.0.0.1') {
  482. $this->error .= ' (line '.$e->getLine().' in '.$e->getFile().')'.PHP_EOL.$e->getTraceAsString();
  483. }
  484. if (!empty($this->_config['report'])) {
  485. $this->_logEmail();
  486. }
  487. return false;
  488. }
  489. if (!empty($this->_config['report'])) {
  490. $this->_logEmail();
  491. }
  492. return true;
  493. }
  494. protected function _prepMessage($text) {
  495. return $text;
  496. }
  497. /**
  498. * @return string
  499. */
  500. public function getError() {
  501. return $this->error;
  502. }
  503. protected function _logEmail($append = null) {
  504. $res = $this->_log['transport'].
  505. ' - '.'TO:'.implode(',', array_keys($this->_log['to'])).
  506. '||FROM:'.implode(',', array_keys($this->_log['from'])).
  507. '||REPLY:'.implode(',', array_keys($this->_log['replyTo'])).
  508. '||S:'.$this->_log['subject'];
  509. $type = 'email';
  510. if (!empty($this->error)) {
  511. $type = 'email_error';
  512. $res .= '||ERROR:' . $this->error;
  513. }
  514. if ($append) {
  515. $res .= '||'.$append;
  516. }
  517. CakeLog::write($type, $res);
  518. }
  519. /**
  520. * toggle debug mode
  521. * 2011-05-27 ms
  522. */
  523. public function debug($mode = null) {
  524. if ($mode) {
  525. $this->debug = true;
  526. //$this->delivery('debug');
  527. } else {
  528. $this->debug = false;
  529. //$this->delivery($this->deliveryMethod);
  530. }
  531. }
  532. public function resetAndSet() {
  533. $this->_to = array();
  534. $this->_cc = array();
  535. $this->_bcc = array();
  536. $this->_messageId = true;
  537. $this->_subject = '';
  538. $this->_headers = array();
  539. $this->_viewVars = array();
  540. $this->_textMessage = '';
  541. $this->_htmlMessage = '';
  542. $this->_message = '';
  543. $this->_attachments = array();
  544. $this->from(Configure::read('Config.admin_email'), Configure::read('Config.admin_emailname'));
  545. if ($xMailer = Configure::read('Config.x-mailer')) {
  546. $this->addHeaders(array('X-Mailer'=>$xMailer));
  547. }
  548. //$this->errors = array();
  549. //$this->charset($this->charset);
  550. //$this->sendAs($this->sendAs);
  551. //$this->layout($this->layout);
  552. //$this->delivery($this->deliveryMethod);
  553. }
  554. public function reset() {
  555. parent::reset();
  556. $this->error = '';
  557. $this->_debug = null;
  558. }
  559. public function flashDebug() {
  560. $info = $this->Email->Controller->Session->read('Message.email.message');
  561. if (empty($info)) {
  562. $info = $this->Email->Controller->Session->read('Message.email.message');
  563. }
  564. $info .= BR;
  565. $info .= h($this->_logMessage());
  566. $this->Email->Controller->Session->delete('Message.email');
  567. $this->Email->Controller->flashMessage($info, 'info');
  568. if (!empty($this->errors)) {
  569. $this->Email->Controller->flashMessage(implode(BR, $this->errors), 'error');
  570. }
  571. }
  572. }