static function send($title, $body, $to_array, $attachment = null, $log = true) { $model = Config::find()->one(); // Create the message $message = \Swift_Message::newInstance()->setSubject($title)->setFrom(array($model->from_email => $model->from_name))->setTo($to_array)->setBody($body); // Optionally add any attachments if ($attachment) { if (is_array($attachment)) { foreach ($attachment as $file) { $message = $message->attach(Swift_Attachment::fromPath($file)); } } else { $message = $message->attach(Swift_Attachment::fromPath($attachment)); } } // Create the Transport switch ($model->type) { case 1: $transport = \Swift_SmtpTransport::newInstance($model->smtp, $model->port > 0 ?: 25)->setUsername($model->from_email)->setPassword($model->pass); break; case 2: $transport = \Swift_SendmailTransport::newInstance('/usr/sbin/sendmail -bs'); break; case 3: $transport = \Swift_MailTransport::newInstance(); break; } $mailer = \Swift_Mailer::newInstance($transport); $result = $mailer->send($message); //log send mail if (true === $log) { static::log($to_array, $title, $body, $attachment); } }
public function actionIndex() { $a = array(array('s' => 2)); $model = Config::find()->one(); if (!$model) { $model = new Config(); } $model->scenario = 'all'; if ($this->populate($_POST, $model) && $model->save()) { flash('success', __('mail settings success')); redirect(url('email/config/index')); } echo $this->render('index', array('model' => $model)); }