/**
     * Creates a new User model.
     * If creation is successful, the browser will be redirected to the 'view' page.
     * @return mixed
     */
    public function actionCreate()
    {
        if (!\Yii::$app->user->isGuest) {
            return $this->goHome();
        }
        $model = new User();
        if ($model->load(Yii::$app->request->post()) && $model->save()) {
            $email = new Email();
            $email->to_name = $model->name;
            $email->to_email = $model->email;
            $email->subject = "Your Tixty Purchase";
            $message = <<<EOT
Hi {$model->name}!!

You just registered as a user. Use {$model->email} to login with the password you chose and start buying tickets at <a href="https://tixty.co.uk/">tixty.co.uk</a>

Thanks,

Tixty
EOT;
            $email->body = nl2br($message);
            $email->save();
            $email->send();
            return $this->redirect(['view', 'id' => $model->id]);
        } else {
            return $this->render('create', ['model' => $model]);
        }
    }
Beispiel #2
0
 public function actionSend()
 {
     //      //broadcast semua
     //      $email = new Email();
     //     if ($email->load(Yii::$app->request->post()) && $email->validate()) {
     //      $peserta = Peserta::find()->all();
     //      foreach($peserta as $key){
     //          $temp = $key->email;
     // echo $temp;
     //          $content_template = $email->content;
     //          //mengambil subjek dari email yang akan dikirimkan
     //          $subject_template = $email->subject;
     //          $subject = str_replace("{nama}", $key->nama, $subject_template);
     //          $content = str_replace("{nama}", $key->nama, $content_template);
     //          echo "</br>";
     //          Yii::$app->mailer
     //                   ->compose()
     //                   ->setFrom(Yii::$app->params['adminEmail'])
     //                   ->setHtmlBody($content)
     //                   ->setSubject($subject)
     //                   ->setTo($temp)
     //                   ->send();
     //          }
     //      }
     //send per event
     $email = new Email();
     if ($email->load(Yii::$app->request->post()) && $email->validate()) {
         //mengambil event yang dipilih
         $event = Event::findOne($email->id_event);
         //mengambil content dari email yang akan dikirimkan
         $content_template = $email->content;
         //mengambil subjek dari email yang akan dikirimkan
         $subject_template = $email->subject;
         foreach ($event->absensis as $absensi) {
             $temp = $absensi->idPeserta->email;
             echo $temp;
             // echo $absensi->idPeserta->email;
             echo "</br>";
             $subject = str_replace("{nama}", $absensi->idPeserta->nama, $subject_template);
             $subject = str_replace("{nama_seminar}", $event->nama, $subject);
             $subject = str_replace("{jadwal}", $event->jadwal, $subject);
             $content = str_replace("{nama}", $absensi->idPeserta->nama, $content_template);
             $content = str_replace("{nama_seminar}", $event->nama, $content);
             $content = str_replace("{jadwal}", $event->jadwal, $content);
             Yii::$app->mailer->compose()->setFrom(Yii::$app->params['adminEmail'])->setHtmlBody($content)->setSubject($subject)->setTo($temp)->send();
         }
     }
 }
 public function actionIndex()
 {
     $model = new Receive();
     error_reporting(E_ALL ^ E_WARNING);
     $obj = new receiveMail('tclrg', 'Luanruitest', '*****@*****.**', 'imap.126.com', 'imap', '993', 'ture');
     $obj->connect();
     $tot = $obj->getTotalMails();
     //查看邮箱是否有新邮件
     $old_email_count = Email::find()->count();
     for ($i = $tot; $i > $old_email_count; $i--) {
         $model = new Receive();
         $head = $obj->getHeaders($i);
         $head['subject'] = imap_mime_header_decode($head['subject'])[0]->text;
         $head['from'] = imap_mime_header_decode($head['from'])[0]->text;
         $head['fromName'] = imap_mime_header_decode($head['fromName'])[0]->text;
         $model->subject = $head['subject'];
         $model->sender = $head['from'];
         //            echo $i.$head['date']."</br>";
         //            echo $i.strtotime($head['date'])."</br>";
         //            echo $i.date("Y-m-d H:i:s",strtotime($head['date']))."</br>";
         $model->sendtime = date("Y-m-d H:i:s", strtotime($head['date']));
         $model->text = $obj->getBody($i);
         //            $model->sendtime=$head['date'];
         $model->save();
         //            echo $i.$head['date'];
     }
     $obj->close_mailbox();
 }
 public function get($id, $elequent)
 {
     $cacheKey = self::CACHE . $id;
     if ($elequent) {
         return Email::find($id);
     }
     $cachedData = \Cache::has($cacheKey);
     if (empty($cachedData)) {
         $email = Email::find($id);
         if (!empty($email)) {
             $email = $email->toArray();
             $email['updated_at'] = date('Y-m-d', strtotime($email['updated_at']));
             $email['created_at_formatted'] = date('Y-m-d', strtotime($email['created_at']));
             $email['updated_at_formatted'] = date('Y-m-d', strtotime($email['updated_at']));
             // unset($country['password']);
             //unset($country['code']);
             // Set data in cache
             \Cache::forever($cacheKey, $email);
             return $email;
         } else {
             return false;
         }
     } else {
         return \Cache::get($cacheKey);
     }
 }
 /**
  * Show the application dashboard to the user.
  *
  * @param  Request $request
  * @param  integer $id
  * @return Response
  */
 public function success(Request $request, $id = 0)
 {
     $email = Email::find($id);
     if ($email) {
         return view('users.dashboard.success')->withEmail($email);
     }
 }
