/** * Abstract sender method * * @param User $user The recipient user * @param Notification $notification the notification to be sent * @param NotificationContent $content the content * @return mixed */ public function sendNotification(User $user, Notification $notification, NotificationContent $content) { $subject = $content->render('email_subject', $notification); $htmlBody = $content->render('email_html', $notification); $textBody = $content->render('email_text', $notification); $email = new Email($this->_config['profile']); $email->transport($this->_config['emailTransport']); $email->emailFormat('html'); if (!empty($notification->config['attachments'])) { $email->attachments($notification->config['attachments']); } $email->to([$user->email => $user->firstname . ' ' . $user->lastname]); $email->subject($subject); if (!empty($this->_config['templated']) && !empty($this->_config['template']) && !empty($this->_config['layout'])) { $email->template($this->_config['template'], $this->_config['layout']); $email->viewVars(['content' => $htmlBody]); return $email->send(); } return $email->send($htmlBody); }
/** * Format the attachments * * @param Email $email * @param type $message * @return array Message */ protected function _attachments(Email $email, $message = []) { foreach ($email->attachments() as $filename => $attach) { $content = base64_encode(file_get_contents($attach['file'])); if (isset($attach['contentId'])) { $message['images'][] = ['type' => $attach['mimetype'], 'name' => $attach['contentId'], 'content' => $content]; } else { $message['attachments'][] = ['type' => $attach['mimetype'], 'name' => $filename, 'content' => $content]; } } return $message; }