Ejemplo n.º 1
0
 public function email(array $conf)
 {
     $to = isAke($conf, 'to', false);
     if (false !== $to) {
         $toName = isAke($conf, 'to_name', $to);
         $from = isAke($conf, 'from', '*****@*****.**');
         $fromName = isAke($conf, 'from_name', 'clippCity');
         $subject = isAke($conf, 'subject', 'Message');
         $priority = isAke($conf, 'priority', 3);
         $files = isAke($conf, 'files', []);
         $embeds = isAke($conf, 'embeds', []);
         $text = isAke($conf, 'text', false);
         $html = isAke($conf, 'html', false);
         if (false === $text && false === $html) {
             throw new Exception("You need to provide a valid text or html message to send this email.");
         } else {
             $message = new Message(new SM());
             $message->from($from, $fromName)->to($to, $toName)->subject($subject)->priority($priority);
             if (!empty($files)) {
                 foreach ($files as $file) {
                     if (File::exists($file)) {
                         $message->attach($file);
                     }
                 }
             }
             if (!empty($embeds)) {
                 foreach ($embeds as $embed) {
                     if (File::exists($embed)) {
                         $message->embed($embed);
                     }
                 }
             }
             $addText = false;
             if (false !== $html) {
                 $message->setBody($html, 'text/html');
                 if (false !== $text) {
                     $message->addPart($text, 'text/plain');
                     $addText = true;
                 }
             }
             if (false !== $text && false === $addText) {
                 $message->setBody($text, 'text/plain');
             }
             return with(new Mandrill(Config::get('mailer.password')))->send($message->getSwiftMessage());
         }
     } else {
         throw new Exception("The field 'to' is needed to send this email.");
     }
 }
Ejemplo n.º 2
0
 public function log()
 {
     $to = isAke($this, 'to', false);
     if ($to) {
         $toName = isAke($this, 'to_name', $to);
         $from = isAke($this, 'from', '*****@*****.**');
         $fromName = isAke($this, 'from_name', 'clippCity');
         $subject = isAke($this, 'subject', 'Message');
         $priority = isAke($this, 'priority', 3);
         $files = isAke($this, 'files', []);
         $embeds = isAke($this, 'embeds', []);
         $text = isAke($this, 'text', false);
         $html = isAke($this, 'html', false);
         if (false === $text && false === $html) {
             throw new Exception("You need to provide a valid text or html message to send this email.");
         } else {
             $message = new Message(new SM());
             $message->from($from, $fromName)->to($to, $toName)->subject($subject)->priority($priority);
             if (!empty($files)) {
                 foreach ($files as $file) {
                     if (File::exists($file)) {
                         $message->attach($file);
                     }
                 }
             }
             if (!empty($embeds)) {
                 foreach ($embeds as $embed) {
                     if (File::exists($embed)) {
                         $message->embed($embed);
                     }
                 }
             }
             $addText = false;
             if (false !== $html) {
                 $message->setBody($html, 'text/html');
                 if (false !== $text) {
                     $message->addPart($text, 'text/plain');
                     $addText = true;
                 }
             }
             if (false !== $text && false === $addText) {
                 $message->setBody($text, 'text/plain');
             }
             return log()->debug($this->getMimeEntityString($message));
         }
     } else {
         throw new Exception("The field 'to' is needed to send this email.");
     }
 }