Beispiel #6
0
 /**
  */
 public function send($id)
 {
     $query = Email::findOne($id);
     //var_dump($query->email);
     //var_dump($this->subject);$query = Email::findOne($id);
     //var_dump($this->body);
     //exit();
     return Yii::$app->mailer->compose()->setTo($query->email)->setFrom(Yii::$app->params['adminEmail'])->setSubject($this->subject)->setTextBody($this->body)->send();
 }
Beispiel #7
0
 public function changeStatus()
 {
     $query = Email::findOne($this->id);
     if ($query->status == 0) {
         return 'Не отправлялось';
     } elseif ($query->status == 1) {
         return 'Отправлено';
     } else {
         return 'Ошибка отправки';
     }
 }
 /**
  * @return Response
  */
 public function getPreview($id)
 {
     $email = Email::findOrFail($id);
     // Send emails
     $view = '';
     if ($email->is_plaintext) {
         $view = nl2br(e($email->template));
     } else {
         $view = $email->template;
     }
     return View::make('dashboard.emails.preview', ['email' => $email, 'view' => $view]);
 }
Beispiel #9
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Email::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'sent_date' => $this->sent_date, 'status' => $this->status]);
     $query->andFilterWhere(['like', 'email', $this->email]);
     return $dataProvider;
 }
