Esempio n. 1
0
 /**
  * Render the given view.
  *
  * @param  string $view
  * @param  array  $data
  *
  * @return mixed
  */
 protected function getView($view, $data)
 {
     try {
         return $this->views->make($view, $data)->render();
     } catch (\InvalidArgumentException $e) {
         return EmailUtilities::applyDataToView($view, $data);
     }
 }
Esempio n. 2
0
 /**
  * Sends out emails.
  *
  * @param array $data
  * @param null  $textView
  * @param null  $htmlView
  *
  * @return mixed
  */
 public function sendEmail($data, $textView = null, $htmlView = null)
 {
     Session::replaceLookups($textView);
     Session::replaceLookups($htmlView);
     $view = ['html' => $htmlView, 'text' => $textView];
     /** @noinspection PhpVoidFunctionResultUsedInspection */
     $count = $this->mailer->send($view, $data, function (Message $m) use($data) {
         $to = ArrayUtils::get($data, 'to');
         $cc = ArrayUtils::get($data, 'cc');
         $bcc = ArrayUtils::get($data, 'bcc');
         $subject = ArrayUtils::get($data, 'subject');
         $fromName = ArrayUtils::get($data, 'from_name');
         $fromEmail = ArrayUtils::get($data, 'from_email');
         $replyName = ArrayUtils::get($data, 'reply_to_name');
         $replyEmail = ArrayUtils::get($data, 'reply_to_email');
         if (empty($fromEmail)) {
             $fromEmail = config('mail.from.address');
             $data['from_email'] = $fromEmail;
             if (empty($fromName)) {
                 $fromName = config('mail.from.name');
                 $data['from_name'] = $fromName;
             }
         }
         $to = EmailUtilities::sanitizeAndValidateEmails($to, 'swift');
         if (!empty($cc)) {
             $cc = EmailUtilities::sanitizeAndValidateEmails($cc, 'swift');
         }
         if (!empty($bcc)) {
             $bcc = EmailUtilities::sanitizeAndValidateEmails($bcc, 'swift');
         }
         $fromEmail = EmailUtilities::sanitizeAndValidateEmails($fromEmail, 'swift');
         if (!empty($replyEmail)) {
             $replyEmail = EmailUtilities::sanitizeAndValidateEmails($replyEmail, 'swift');
         }
         $m->to($to);
         if (!empty($fromEmail)) {
             $m->from($fromEmail, $fromName);
         }
         if (!empty($replyEmail)) {
             $m->replyTo($replyEmail, $replyName);
         }
         if (!empty($subject)) {
             Session::replaceLookups($subject);
             $m->subject(EmailUtilities::applyDataToView($subject, $data));
         }
         if (!empty($bcc)) {
             $m->bcc($bcc);
         }
         if (!empty($cc)) {
             $m->cc($cc);
         }
     });
     return $count;
 }