/application/models/notifier/Notifier.class.php

https://gitlab.com/x33n/ProjectPier-Core · PHP · 720 lines · 397 code · 100 blank · 223 comment · 75 complexity · 81694000a532d365a56f1088bd08a23a MD5 · raw file

  1. <?php
  2. /**
  3. * Notifier class has purpose of sending various notification to users. Primary
  4. * notification method is email
  5. *
  6. * @version 1.0
  7. * @http://www.projectpier.org/
  8. */
  9. class Notifier {
  10. /** Supported transports **/
  11. const MAIL_TRANSPORT_MAIL = 'mail()';
  12. const MAIL_TRANSPORT_SMTP = 'smtp';
  13. /** Secure connection values **/
  14. const SMTP_SECURE_CONNECTION_NO = 'no';
  15. const SMTP_SECURE_CONNECTION_SSL = 'ssl';
  16. const SMTP_SECURE_CONNECTION_TLS = 'tls';
  17. /**
  18. * Cached value of exchange compatible config option
  19. *
  20. * @var boolean
  21. */
  22. static public $exchange_compatible = null;
  23. /**
  24. * Reset password and send forgot password email to the user
  25. *
  26. * @param User $user
  27. * @return boolean
  28. * @throws NotifierConnectionError
  29. */
  30. static function forgotPassword(User $user) {
  31. $administrator = owner_company()->getCreatedBy();
  32. $new_password = $user->resetPassword(true);
  33. tpl_assign('user', $user);
  34. tpl_assign('new_password', $new_password);
  35. $from = $administrator->getDisplayName() . ' ' . config_option('site_name', '');
  36. return self::sendEmail(
  37. self::prepareEmailAddress($user->getEmail(), $user->getDisplayName()),
  38. self::prepareEmailAddress($administrator->getEmail(), $from),
  39. lang('your password'),
  40. tpl_fetch(get_template_path('forgot_password', 'notifier'))
  41. ); // send
  42. } // forgotPassword
  43. /**
  44. * Send new account notification email to the user whose accout has been created
  45. * (welcome message)
  46. *
  47. * @param User $user
  48. * @param string $raw_password
  49. * @return boolean
  50. * @throws NotifierConnectionError
  51. */
  52. static function newUserAccount(User $user, $raw_password) {
  53. tpl_assign('new_account', $user);
  54. tpl_assign('raw_password', $raw_password);
  55. $from = $user->getCreatedByDisplayName() . ' ' . config_option('site_name', '');
  56. return self::sendEmail(
  57. self::prepareEmailAddress($user->getEmail(), $user->getDisplayName()),
  58. self::prepareEmailAddress($user->getCreatedBy()->getEmail(), $from),
  59. lang('your account created'),
  60. tpl_fetch(get_template_path('new_account', 'notifier'))
  61. ); // send
  62. } // newUserAccount
  63. /**
  64. * Send account update notification email to the user whose account has been updated
  65. *
  66. * @param User $user
  67. * @param string $raw_password
  68. * @return boolean
  69. * @throws NotifierConnectionError
  70. */
  71. static function updatedUserAccount(User $user, $raw_password) {
  72. tpl_assign('updated_account', $user);
  73. tpl_assign('raw_password', $raw_password);
  74. return self::sendEmail(
  75. self::prepareEmailAddress($user->getEmail(), $user->getDisplayName()),
  76. self::prepareEmailAddress($user->getUpdatedBy()->getEmail(), $user->getUpdatedByDisplayName()),
  77. lang('your account updated'),
  78. tpl_fetch(get_template_path('updated_account', 'notifier'))
  79. ); // send
  80. } // updatedUserAccount
  81. /**
  82. * Send new task notification to the list of users ($people)
  83. *
  84. * @param ProjectMessage $message New message
  85. * @param array $people
  86. * @return boolean
  87. * @throws NotifierConnectionError
  88. */
  89. static function newTask(ProjectTask $task, $people) {
  90. if(!is_array($people) || !count($people)) {
  91. return; // nothing here...
  92. } // if
  93. tpl_assign('new_task', $task);
  94. $recipients = array();
  95. foreach($people as $user) {
  96. $recipients[] = self::prepareEmailAddress($user->getEmail(), $user->getDisplayName());
  97. } // foreach
  98. return self::sendEmail(
  99. $recipients,
  100. self::prepareEmailAddress($task->getCreatedBy()->getEmail(), $task->getCreatedByDisplayName()),
  101. $task->getProject()->getName() . ' - ' . lang('new task') . ' - ' . $task->getObjectName(),
  102. tpl_fetch(get_template_path('new_task', 'notifier'))
  103. ); // send
  104. } // newTask
  105. /**
  106. * Send closed task notification to the list of users ($people)
  107. *
  108. * @param ProjectTask $task closed task
  109. * @param array $people
  110. * @return boolean
  111. * @throws NotifierConnectionError
  112. */
  113. static function completeTask(ProjectTask $task, $people) {
  114. if(!is_array($people) || !count($people)) {
  115. return; // nothing here...
  116. } // if
  117. tpl_assign('task', $task);
  118. $recipients = array();
  119. foreach($people as $user) {
  120. $recipients[] = self::prepareEmailAddress($user->getEmail(), $user->getDisplayName());
  121. } // foreach
  122. return self::sendEmail(
  123. $recipients,
  124. self::prepareEmailAddress($task->getCreatedBy(), $user->getEmail(), $task->getCreatedByDisplayName()),
  125. $task->getProject()->getName() . ' - ' . lang('complete task') . ' - ' . $task->getObjectName(),
  126. tpl_fetch(get_template_path('complete_task', 'notifier'))
  127. ); // send
  128. } // newTask
  129. /**
  130. * Send new message notification to the list of users ($people)
  131. *
  132. * @param ProjectMessage $message New message
  133. * @param array $people
  134. * @return boolean
  135. * @throws NotifierConnectionError
  136. */
  137. static function newMessage(ProjectMessage $message, $people) {
  138. if (!is_array($people) || !count($people)) {
  139. return; // nothing here...
  140. } // if
  141. tpl_assign('new_message', $message);
  142. $recipients = array();
  143. foreach ($people as $user) {
  144. $recipients[] = self::prepareEmailAddress($user->getEmail(), $user->getDisplayName());
  145. } // foreach
  146. return self::sendEmail(
  147. $recipients,
  148. self::prepareEmailAddress($message->getCreatedBy()->getEmail(), $message->getCreatedByDisplayName()),
  149. $message->getProject()->getName() . ' - ' . $message->getTitle(),
  150. tpl_fetch(get_template_path('new_message', 'notifier'))
  151. ); // send
  152. } // newMessage
  153. /**
  154. * Send new message notification to the list of users ($people)
  155. *
  156. * @param ProjectFile $file New file
  157. * @param array $people
  158. * @return boolean
  159. * @throws NotifierConnectionError
  160. */
  161. static function newFile(ProjectFile $file, $people) {
  162. if (!is_array($people) || !count($people)) {
  163. return; // nothing here...
  164. } // if
  165. tpl_assign('new_file', $file);
  166. $recipients = array();
  167. foreach ($people as $user) {
  168. $recipients[] = self::prepareEmailAddress($user->getEmail(), $user->getDisplayName());
  169. } // foreach
  170. return self::sendEmail(
  171. $recipients,
  172. self::prepareEmailAddress($file->getCreatedBy()->getEmail(), $file->getCreatedByDisplayName()),
  173. $file->getProject()->getName() . ' - ' . $file->getFilename(),
  174. tpl_fetch(get_template_path('new_file', 'notifier'))
  175. ); // send
  176. } // newFile
  177. /**
  178. * Send ticket notification to the list of users ($people)
  179. *
  180. * @param ProjectTicket $ticket New ticket
  181. * @param array $people
  182. * @param string $template template to send notification
  183. * @param User $user user who send the notification
  184. * @return boolean
  185. * @throws NotifierConnectionError
  186. */
  187. static function ticket(ProjectTicket $ticket, $people, $template, $user) {
  188. if(!is_array($people) || !count($people)) {
  189. return; // nothing here...
  190. } // if
  191. $recipients = array();
  192. foreach($people as $subscriber) {
  193. if($subscriber->getId() == $user->getId()) {
  194. continue; // skip comment author
  195. } // if
  196. $recipients[] = self::prepareEmailAddress($subscriber->getEmail(), $subscriber->getDisplayName());
  197. } // foreach
  198. if(!count($recipients)) {
  199. return true; // no recipients
  200. } // if
  201. tpl_assign('ticket', $ticket);
  202. return self::sendEmail(
  203. $recipients,
  204. self::prepareEmailAddress($user->getEmail(), $user->getDisplayName()),
  205. $ticket->getProject()->getName() . ' - ' . $ticket->getSummary(),
  206. tpl_fetch(get_template_path($template, 'notifier'))
  207. ); // send
  208. } // ticket
  209. /**
  210. * Send some files attached to ticket notification to ticket subscribers
  211. *
  212. * @param ProjectTicket $ticket
  213. * @param array $attached_files Files attached to ticket
  214. * @return boolean
  215. * @throws NotifierConnectionError
  216. */
  217. static function attachFilesToTicket(ProjectTicket $ticket, $attached_files) {
  218. $all_subscribers = $ticket->getSubscribers();
  219. if(!is_array($all_subscribers)) {
  220. return true; // no subscribers
  221. } // if
  222. $recipients = array();
  223. foreach($all_subscribers as $subscriber) {
  224. if($subscriber->getId() == $ticket->getUpdatedById()) {
  225. continue; // skip comment author
  226. } // if
  227. $recipients[] = self::prepareEmailAddress($subscriber->getEmail(), $subscriber->getDisplayName());
  228. } // foreach
  229. if(!count($recipients)) {
  230. return true; // no recipients
  231. } // if
  232. tpl_assign('ticket', $ticket);
  233. tpl_assign('attached_files', $attached_files);
  234. return self::sendEmail(
  235. $recipients,
  236. self::prepareEmailAddress($ticket->getUpdatedBy()->getEmail(), $ticket->getUpdatedBy()->getDisplayName()),
  237. $ticket->getProject()->getName() . ' - ' . $ticket->getSummary(),
  238. tpl_fetch(get_template_path('attach_files_ticket', 'notifier'))
  239. ); // send
  240. } // attachFilesToTicket
  241. /**
  242. * Send some files detached from ticket notification to ticket subscribers
  243. *
  244. * @param ProjectTicket $ticket
  245. * @param array $detached_files Files detached from ticket
  246. * @return boolean
  247. * @throws NotifierConnectionError
  248. */
  249. static function detachFilesFromTicket(ProjectTicket $ticket, $detached_files) {
  250. $all_subscribers = $ticket->getSubscribers();
  251. if (!is_array($all_subscribers)) {
  252. return true; // no subscribers
  253. } // if
  254. $recipients = array();
  255. foreach ($all_subscribers as $subscriber) {
  256. if ($subscriber->getId() == $ticket->getUpdatedById()) {
  257. continue; // skip comment author
  258. } // if
  259. $recipients[] = self::prepareEmailAddress($subscriber->getEmail(), $subscriber->getDisplayName());
  260. } // foreach
  261. if (!count($recipients)) {
  262. return true; // no recipients
  263. } // if
  264. tpl_assign('ticket', $ticket);
  265. tpl_assign('detached_files', $detached_files);
  266. return self::sendEmail(
  267. $recipients,
  268. self::prepareEmailAddress($ticket->getUpdatedBy()->getEmail(), $ticket->getUpdatedBy()->getDisplayName()),
  269. $ticket->getProject()->getName() . ' - ' . $ticket->getSummary(),
  270. tpl_fetch(get_template_path('detach_files_ticket', 'notifier'))
  271. ); // send
  272. } // detachFilesFromTicket
  273. /**
  274. * Send new comment notification to ticket subscriber
  275. *
  276. * @param TicketComment $comment
  277. * @return boolean
  278. * @throws NotifierConnectionError
  279. */
  280. static function newTicketComment(Comment $comment) {
  281. $ticket = $comment->getObject();
  282. if(!($ticket instanceof ProjectTicket)) {
  283. throw new Error('Invalid comment object');
  284. } // if
  285. return self::newComment($comment, $ticket->getSubscribers());
  286. } // newTicketComment
  287. /**
  288. * Send new comment notification to message subscriber
  289. *
  290. * @param MessageComment $comment
  291. * @return boolean
  292. * @throws NotifierConnectionError
  293. */
  294. static function newMessageComment(Comment $comment) {
  295. $message = $comment->getObject();
  296. if (!($message instanceof ProjectMessage)) {
  297. throw new Error('Invalid comment object');
  298. } // if
  299. $all_subscribers = $message->getSubscribers();
  300. return self::newComment($comment, $message->getSubscribers());
  301. } // newMessageComment
  302. /**
  303. * Send new comment notification to subscribers
  304. *
  305. * @access private
  306. * @param Comment $comment
  307. * @param string $title title of object for subject
  308. * @param array $all_subscribers subscribers
  309. * @return boolean
  310. * @throws NotifierConnectionError
  311. */
  312. static function newComment(Comment $comment, $all_subscribers) {
  313. if (!is_array($all_subscribers)) {
  314. return true; // no subscribers
  315. } // if
  316. $recipients = array();
  317. foreach ($all_subscribers as $subscriber) {
  318. //if ($subscriber->getId() == $comment->getCreatedById()) {
  319. // continue; // skip comment author
  320. //} // if
  321. if ($comment->isPrivate() || $comment->getObject()->isPrivate()) {
  322. if ($subscriber->isMemberOfOwnerCompany()) {
  323. $recipients[] = self::prepareEmailAddress($subscriber->getEmail(), $subscriber->getDisplayName());
  324. } // if
  325. } else {
  326. $recipients[] = self::prepareEmailAddress($subscriber->getEmail(), $subscriber->getDisplayName());
  327. } // of
  328. } // foreach
  329. if (!count($recipients)) {
  330. return true; // no recipients
  331. } // if
  332. tpl_assign('new_comment', $comment);
  333. return self::sendEmail(
  334. $recipients,
  335. self::prepareEmailAddress($comment->getCreatedBy()->getEmail(), $comment->getCreatedByDisplayName()),
  336. $comment->getProject()->getName() . ' - ' . $comment->getObject()->getTitle(),
  337. tpl_fetch(get_template_path('new_comment', 'notifier'))
  338. ); // send
  339. } // newComment
  340. /**
  341. * Tests to see if $new_user is not the same as $old_user
  342. * if users are different return true so a notification can be sent
  343. * otherwise return false so the notification can be avoided
  344. *
  345. * @param $new_user (optional) Newly assigned user (if applicable)
  346. * @param $old_user (optional) Previously assigned user (if applicable)
  347. * @return boolean
  348. */
  349. static function notifyNeeded($new_user, $old_user) {
  350. if ($old_user instanceof User) {
  351. // We have a new owner and it is different than old owner
  352. if ($new_user instanceof User && $new_user->getId() <> $old_user->getId()) {
  353. return true;
  354. }
  355. } else {
  356. // We have new owner
  357. if ($new_user instanceof User) {
  358. return true;
  359. }
  360. } // if
  361. return false;
  362. }
  363. // ---------------------------------------------------
  364. // Milestone
  365. // ---------------------------------------------------
  366. /**
  367. * Milestone has been assigned to the user
  368. *
  369. * @param ProjectMilestone $milestone
  370. * @return boolean
  371. * @throws NotifierConnectionError
  372. */
  373. function milestoneAssigned(ProjectMilestone $milestone) {
  374. if ($milestone->isCompleted()) {
  375. return true; // milestone has been already completed...
  376. } // if
  377. if (!($milestone->getAssignedTo() instanceof User)) {
  378. return true; // not assigned to user
  379. } // if
  380. tpl_assign('milestone_assigned', $milestone);
  381. return self::sendEmail(
  382. self::prepareEmailAddress($milestone->getAssignedTo()->getEmail(), $milestone->getAssignedTo()->getDisplayName()),
  383. self::prepareEmailAddress($milestone->getCreatedBy()->getEmail(), $milestone->getCreatedByDisplayName()),
  384. $milestone->getProject()->getName() . ' - ' . lang('milestone assigned to you') . ' - ' . $milestone->getName(),
  385. tpl_fetch(get_template_path('milestone_assigned', 'notifier'))
  386. ); // send
  387. } // milestoneAssigned
  388. /**
  389. * Task has been assigned to the user
  390. *
  391. * @param ProjectTask $task
  392. * @return boolean
  393. * @throws NotifierConnectionError
  394. */
  395. function taskAssigned(ProjectTask $task) {
  396. if ($task->isCompleted()) {
  397. return true; // task has been already completed...
  398. } // if
  399. if (!($task->getAssignedTo() instanceof User)) {
  400. return true; // not assigned to user
  401. } // if
  402. if ($task->getCreatedBy() instanceof User) {
  403. $from = self::prepareEmailAddress($task->getCreatedBy()->getEmail(), $task->getCreatedByDisplayName());
  404. } else {
  405. $from = self::prepareEmailAddress(logged_user()->getEmail(), logged_user()->getDisplayName());
  406. } // if
  407. tpl_assign('task_assigned', $task);
  408. return self::sendEmail(
  409. self::prepareEmailAddress($task->getAssignedTo()->getEmail(), $task->getAssignedTo()->getDisplayName()),
  410. $from,
  411. $task->getProject()->getName() . ' - ' . lang('task assigned to you') . ' - ' . $task->getObjectName(),
  412. tpl_fetch(get_template_path('task_assigned', 'notifier'), 'html', '')
  413. ); // send
  414. }
  415. /**
  416. * Send new comment notification to selected users, if not message (because message is already treated and can subscribre/unsubscribe)
  417. *
  418. * @param comment $comment
  419. * @return boolean
  420. * @throws NotifierConnectionError
  421. */
  422. static function newOtherComment(Comment $comment, $people) {
  423. if (!is_array($people) || !count($people)) {
  424. return; // nothing here...
  425. } // if
  426. // normally, if comment on message, shouldn't be using this function by the normal subscription
  427. if (($comment->getObject() instanceof ProjectMessage)) {
  428. throw new Error('Invalid comment object');
  429. } // if
  430. if (!is_array($people)) {
  431. return true; // no subscribers
  432. } // if
  433. $recipients = array();
  434. foreach ($people as $subscriber) {
  435. //if ($subscriber->getId() == $comment->getCreatedById()) {
  436. // continue; // skip comment author
  437. //} // if
  438. if ($comment->isPrivate() || $comment->getObject()->isPrivate()) {
  439. if ($subscriber->isMemberOfOwnerCompany()) {
  440. $recipients[] = self::prepareEmailAddress($subscriber->getEmail(), $subscriber->getDisplayName());
  441. } // if
  442. } else {
  443. $recipients[] = self::prepareEmailAddress($subscriber->getEmail(), $subscriber->getDisplayName());
  444. } // of
  445. } // foreach
  446. if (!count($recipients)) {
  447. return true; // no recipients
  448. } // if
  449. tpl_assign('new_comment', $comment);
  450. return self::sendEmail(
  451. $recipients,
  452. self::prepareEmailAddress($comment->getCreatedBy()->getEmail(), $comment->getCreatedByDisplayName()),
  453. $comment->getProject()->getName(),
  454. tpl_fetch(get_template_path('new_comment', 'notifier'))
  455. ); // send
  456. } // newOtherComment
  457. // ---------------------------------------------------
  458. // Util functions
  459. // ---------------------------------------------------
  460. /**
  461. * This function will prepare email address. It will return $name <$email> if both
  462. * params are presend and we are not in exchange compatibility mode. In other case
  463. * it will just return email
  464. *
  465. * @param string $email
  466. * @param string $name
  467. * @return string
  468. */
  469. static function prepareEmailAddress($email, $name = null) {
  470. if (trim($name) && !self::getExchangeCompatible()) {
  471. return trim($name) . ' <' . trim($email) . '>';
  472. } else {
  473. return trim($email);
  474. } // if
  475. } // prepareEmailAddress
  476. /**
  477. * Returns true if exchange compatible config option is set to true
  478. *
  479. * @param void
  480. * @return boolean
  481. */
  482. static function getExchangeCompatible() {
  483. if (is_null(self::$exchange_compatible)) {
  484. self::$exchange_compatible = config_option('exchange_compatible', false);
  485. } // if
  486. return self::$exchange_compatible;
  487. } // getExchangeCompatible
  488. /**
  489. * Send an email using Swift (send commands)
  490. *
  491. * @param string to_address
  492. * @param string from_address
  493. * @param string subject
  494. * @param string body, optional
  495. * @param string content-type,optional
  496. * @param string content-transfer-encoding,optional
  497. * @return bool successful
  498. */
  499. static function sendEmail($to, $from, $subject, $body = false, $type = 'text/plain', $encoding = '8bit') {
  500. //static function sendEmail($to, $from, $subject, $body = false, $type = 'text/html', $encoding = '') {
  501. Env::useLibrary('swift');
  502. $mailer = self::getMailer();
  503. if (!($mailer instanceof Swift)) {
  504. throw new NotifierConnectionError();
  505. } // if
  506. /**
  507. * If the 'expose user e-mail' flag is cleared, then replace the user's
  508. * email with the site e-mail.
  509. */
  510. if (config_option('mail_expose_user_emails', 0)==0) {
  511. $from = self::getSiteEmailAddress();
  512. }
  513. /**
  514. * Set name address in ReplyTo, some MTA think we're usurpators
  515. * (which is quite true actually...)
  516. * We only do this if we aren't already set to use the site e-mail for
  517. * all communications.
  518. */
  519. elseif (config_option('mail_use_reply_to', 0)==1) {
  520. $i = strpos($from, ' <');
  521. $name = '';
  522. if ($i!==false) {
  523. $name = substr($from, 0, $i);
  524. }
  525. $mailer->setReplyTo($from);
  526. $from = self::getSiteEmailAddress($name);
  527. }
  528. // from must be address known on server when authentication is selected
  529. $smtp_authenticate = config_option('smtp_authenticate', false);
  530. if ($smtp_authenticate) $from = config_option('smtp_username');
  531. trace("mailer->send($to, $from, $subject, $body, $type, $encoding)");
  532. $result = $mailer->send($to, $from, $subject, $body, $type, $encoding);
  533. $mailer->close();
  534. return $result;
  535. } // sendEmail
  536. /**
  537. * This function will return the e-mail address that should be used as the 'from'
  538. * address, if we are using the site address, rather than a user's own address.
  539. * $display_name is the name that will be displayed. If blank or omitted then
  540. * the project name will be used.
  541. *
  542. * @param void
  543. * @return string
  544. */
  545. static function getSiteEmailAddress($display_name = '') {
  546. static $site_email;
  547. static $default_name;
  548. if (!isset($site_email)) {
  549. $site_email = trim(config_option('mail_from'));
  550. if ($site_email=='') {
  551. $site_email = 'projectpier@'.$_SERVER['SERVER_NAME'];
  552. }
  553. }
  554. $display_name = trim($display_name);
  555. if ($display_name == '') {
  556. if (!isset($default_name)) {
  557. $default_name = config_option('site_name', '');
  558. if ($default_name == '') {
  559. $default_name = "ProjectPier";
  560. }
  561. }
  562. $display_name = $default_name;
  563. }
  564. return self::prepareEmailAddress($site_email, $display_name);
  565. }
  566. /**
  567. * This function will return SMTP connection. It will try to load options from
  568. * config and if it fails it will use settings from php.ini
  569. *
  570. * @param void
  571. * @return Swift
  572. */
  573. static function getMailer() {
  574. $mail_transport_config = config_option('mail_transport', self::MAIL_TRANSPORT_MAIL);
  575. // Emulate mail() - use NativeMail
  576. if ($mail_transport_config == self::MAIL_TRANSPORT_MAIL) {
  577. $mailer = new Swift(new Swift_Connection_NativeMail());
  578. return $mailer->isConnected() ? $mailer : null;
  579. // Use SMTP server
  580. } elseif ($mail_transport_config == self::MAIL_TRANSPORT_SMTP) {
  581. // Load SMTP config
  582. $smtp_server = config_option('smtp_server');
  583. $smtp_port = config_option('smtp_port', 25);
  584. $smtp_secure_connection = config_option('smtp_secure_connection', self::SMTP_SECURE_CONNECTION_NO);
  585. $smtp_authenticate = config_option('smtp_authenticate', false);
  586. if ($smtp_authenticate) {
  587. $smtp_username = config_option('smtp_username');
  588. $smtp_password = config_option('smtp_password');
  589. } // if
  590. switch ($smtp_secure_connection) {
  591. case self::SMTP_SECURE_CONNECTION_SSL:
  592. $transport = SWIFT_SSL;
  593. break;
  594. case self::SMTP_SECURE_CONNECTION_TLS:
  595. $transport = SWIFT_TLS;
  596. break;
  597. default:
  598. $transport = SWIFT_OPEN;
  599. } // switch
  600. $mailer = new Swift(new Swift_Connection_SMTP($smtp_server, $smtp_port, $transport));
  601. if (!$mailer->isConnected()) {
  602. return null;
  603. } // if
  604. $mailer->setCharset('UTF-8');
  605. if ($smtp_authenticate) {
  606. if ($mailer->authenticate($smtp_username, $smtp_password)) {
  607. return $mailer;
  608. } else {
  609. return null;
  610. } // if
  611. } else {
  612. return $mailer;
  613. } // if
  614. // Somethings wrong here...
  615. } else {
  616. return null;
  617. } // if
  618. } // getMailer
  619. } // Notifier
  620. ?>