Beispiel #10
0
 public function search($input)
 {
     $query = Email::query();
     $columns = Schema::getColumnListing('emails');
     $attributes = array();
     foreach ($columns as $attribute) {
         if (isset($input[$attribute]) and !empty($input[$attribute])) {
             $query->where($attribute, $input[$attribute]);
             $attributes[$attribute] = $input[$attribute];
         } else {
             $attributes[$attribute] = null;
         }
     }
     return [$query->get(), $attributes];
 }
    /**
     * Displays a single Organisation model.
     * @param string $id
     * @return mixed
     */
    public function actionConnect($code, $state)
    {
        $sql = "SELECT * FROM organisation WHERE SHA1(CONCAT(`id`, :salt, `name`)) = :state";
        $organisation = Organisation::findBySql($sql, [':salt' => 'jiejieugs9837', ':state' => $state])->one();
        if (\Yii::$app->user->isGuest) {
            return $this->redirect('/site/denied/');
        }
        $user = \Yii::$app->user->identity;
        if (!$user->admin && count($user->organisations) == 0) {
            return $this->redirect('/site/denied/');
        } else {
            if (!$user->admin) {
                $organisations = $user->organisations;
                foreach ($organisations as $org) {
                    if ($organisation->id == $org->id) {
                        break 2;
                    }
                }
                return $this->redirect('/site/denied');
            }
        }
        if (!empty($code)) {
            $token_request_body = array('grant_type' => 'authorization_code', 'client_id' => Yii::$app->params['stripeClientID'], 'code' => $code, 'client_secret' => Yii::$app->params['stripeSecretKey']);
            $req = curl_init('https://connect.stripe.com/oauth/token');
            curl_setopt($req, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($req, CURLOPT_POST, true);
            curl_setopt($req, CURLOPT_POSTFIELDS, http_build_query($token_request_body));
            curl_setopt($req, CURLOPT_SSL_VERIFYPEER, true);
            //curl_setopt($req, CURLOPT_CAINFO, '/home/web/tickets/cacert.pem');
            $respCode = curl_getinfo($req, CURLINFO_HTTP_CODE);
            $resp = json_decode(curl_exec($req), true);
            curl_close($req);
            $organisation = $this->findModel($organisation->id);
            $organisation->stripe_access_token = $resp['access_token'];
            $organisation->stripe_public_key = $resp['stripe_publishable_key'];
            $organisation->stripe_user_id = $resp['stripe_user_id'];
            $organisation->stripe_refresh_token = $resp['refresh_token'];
            $organisation->save();
            $organisation_test = Organisation::findOne($organisation->id);
            $result = $organisation_test->stripe_user_id ? "successful" : "unsuccessful";
            $founder = User::findOne(OrganisationMembers::findOne(['organisation_id' => $organisation->id, 'founder' => 1])->user_id);
            $email = new Email();
            $email->to_name = $founder->name;
            $email->to_email = $founder->email;
            $email->subject = "Authorisation Attempt";
            $email->body = <<<EOT
You tried to connect {$organisation->name} to Tixty. That was {$result}.

Tixty
EOT;
            $email->save();
            $email->send();
            $response = print_r($resp, true);
            $email = new Email();
            $email->to_name = $email->sender_name;
            $email->to_email = $email->sender_email;
            $email->subject = "Authorisation Attempt for {$organisation->name} {$result}";
            $email->body = <<<EOT
<pre>{$response}</pre>
EOT;
            $email->save();
            $email->send();
        }
        return $this->redirect('/organisation/view', ['id' => $organisation->id]);
    }
Beispiel #12
0
 private function send($method = 'post', $data = null)
 {
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, $this->url);
     curl_setopt($ch, CURLOPT_POST, 1);
     curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
     curl_setopt($ch, CURLOPT_HEADER, false);
     $file_contents = curl_exec($ch);
     curl_close($ch);
     $res = json_decode($file_contents);
     $opts = ['to' => $this->to, 'mail_type' => $this->mail_type, 'deliver_at' => date('Y-m-d H:i:s')];
     foreach ($res as $key => $val) {
         $opts[$key] = $val;
     }
     Email::create($opts);
     return $res;
 }
Beispiel #13
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getEmail()
 {
     return $this->hasOne(Email::className(), ['id' => 'email_id']);
 }
