Email.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742
  1. <?php
  2. namespace Tools\Mailer;
  3. use Cake\Core\Configure;
  4. use Cake\Log\LogTrait;
  5. use Cake\Mailer\Email as CakeEmail;
  6. use InvalidArgumentException;
  7. use Psr\Log\LogLevel;
  8. use Tools\Utility\Mime;
  9. use Tools\Utility\Text;
  10. use Tools\Utility\Utility;
  11. class Email extends CakeEmail {
  12. use LogTrait;
  13. /**
  14. * @var int|null
  15. */
  16. protected $_wrapLength = null;
  17. /**
  18. * @deprecated Since CakePHP 3.4.0-RC4 in core
  19. *
  20. * @var int|null
  21. */
  22. protected $_priority = null;
  23. /**
  24. * @var string|null
  25. */
  26. protected $_error = null;
  27. /**
  28. * @var bool|null
  29. */
  30. protected $_debug = null;
  31. /**
  32. * @var array
  33. */
  34. protected $_log = [];
  35. /**
  36. * @param string|null $config
  37. */
  38. public function __construct($config = null) {
  39. if ($config === null) {
  40. $config = 'default';
  41. }
  42. parent::__construct($config);
  43. }
  44. /**
  45. * Change the layout
  46. *
  47. * @deprecated Since CakePHP 3.4.0-RC4 in core as getLayout()/setLayout()
  48. *
  49. * @param string|bool $layout Layout to use (or false to use none)
  50. * @return $this
  51. */
  52. public function layout($layout = false) {
  53. if ($layout !== false) {
  54. $this->_layout = $layout;
  55. }
  56. return $this;
  57. }
  58. /**
  59. * Sets wrap length.
  60. *
  61. * @param int $length Must not be more than CakeEmail::LINE_LENGTH_MUST
  62. * @return $this
  63. */
  64. public function setWrapLength($length) {
  65. $this->_wrapLength = $length;
  66. return $this;
  67. }
  68. /**
  69. * Gets wrap length.
  70. *
  71. * @return int
  72. */
  73. public function getWrapLength() {
  74. return $this->_wrapLength;
  75. }
  76. /**
  77. * Set/Get wrapLength
  78. *
  79. * @deprecated Use setWrapLenght()/getWrapLength() instead.
  80. *
  81. * @param int|null $length Must not be more than CakeEmail::LINE_LENGTH_MUST
  82. * @return int|$this
  83. */
  84. public function wrapLength($length = null) {
  85. if ($length === null) {
  86. return $this->getWrapLength();
  87. }
  88. return $this->setWrapLength($length);
  89. }
  90. /**
  91. * Set/Get priority
  92. *
  93. * @deprecated Since CakePHP 3.4.0-RC4 in core as setPriority()/getPriority()
  94. *
  95. * @param int|null $priority 1 (highest) to 5 (lowest)
  96. * @return int|$this
  97. */
  98. public function priority($priority = null) {
  99. if ($priority === null) {
  100. return $this->_priority;
  101. }
  102. $this->_priority = $priority;
  103. return $this;
  104. }
  105. /**
  106. * Fix line length
  107. *
  108. * @override To wrap by must length by default.
  109. *
  110. * @param string $message Message to wrap
  111. * @param int $wrapLength
  112. * @return array Wrapped message
  113. */
  114. protected function _wrap($message, $wrapLength = CakeEmail::LINE_LENGTH_MUST) {
  115. if ($this->_wrapLength !== null) {
  116. $wrapLength = $this->_wrapLength;
  117. }
  118. return parent::_wrap($message, $wrapLength);
  119. }
  120. /**
  121. * EmailLib::resetAndSet()
  122. *
  123. * @return void
  124. */
  125. public function reset() {
  126. parent::reset();
  127. $this->_priority = null;
  128. $this->_wrapLength = null;
  129. $this->_error = null;
  130. $this->_debug = null;
  131. }
  132. /**
  133. * Ovewrite to allow custom enhancements
  134. *
  135. * @param array|string $config
  136. * @return $this
  137. */
  138. public function setProfile($config) {
  139. if (!is_array($config)) {
  140. $config = (string)$config;
  141. }
  142. $this->_applyConfig($config);
  143. $fromEmail = Configure::read('Config.systemEmail');
  144. if ($fromEmail) {
  145. $fromName = Configure::read('Config.systemName');
  146. } else {
  147. $fromEmail = Configure::read('Config.adminEmail');
  148. $fromName = Configure::read('Config.adminName');
  149. }
  150. if ($fromEmail) {
  151. $this->from($fromEmail, $fromName);
  152. }
  153. $xMailer = Configure::read('Config.xMailer');
  154. if ($xMailer) {
  155. $this->addHeaders(['X-Mailer' => $xMailer]);
  156. }
  157. return $this;
  158. }
  159. /**
  160. * @deprecated Since CakePHP 3.4.0 - use setProfile()/getProfile() instead.
  161. *
  162. * @param mixed $config
  163. * @return string|null|$this
  164. */
  165. public function profile($config = null) {
  166. if ($config === null) {
  167. return $this->_profile;
  168. }
  169. return $this->setProfile($config);
  170. }
  171. /**
  172. * Overwrite to allow mimetype detection
  173. *
  174. * @param string|array $attachments String with the filename or array with filenames
  175. * @return $this
  176. * @throws \InvalidArgumentException
  177. */
  178. public function setAttachments($attachments) {
  179. $attach = [];
  180. foreach ((array)$attachments as $name => $fileInfo) {
  181. if (!is_array($fileInfo)) {
  182. $fileInfo = ['file' => $fileInfo];
  183. }
  184. if (!isset($fileInfo['file'])) {
  185. if (!isset($fileInfo['data'])) {
  186. throw new InvalidArgumentException('No file or data specified.');
  187. }
  188. if (is_int($name)) {
  189. throw new InvalidArgumentException('No filename specified.');
  190. }
  191. } else {
  192. $fileName = $fileInfo['file'];
  193. if (!preg_match('~^https?://~i', $fileInfo['file'])) {
  194. $fileInfo['file'] = realpath($fileInfo['file']);
  195. }
  196. if ($fileInfo['file'] === false || !Utility::fileExists($fileInfo['file'])) {
  197. throw new InvalidArgumentException(sprintf('File not found: "%s"', $fileName));
  198. }
  199. if (is_int($name)) {
  200. $name = basename($fileInfo['file']);
  201. }
  202. }
  203. if (!isset($fileInfo['mimetype'])) {
  204. $ext = pathinfo($name, PATHINFO_EXTENSION);
  205. $fileInfo['mimetype'] = $this->_getMimeByExtension($ext);
  206. }
  207. $attach[$name] = $fileInfo;
  208. }
  209. $this->_attachments = $attach;
  210. return $this;
  211. }
  212. /**
  213. * @deprecated Since CakePHP 3.4.0 - use setAttachments()/getAttachments() instead.
  214. *
  215. * @param mixed|null $attachments
  216. * @return array|$this
  217. */
  218. public function attachments($attachments = null) {
  219. if ($attachments === null) {
  220. return $this->_attachments;
  221. }
  222. return $this->setAttachments($attachments);
  223. }
  224. /**
  225. * Add an attachment from file
  226. *
  227. * @param string $file Absolute path
  228. * @param string|null $name
  229. * @param array $fileInfo
  230. * @return $this
  231. */
  232. public function addAttachment($file, $name = null, $fileInfo = []) {
  233. $fileInfo['file'] = $file;
  234. if (!empty($name)) {
  235. $fileInfo = [$name => $fileInfo];
  236. } else {
  237. $fileInfo = [$fileInfo];
  238. }
  239. return $this->addAttachments($fileInfo);
  240. }
  241. /**
  242. * Add an attachment as blob
  243. *
  244. * @param string $content Blob data
  245. * @param string $filename to attach it
  246. * @param string|null $mimeType (leave it empty to get mimetype from $filename)
  247. * @param array $fileInfo
  248. * @return $this
  249. */
  250. public function addBlobAttachment($content, $filename, $mimeType = null, $fileInfo = []) {
  251. if ($mimeType === null) {
  252. $ext = pathinfo($filename, PATHINFO_EXTENSION);
  253. $mimeType = $this->_getMimeByExtension($ext);
  254. }
  255. $fileInfo['data'] = $content;
  256. $fileInfo['mimetype'] = $mimeType;
  257. $file = [$filename => $fileInfo];
  258. return $this->addAttachments($file);
  259. }
  260. /**
  261. * Adds an inline attachment from file.
  262. *
  263. * Options:
  264. * - mimetype
  265. * - contentDisposition
  266. *
  267. * @param string $contentId
  268. * @param string $file
  269. * @param string|null $name
  270. * @param array $options
  271. * @return $this
  272. */
  273. public function addEmbeddedAttachmentByContentId($contentId, $file, $name = null, array $options = []) {
  274. if (empty($name)) {
  275. $name = basename($file);
  276. }
  277. $name = pathinfo($name, PATHINFO_FILENAME) . '_' . md5($file) . '.' . pathinfo($name, PATHINFO_EXTENSION);
  278. $options['file'] = $file;
  279. if (empty($options['mimetype'])) {
  280. $options['mimetype'] = $this->_getMime($file);
  281. }
  282. $options['contentId'] = $contentId;
  283. $file = [$name => $options];
  284. return $this->addAttachments($file);
  285. }
  286. /**
  287. * Adds an inline attachment from file.
  288. *
  289. * Options:
  290. * - mimetype
  291. * - contentDisposition
  292. *
  293. * @param string $file Absolute path
  294. * @param string|null $name (optional)
  295. * @param array|string|null $options Options - string CID is deprecated
  296. * @param array $notUsed Former Options @deprecated 4th param is now 3rd since CakePHP 3.4.0 - Use addEmbeddedAttachmentByContentId() otherwise.
  297. * @return string CID ($this is deprecated!)
  298. */
  299. public function addEmbeddedAttachment($file, $name = null, $options = null, array $notUsed = []) {
  300. if (empty($name)) {
  301. $name = basename($file);
  302. }
  303. $contentId = null;
  304. // Deprecated $contentId here
  305. if (!is_array($options)) {
  306. $contentId = $options;
  307. $options = $notUsed;
  308. }
  309. $name = pathinfo($name, PATHINFO_FILENAME) . '_' . md5($file) . '.' . pathinfo($name, PATHINFO_EXTENSION);
  310. if ($contentId === null && ($cid = $this->_isEmbeddedAttachment($file, $name))) {
  311. return $cid;
  312. }
  313. $options['file'] = $file;
  314. if (empty($options['mimetype'])) {
  315. $options['mimetype'] = $this->_getMime($file);
  316. }
  317. $options['contentId'] = $contentId ?: str_replace('-', '', Text::uuid()) . '@' . $this->_domain;
  318. $file = [$name => $options];
  319. $res = $this->addAttachments($file);
  320. if ($contentId === null) {
  321. return $options['contentId'];
  322. }
  323. // Deprecated
  324. return $res;
  325. }
  326. /**
  327. * Adds an inline attachment from file.
  328. *
  329. * Options:
  330. * - mimetype
  331. * - contentDisposition
  332. *
  333. * @param string $contentId
  334. * @param string $content Blob data
  335. * @param string $file File File path to file
  336. * @param string|null $mimeType (leave it empty to get mimetype from $filename)
  337. * @param array $options
  338. * @return $this
  339. */
  340. public function addEmbeddedBlobAttachmentByContentId($contentId, $content, $file, $mimeType = null, array $options = []) {
  341. if ($mimeType === null) {
  342. $ext = pathinfo($file, PATHINFO_EXTENSION);
  343. $mimeType = $this->_getMimeByExtension($ext);
  344. }
  345. $filename = pathinfo($file, PATHINFO_FILENAME) . '_' . md5($content) . '.' . pathinfo($file, PATHINFO_EXTENSION);
  346. $options['data'] = $content;
  347. $options['mimetype'] = $mimeType;
  348. $options['contentId'] = $contentId;
  349. $file = [$filename => $options];
  350. $res = $this->addAttachments($file);
  351. return $res;
  352. }
  353. /**
  354. * Add an inline attachment as blob
  355. *
  356. * Options:
  357. * - contentDisposition
  358. *
  359. * @param string $content Blob data
  360. * @param string $filename to attach it
  361. * @param string|null $mimeType (leave it empty to get mimetype from $filename)
  362. * @param array|string|null $options Options - string CID is deprecated
  363. * @param array $notUsed
  364. * @return string CID CcontentId ($this is deprecated)
  365. */
  366. public function addEmbeddedBlobAttachment($content, $filename, $mimeType = null, $options = null, array $notUsed = []) {
  367. if ($mimeType === null) {
  368. $ext = pathinfo($filename, PATHINFO_EXTENSION);
  369. $mimeType = $this->_getMimeByExtension($ext);
  370. }
  371. $contentId = null;
  372. // Deprecated $contentId here
  373. if (!is_array($options)) {
  374. $contentId = $options;
  375. $options = $notUsed;
  376. }
  377. $filename = pathinfo($filename, PATHINFO_FILENAME) . '_' . md5($content) . '.' . pathinfo($filename, PATHINFO_EXTENSION);
  378. if ($contentId === null && ($cid = $this->_isEmbeddedBlobAttachment($content, $filename))) {
  379. return $cid;
  380. }
  381. $options['data'] = $content;
  382. $options['mimetype'] = $mimeType;
  383. $options['contentId'] = $contentId ? $contentId : str_replace('-', '', Text::uuid()) . '@' . $this->_domain;
  384. $file = [$filename => $options];
  385. $res = $this->addAttachments($file);
  386. if ($contentId === null) {
  387. return $options['contentId'];
  388. }
  389. // Deprecated
  390. return $res;
  391. }
  392. /**
  393. * Returns if this particular file has already been attached as embedded file with this exact name
  394. * to prevent the same image to overwrite each other and also to only send this image once.
  395. * Allows multiple usage of the same embedded image (using the same cid)
  396. *
  397. * @param string $file
  398. * @param string $name
  399. * @return bool|string CID of the found file or false if no such attachment can be found
  400. */
  401. protected function _isEmbeddedAttachment($file, $name) {
  402. foreach ($this->_attachments as $filename => $fileInfo) {
  403. if ($filename !== $name) {
  404. continue;
  405. }
  406. return $fileInfo['contentId'];
  407. }
  408. return false;
  409. }
  410. /**
  411. * Returns if this particular file has already been attached as embedded file with this exact name
  412. * to prevent the same image to overwrite each other and also to only send this image once.
  413. * Allows multiple usage of the same embedded image (using the same cid)
  414. *
  415. * @param string $content
  416. * @param string $name
  417. * @return bool|string CID of the found file or false if no such attachment can be found
  418. */
  419. protected function _isEmbeddedBlobAttachment($content, $name) {
  420. foreach ($this->_attachments as $filename => $fileInfo) {
  421. if ($filename !== $name) {
  422. continue;
  423. }
  424. return $fileInfo['contentId'];
  425. }
  426. return false;
  427. }
  428. /**
  429. * @param string $ext
  430. * @param string $default
  431. * @return mixed
  432. */
  433. protected function _getMimeByExtension($ext, $default = 'application/octet-stream') {
  434. if (!isset($this->_Mime)) {
  435. $this->_Mime = new Mime();
  436. }
  437. $mime = $this->_Mime->getMimeTypeByAlias($ext);
  438. if (!$mime) {
  439. $mime = $default;
  440. }
  441. return $mime;
  442. }
  443. /**
  444. * Try to find mimetype by file extension
  445. *
  446. * @param string $filename File name
  447. * @param string $default default MimeType
  448. * @return string Mimetype (falls back to `application/octet-stream`)
  449. */
  450. protected function _getMime($filename, $default = 'application/octet-stream') {
  451. if (!isset($this->_Mime)) {
  452. $this->_Mime = new Mime();
  453. }
  454. $mime = $this->_Mime->detectMimeType($filename);
  455. // Some environments falsely return the default too fast, better fallback to extension here
  456. if (!$mime || $mime === $default) {
  457. $ext = pathinfo($filename, PATHINFO_EXTENSION);
  458. $mime = $this->_Mime->getMimeTypeByAlias($ext);
  459. }
  460. return $mime;
  461. }
  462. /**
  463. * Read the file contents and return a base64 version of the file contents.
  464. * Overwrite parent to avoid File class and file_exists to false negative existent
  465. * remove images.
  466. * Also fixes file_get_contents (used via File class) to close the connection again
  467. * after getting remote files. So far it would have kept the connection open in HTTP/1.1.
  468. *
  469. * @param string $path The absolute path to the file to read.
  470. * @return string File contents in base64 encoding
  471. */
  472. protected function _readFile($path) {
  473. $context = stream_context_create(
  474. ['http' => ['header' => 'Connection: close']]);
  475. $content = file_get_contents($path, 0, $context);
  476. if (!$content) {
  477. trigger_error('No content found for ' . $path);
  478. }
  479. return chunk_split(base64_encode($content));
  480. }
  481. /**
  482. * Validate if the email has the required fields necessary to make send() work.
  483. * Assumes layouting (does not check on content to be present or if view/layout files are missing).
  484. *
  485. * @return bool Success
  486. */
  487. public function validates() {
  488. if (!empty($this->_subject) && !empty($this->_to)) {
  489. return true;
  490. }
  491. return false;
  492. }
  493. /**
  494. * Set the body of the mail as we send it.
  495. * Note: the text can be an array, each element will appear as a seperate line in the message body.
  496. *
  497. * Do NOT pass a message if you use $this->set() in combination with templates
  498. *
  499. * @override
  500. * @param string|array|null $message Message
  501. * @return bool Success
  502. */
  503. public function send($message = null) {
  504. $this->_log = [
  505. 'to' => $this->_to,
  506. 'from' => $this->_from,
  507. 'sender' => $this->_sender,
  508. 'replyTo' => $this->_replyTo,
  509. 'cc' => $this->_cc,
  510. 'subject' => $this->_subject,
  511. 'bcc' => $this->_bcc,
  512. 'transport' => get_class($this->_transport),
  513. ];
  514. /** @deprecated Since CakePHP 3.4.0-RC4 in core */
  515. if ($this->_priority) {
  516. $this->_headers['X-Priority'] = $this->_priority;
  517. }
  518. // if not live, just log but do not send any mails //TODO: remove and use Debug Transport!
  519. if (!Configure::read('Config.live')) {
  520. $this->_logEmail();
  521. return true;
  522. }
  523. // Security measure to not sent to the actual addressee in debug mode while email sending is live
  524. if (Configure::read('debug') && Configure::read('Config.live')) {
  525. $adminEmail = Configure::read('Config.adminEmail');
  526. if (!$adminEmail) {
  527. $adminEmail = Configure::read('Config.systemEmail');
  528. }
  529. foreach ($this->_to as $k => $v) {
  530. if ($k === $adminEmail) {
  531. continue;
  532. }
  533. unset($this->_to[$k]);
  534. $this->_to[$adminEmail] = $v;
  535. }
  536. foreach ($this->_cc as $k => $v) {
  537. if ($k === $adminEmail) {
  538. continue;
  539. }
  540. unset($this->_cc[$k]);
  541. $this->_cc[$adminEmail] = $v;
  542. }
  543. foreach ($this->_bcc as $k => $v) {
  544. if ($k === $adminEmail) {
  545. continue;
  546. }
  547. unset($this->_bcc[$k]);
  548. $this->_bcc[] = $v;
  549. }
  550. }
  551. try {
  552. $this->_debug = parent::send($message);
  553. } catch (\Exception $e) {
  554. $this->_error = $e->getMessage();
  555. $this->_error .= ' (line ' . $e->getLine() . ' in ' . $e->getFile() . ')' . PHP_EOL .
  556. $e->getTraceAsString();
  557. // always log report
  558. $this->_logEmail(LogLevel::ERROR);
  559. // log error
  560. $this->log($this->_error, LogLevel::ERROR);
  561. return false;
  562. }
  563. if (!empty($this->_profile['logReport'])) {
  564. $this->_logEmail();
  565. }
  566. return true;
  567. }
  568. /**
  569. * @param string $level
  570. * @return void
  571. */
  572. protected function _logEmail($level = LogLevel::INFO) {
  573. $content =
  574. $this->_log['transport'] . (!Configure::read('Config.live') ? ' (simulated)' : '')
  575. . ' - ' . 'TO:' . implode(',', array_keys($this->_log['to']))
  576. . '||FROM:' . implode(',', array_keys($this->_log['from']))
  577. . '||REPLY:' . implode(',', array_keys($this->_log['replyTo']))
  578. . '||S:' . $this->_log['subject'];
  579. $this->log($content, $level);
  580. }
  581. /**
  582. * Attach inline/embedded files to the message.
  583. *
  584. * CUSTOM FIX: blob data support
  585. *
  586. * @override
  587. * @param string|null $boundary Boundary to use. If null, will default to $this->_boundary
  588. * @return array An array of lines to add to the message
  589. */
  590. protected function _attachInlineFiles($boundary = null) {
  591. if ($boundary === null) {
  592. $boundary = $this->_boundary;
  593. }
  594. $msg = [];
  595. foreach ($this->_attachments as $filename => $fileInfo) {
  596. if (empty($fileInfo['contentId'])) {
  597. continue;
  598. }
  599. if (!empty($fileInfo['data'])) {
  600. $data = $fileInfo['data'];
  601. $data = chunk_split(base64_encode($data));
  602. } elseif (!empty($fileInfo['file'])) {
  603. $data = $this->_readFile($fileInfo['file']);
  604. } else {
  605. continue;
  606. }
  607. $msg[] = '--' . $boundary;
  608. $msg[] = 'Content-Type: ' . $fileInfo['mimetype'];
  609. $msg[] = 'Content-Transfer-Encoding: base64';
  610. $msg[] = 'Content-ID: <' . $fileInfo['contentId'] . '>';
  611. $msg[] = 'Content-Disposition: inline; filename="' . $filename . '"';
  612. $msg[] = '';
  613. $msg[] = $data;
  614. $msg[] = '';
  615. }
  616. return $msg;
  617. }
  618. /**
  619. * Attach non-embedded files by adding file contents inside boundaries.
  620. *
  621. * CUSTOM FIX: blob data support
  622. *
  623. * @override
  624. * @param string|null $boundary Boundary to use. If null, will default to $this->_boundary
  625. * @return array An array of lines to add to the message
  626. */
  627. protected function _attachFiles($boundary = null) {
  628. if ($boundary === null) {
  629. $boundary = $this->_boundary;
  630. }
  631. $msg = [];
  632. foreach ($this->_attachments as $filename => $fileInfo) {
  633. if (!empty($fileInfo['contentId'])) {
  634. continue;
  635. }
  636. if (!empty($fileInfo['data'])) {
  637. $data = $fileInfo['data'];
  638. $data = chunk_split(base64_encode($data));
  639. } elseif (!empty($fileInfo['file'])) {
  640. $data = $this->_readFile($fileInfo['file']);
  641. } else {
  642. continue;
  643. }
  644. $msg[] = '--' . $boundary;
  645. $msg[] = 'Content-Type: ' . $fileInfo['mimetype'];
  646. $msg[] = 'Content-Transfer-Encoding: base64';
  647. if (
  648. !isset($fileInfo['contentDisposition']) ||
  649. $fileInfo['contentDisposition']
  650. ) {
  651. $msg[] = 'Content-Disposition: attachment; filename="' . $filename . '"';
  652. }
  653. $msg[] = '';
  654. $msg[] = $data;
  655. $msg[] = '';
  656. }
  657. return $msg;
  658. }
  659. /**
  660. * Returns the error if existent
  661. *
  662. * @return string
  663. */
  664. public function getError() {
  665. return $this->_error;
  666. }
  667. }