public static function send($from, $template, $params = [], $options = []) { if (!isset(self::$instance)) { self::$instance = new Email(); } if (is_string($from)) { $from = [$from]; } else { array_walk_recursive($from, function (&$value) { if (is_string($value)) { $value = htmlentities($value); } }); } array_walk_recursive($params, function (&$value) { if (is_string($value)) { $value = htmlentities($value); } }); $currentUserId = null; if (isset(Yii::app()->user)) { $currentUserId = Yii::app()->user->id; } $eb = EmailBuilder::load($template); $mails = []; foreach ($from as $key => $value) { $email = $key; if (is_numeric($key)) { $email = $value; } ## merge local parameters if (is_array($value)) { $params = array_merge($params, $value); } $params['to'] = $email; $params['isPreview'] = false; if (!self::$instance->validator->validateValue($email)) { ## when email is not valid, fails silently... continue; } $html = $eb->render($params); $mails[] = ['subject' => $eb->subject, 'body' => $html, 'to' => $email]; } ServiceManager::run('SendEmail', ['mails' => $mails]); }
public function actionPreview($template) { $eb = EmailBuilder::load($template); echo $eb->render(['isPreview' => true]); }