Beispiel #14
0
 /**
  * @param string $toEmail
  * @param string $subject
  * @param string $textPlain
  * @param string $textHtml
  *
  * @throws \Exception
  */
 public static function sendWithLog($toEmail, $subject, $textPlain, $textHtml = '')
 {
     $mailer = new static(\Yii::$app->params);
     $messageId = explode('@', \Yii::$app->params['mailFromEmail']);
     $messageId = uniqid() . '@' . $messageId[1];
     $exception = null;
     try {
         $message = $mailer->createMessage($subject, $textPlain, $textHtml, $messageId);
         $status = $mailer->send($message, $toEmail);
     } catch (\Exception $e) {
         $status = Email::STATUS_DELIVERY_ERROR;
         $exception = $e;
     }
     $obj = new Email();
     $obj->toEmail = $toEmail;
     $obj->subject = $subject;
     $obj->text = $textPlain;
     $obj->dateSent = date('Y-m-d H:i:s');
     $obj->status = $status;
     $obj->messageId = $messageId;
     $obj->save();
     if ($exception) {
         /** @var \Exception $exception */
         throw new \Exception($exception->getMessage());
     }
     if (YII_ENV == 'test') {
         \Yii::$app->session->setFlash('email', 'E-Mail sent to: ' . $toEmail);
     }
 }
                        <span class="title">&nbsp;&nbsp;收件箱</span>
                        
                        
                    </a>
                </li>
                <li>
                    <a href="<?php 
echo \yii\helpers\Url::toRoute(['site/undistribute', 'handle_status' => 0]);
?>
">
                        <i class="glyphicon glyphicon-remove-circle"></i>
                        <span class="title">&nbsp;&nbsp;待分发</span>
                        <span class="sr-only">(current)</span>
                        <?php 
use app\models\Email;
$count = Email::find()->where(['handle_status' => 0])->count();
if ($count > 0) {
    echo '<span class="badge pull-right">' . $count . '</span>';
}
?>
                    </a>
                </li>

                <li>
                    <a href="<?php 
