public function send($subject, $text, $to, $from = null) { if (!config('mail.enabled')) { return; } $message = new Message(); $message->setSubject($subject); if ($from) { if (is_array($from)) { $message->setFrom($from[0], $from[1]); } else { $message->setFrom($from); } } $message->addTo($to); $content = '<html><head><title>' . $subject . '</title></head><body>' . $text . '</body></html>'; $html = new Mime\Part($content); $html->setType(Mime\Mime::TYPE_HTML); $html->setCharset('utf-8'); $mimeMessage = new Mime\Message(); $mimeMessage->addPart($html); foreach ($this->attachments as $attachment) { $mimeMessage->addPart($attachment); } $message->setBody($mimeMessage); try { $transport = new SmtpTransport(new SmtpOptions(config('mail.options'))); $transport->send($message); } catch (\Exception $e) { throw $e; } return $this; }
public function send($alias, $to, $from = null, array $data = null) { if (!config('mail.enabled')) { return; } $template = $this->getTemplate($alias); if (!$template) { throw new CoreException('Cannot find template with alias/id: ' . $alias, 404); } if ($data === null) { $data = array(); } $template->setDescription($this->replaceTemplateContent($template->getDescription(), $data)); $template->setName($this->replaceTemplateContent($template->getName(), $data)); $preffix = server_url(base_url()); $content = preg_replace('#background\\: url\\((.*)\\)#', 'background: url(' . $preffix . '$1)', $template->getDescription()); $content = preg_replace('#\\<img src=\\"(.*)\\"#', '<img src="' . $preffix . '$1"', $content); $template->getDescription($content); $message = new Message(); $message->setSubject($template->getName()); if ($from) { $message->setFrom($from); } $message->addTo($to); $content = $template->getDescription(); $content = '<html><head><title>' . $template->getName() . '</title></head><body>' . $template->getDescription() . '</body></html>'; $html = new Mime\Part($content); $html->setType(Mime\Mime::TYPE_HTML); $html->setCharset('utf-8'); $mimeMessage = new Mime\Message(); $mimeMessage->addPart($html); foreach ($this->attachments as $attachment) { $mimeMessage->addPart($attachment); } $message->setBody($mimeMessage); try { $transport = new SmtpTransport(new SmtpOptions(config('mail.options'))); $transport->send($message); } catch (\Exception $e) { throw $e; } return $this; }