echo \yii\helpers\Url::toRoute(['site/distributed', 'handle_status' => 1]);
?>
">
                        <i class="glyphicon glyphicon-ok-circle"></i>
                        <span class="title">&nbsp;&nbsp;已分发</span>
                    </a>
 protected function generateEmail()
 {
     $data = ['to' => '*****@*****.**', 'send_type' => 'queue', 'subject' => 'Test', 'html' => '<html></html>'];
     return Email::create($data);
 }
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     // Find email that are ready to be started
     $emails = Email::where('started', 0)->whereNotNull('scheduled_for')->where('scheduled_for', '<=', DB::RAW('NOW()'))->get();
     // set every email as started
     foreach ($emails as $email) {
         $email->started = 1;
         $email->save();
     }
     foreach ($emails as $email) {
         // Generate email list
         // To add more email list edit this file and `App/Models/Email.php
         $list = [];
         $students = [];
         $newcomers = [];
         switch ($email->list) {
             case Email::STUPRELISTE:
                 $list['*****@*****.**'] = ['name' => 'STUPRE-liste', 'user' => null];
                 break;
             case Email::VOLUNTEERS:
                 $students = Student::where('volunteer', 1)->get();
                 break;
             case Email::CE_VALIDATED:
                 $students = Student::where('ce', 1)->whereNotNull('team_id')->where('team_accepted', 1)->get();
                 break;
             case Email::REFERRALS_VALIDATED:
                 $students = Student::where('referral', 1)->where('referral_validated', 1)->get();
                 break;
             case Email::REFERRALS_INCOMPLETE:
                 $students = Student::where('referral', 1)->where('referral_validated', 0)->where(function ($query) {
                     $query->where('phone', '')->orWhereNull('phone')->orWhere('email', '')->orWhereNull('email')->orWhere('referral_text', '')->orWhereNull('referral_text');
                 })->get();
                 break;
             case Email::REFERRALS_VALIDATED_BRANCH:
                 $students = Student::where('referral', 1)->where('referral_validated', 1)->where('branch', '<>', 'tc')->get();
                 break;
             case Email::REFERRALS_VALIDATED_TC:
                 $students = Student::where('referral', 1)->where('referral_validated', 1)->where('branch', '=', 'tc')->get();
                 break;
             case Email::ORGA:
                 $students = Student::where('orga', 1)->get();
                 break;
             case Email::ADMIN:
                 $students = Student::where('admin', 100)->get();
                 break;
             case Email::NEWCOMERS_ALL:
                 $newcomers = Newcomer::all();
                 break;
             case Email::NEWCOMERS_ALL_TC:
                 $newcomers = Newcomer::where('branch', 'TC')->get();
                 break;
             case Email::NEWCOMERS_ALL_BRANCH:
                 $newcomers = Newcomer::where('branch', '<>', 'TC')->where('branch', '<>', 'MP')->get();
                 break;
             case Email::NEWCOMERS_ALL_MASTER:
                 $newcomers = Newcomer::where('branch', 'MP')->get();
                 break;
             case Email::NEWCOMERS_FILLED:
                 $newcomers = Newcomer::where('email', '<>', '')->whereNotNull('email')->get();
                 break;
             case Email::NEWCOMERS_FILLED_TC:
                 $newcomers = Newcomer::where('branch', 'TC')->where('email', '<>', '')->whereNotNull('email')->get();
                 break;
             case Email::NEWCOMERS_FILLED_BRANCH:
                 $newcomers = Newcomer::where('branch', '<>', 'TC')->where('branch', '<>', 'MP')->where('email', '<>', '')->whereNotNull('email')->get();
                 break;
             case Email::NEWCOMERS_FILLED_MASTER:
                 $newcomers = Newcomer::where('branch', 'MP')->where('email', '<>', '')->whereNotNull('email')->get();
                 break;
             default:
                 echo 'Error : Unknown email list id';
                 break;
         }
         // Select email to put in the list
         foreach ($students as $student) {
             $list[$student->email] = ['name' => $student->first_name . ' ' . $student->last_name, 'user' => $student];
         }
         foreach ($newcomers as $newcomer) {
             if (!empty($newcomer->email)) {
                 $list[$newcomer->email] = ['name' => $newcomer->first_name . ' ' . $newcomer->last_name, 'user' => $newcomer];
             } elseif (!empty($newcomer->registration_email)) {
                 $list[$newcomer->registration_email] = ['name' => $newcomer->first_name . ' ' . $newcomer->last_name, 'user' => $newcomer];
             }
         }
         // Set count in db
         $email->done = 0;
         $email->total = count($list);
         $email->save();
         // Send emails
         $delay = 0;
         foreach ($list as $dest => $val) {
             $this->currentUser = $val['user'];
             $view = $email->template;
             if ($email->is_plaintext) {
                 $view = preg_replace_callback('/{{([A-Z0-9_]+)}}/i', array($this, 'replaceCallback'), $view);
                 $view = nl2br(e($view));
             } else {
                 $view = preg_replace_callback('/{{([A-Z0-9_]+)}}/i', array($this, 'replaceCallback'), $view);
             }
             $job = new SendEmail($email, $view, $dest, $val['name']);
             $job->delay($delay);
             $this->dispatch($job);
             $delay += 5;
         }
     }
 }
Beispiel #18
0
 /**
  * Save a new Email model and return the instance.
  *
  * @access protected
  * @param  Request $request
  * @return Email|null - en caso de error.
  */
 protected function newEmail(Request $request)
 {
     $email = null;
     try {
         DB::beginTransaction();
         $email = Email::create(['stand' => $request->get('stand'), 'empresa' => $request->get('empresa'), 'email' => $request->get('email'), 'telefono' => $request->get('telefono'), 'mensaje' => $request->get('mensaje'), 'plantilla_id' => $request->get('plantilla'), 'usuario_id' => auth()->user()->id]);
         if ($email->save() === true) {
             $email->logotipo = $this->saveImage($request->file('logotipo'), $email->id);
             $email->contactos()->saveMany($this->contactos($request->get('contactos')));
             $email->save();
         }
         DB::commit();
     } catch (Exception $e) {
         DB::rollBack();
         Log::error($e);
         $email = null;
     }
     return $email;
 }
 /**
  * Finds the Email model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Email the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Email::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
    public function actionSave()
    {
        $session = new Session();
        $user = Yii::$app->user->identity;
        $cart = Cart::getCurrentCart();
        $cart->processCart();
        if ($cart->total > 0) {
            return $this->actionCharge();
        }
        $cart->status = Cart::CART_SOLD;
        $cart->save();
        $session->addSuccess(Yii::t('app', 'Congratulations, you\'ve completed your order!'));
        $cart_lines = [];
        foreach ($cart->items as $item) {
            $cart_lines[] = $item->ticket->group->event->name . ': ' . $item->ticket->name . ' x' . $item->quantity . ' @ ' . $item->ticket->ticket_price . ' each';
        }
        $cart_details = implode("\n", $cart_lines);
        $email = new Email();
        $email->to_name = $user->name;
        $email->to_email = $user->email;
        $email->subject = "Your Tixty Purchase";
        $message = <<<EOT
Hi {$user->name}!!

You just bought {$cart->quantity} tickets for a total of {$cart->total} - details below.

Thanks,

Tixty

---
{$cart_details}
EOT;
        $email->body = nl2br($message);
        $email->save();
        $email->send();
        $email = new Email();
        $email->to_name = "Tixty";
        $email->to_email = \Yii::$app->params['adminEmail'];
        $email->subject = "Tixty Purchase #{$cart->id}";
        $message = <<<EOT
{$user->name} just bought {$cart->quantity} tickets for a total of {$cart->total} - details below.

Tixty

---
{$cart_details}
EOT;
        $email->body = nl2br($message);
        $email->save();
        $email->send();
        return $this->redirect('index');
    }
Beispiel #21
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getEmails()
 {
     return $this->hasMany(Email::className(), ['user_id' => 'id']);
 }
 public function actionReceiver()
 {
     $model = new Receive();
     error_reporting(E_ALL || ~E_WARNING || ~E_NOTICE);
     $mailaccount = setting::find()->one();
     $user = $mailaccount->user;
     $password = $mailaccount->password;
     $username = $mailaccount->username;
     $receivehost = $mailaccount->receivehost;
     $receiveapply = "imap";
     $receiveport = $mailaccount->receiveport;
     $obj = new receiveMail($user, $password, $username, $receivehost, $receiveapply, $receiveport, 'ture');
     $obj->connect();
     $tot = $obj->getTotalMails();
     //查看邮箱是否有新邮件
     $old_email_count = Email::find()->count();
     for ($i = $tot; $i > $old_email_count; $i--) {
         $model = new Receive();
         $head = $obj->getHeaders($i);
         $head['subject'] = imap_mime_header_decode($head['subject'])[0]->text;
         $head['from'] = imap_mime_header_decode($head['from'])[0]->text;
         $head['fromName'] = imap_mime_header_decode($head['fromName'])[0]->text;
         $text = $obj->getBody($i);
         $encode = mb_detect_encoding($text, array("ASCII", "UTF-8", "GB2312", "GBK", "BIG5", "EUC-CN"));
         if ($encode == "EUC-CN") {
             $encode = "GB2312";
         }
         if ($encode != "UTF-8") {
             $text = iconv("{$encode}", "UTF-8", $text);
         }
         $model->text = $text;
         $attachments = $obj->GetAttach($i, "../attachment/receiveattachment");
         $attach = "";
         if ($attachments != "") {
             $attach = $attachments;
             $encode = mb_detect_encoding($attachments, array("ASCII", "UTF-8", "GB2312", "GBK", "BIG5", "EUC-CN"));
             if ($encode == "EUC-CN") {
                 $encode = "GB2312";
             }
             if ($encode != "UTF-8") {
                 $attach = iconv("{$encode}", "UTF-8", $attachments);
             }
         }
         $model->subject = $head['subject'];
         $model->sender = $head['from'];
         $model->sendtime = date("Y-m-d H:i:s", strtotime($head['date']));
         $model->attachment = $attach;
         $model->save();
     }
     $obj->close_mailbox();
 }