Exemplo n.º 1
1
 public function register()
 {
     $user = new Users();
     $user->attributes = $this->attributes;
     $salt = md5(uniqid() . time());
     $user->email = $this->email;
     $user->salt = $salt;
     $user->pass = crypt(trim($this->pass) . $salt);
     if ($user->validate() && $user->save()) {
         if (!Settings::model()->getValue('mail_confirm')) {
             $user->status = 1;
             $user->save();
             return 1;
         }
         Yii::import('ext.YiiMailer.YiiMailer');
         $code = md5(md5($user->pass . $user->email));
         $mail = new YiiMailer();
         $mail->setFrom(Settings::model()->getValue('register'));
         $mail->setTo($user->email);
         $mail->setSubject(Yii::t('register', 'Account activation'));
         $mail->setBody(Yii::t('register', "Hello {nick},<br/><br/>Your activation code: {code}<br/>{link}", array('{nick}' => $user->nick, '{code}' => $code, '{link}' => Yii::app()->createAbsoluteUrl('site/confirm', array('user' => $user->nick, 'code' => $code)))));
         $mail->send();
         return 1;
     }
 }
 /**
  * Displays the contact page
  */
 public function actionContact()
 {
     $model = new ContactForm();
     if (isset($_POST['ContactForm'])) {
         $model->attributes = $_POST['ContactForm'];
         if ($model->validate()) {
             //use 'contact' view from views/mail
             $mail = new YiiMailer('contact', array('message' => $model->body, 'name' => $model->name, 'description' => 'Contact form'));
             //render HTML mail, layout is set from config file or with $mail->setLayout('layoutName')
             $mail->render();
             //set properties as usually with PHPMailer
             $mail->From = $model->email;
             $mail->FromName = $model->name;
             $mail->Subject = $model->subject;
             $mail->AddAddress(Yii::app()->params['adminEmail']);
             //send
             if ($mail->Send()) {
                 $mail->ClearAddresses();
                 Yii::app()->user->setFlash('contact', 'Thank you for contacting us. We will respond to you as soon as possible.');
             } else {
                 Yii::app()->user->setFlash('error', 'Error while sending email: ' . $mail->ErrorInfo);
             }
             $this->refresh();
         }
     }
     $this->render('contact', array('model' => $model));
 }
Exemplo n.º 3
0
 /**
  * Provides ability to change password and email address.
  * If user want to change email it will be changed after confirmation of
  * new email address.
  * 
  * @throws CException
  */
 public function actionEdit()
 {
     $identity = Identity::model()->findByAttributes(array('user_id' => Yii::app()->user->id));
     $newPassword = new ChangePasswordForm();
     if ($this->request->isPostRequest) {
         if ($identity->identity !== $_POST['Identity']['identity']) {
             $newEmail = $_POST['Identity']['identity'];
             $storedIdentity = clone $identity;
             $identity->identity = $newEmail;
         }
         $newPassword->attributes = $_POST['ChangePasswordForm'];
         $isFormValid = $newPassword->validate();
         if ($isFormValid && $newEmail) {
             $isFormValid = $identity->validate();
         }
         if ($isFormValid && isset($newEmail)) {
             $identity->status = Identity::STATUS_NEED_CONFIRMATION;
             $identity->isNewRecord = true;
             $identity->id = null;
             $identity->save();
             $confirmation = $identity->startConfirmation(IdentityConfirmation::TYPE_EMAIL_REPLACE_CONFIRMATION);
             $activationUrl = $this->createAbsoluteUrl($this->module->confirmationUrl, array('key' => $confirmation->key));
             $email = new YiiMailer('changeEmail', $data = array('activationUrl' => $activationUrl, 'description' => $description = 'Email change confirmation'));
             $email->setSubject($description);
             $email->setTo($identity->identity);
             $email->setFrom(Yii::app()->params['noreplyAddress'], Yii::app()->name, FALSE);
             Yii::log('Sendign email change confirmation to ' . $identity->identity . ' with data: ' . var_export($data, true));
             // @TODO: catch mailing exceptions here, to give user right messages
             if ($email->send()) {
                 Yii::log('Ok');
             } else {
                 Yii::log('Failed');
                 throw new CException('Failed to send the email');
             }
             Yii::app()->user->setFlash('info', 'Your new email will be applied after confirmation. Please, check this email address ' . $newEmail . '. You should get confirmation mail there.');
         }
         if ($isFormValid) {
             $user = $identity->userAccount;
             if ($newPassword->password && !$user->passwordEquals($newPassword->password)) {
                 $user->setPassword($newPassword->password);
                 $user->save();
                 Yii::app()->user->setFlash('success', 'Password has been changed successfully');
             }
         }
         if ($isFormValid) {
             $this->redirect(array($this->module->afterIdentityEditedUrl));
         }
     }
     $this->render('edit', array('identity' => $identity, 'newPassword' => $newPassword));
 }
Exemplo n.º 4
0
 /**
  * Runs after user's records were created in the database. Contains logic
  * for sending activation mail. 
  * 
  * @param СEvent $event
  * @throws CException
  */
 protected function afterRecordsCreated($event)
 {
     $identity = $event->params['identity'];
     $confirmation = $identity->startConfirmation();
     $activationUrl = $this->createAbsoluteUrl($this->module->activationUrl, array('key' => $confirmation->key));
     $email = new YiiMailer('activation', $data = array('activationUrl' => $activationUrl, 'description' => $description = 'Account activation'));
     $email->setSubject($description);
     $email->setTo($identity->identity);
     $email->setFrom(Yii::app()->params['noreplyAddress'], Yii::app()->name, FALSE);
     Yii::log('Sendign activation mail to ' . $identity->identity . ' with data: ' . var_export($data, true));
     if ($email->send()) {
         Yii::log('Ok');
     } else {
         Yii::log('Failed');
         throw new CException('Failed to send the email');
     }
 }
 public function processSurveys(array $surveys)
 {
     foreach ($surveys as $survey) {
         if ($survey->surveyInfo == null) {
             $info = new SurveyInfo();
             $info->surveyId = $survey->sid;
             $info->surveyType = $survey->location;
             $survey->surveyInfo = $info;
         }
         if ($survey->surveyInfo->isActive == null) {
             $survey->surveyInfo->isActive = $survey->isActive();
             $survey->surveyInfo->save();
         } else {
             if ($survey->surveyInfo->isActive && $survey->surveyInfo->isActive != $survey->isActive()) {
                 $attachedFiles = AttachedFile::model()->findAllByAttributes(array('fileType' => AttachedFile::FILE_TYPE_FULL_ANALYTICS, 'modelId' => $survey->sid, 'modelType' => get_class($survey)));
                 $linksToFiles = array();
                 $filesToAttachment = array();
                 foreach ($attachedFiles as $file) {
                     if ($file->attachType == AttachedFile::ATTACH_TYPE_LINK) {
                         $linksToFiles[$file->filePath] = $file->name;
                     } elseif ($file->attachType == AttachedFile::ATTACH_TYPE_FILE) {
                         $filesToAttachment[$file->filePath] = $file->fileName;
                     }
                 }
                 $exportHelper = new ExcelExportSurveyHelper($survey);
                 $res = $exportHelper->export();
                 if ($res != null) {
                     $excelFilepath = "/tmp/" . md5(time() . "_" . $survey->sid . "_" . $survey->location) . '.xls';
                     file_put_contents($excelFilepath, $res['content']);
                     $filesToAttachment[$excelFilepath] = 'Массив данных в Excel.xls';
                 }
                 $mail = new YiiMailer();
                 $mail->setFrom(Yii::app()->params['adminEmail'], 'Администраток ЛК');
                 $mail->setTo(Yii::app()->params['adminEmail']);
                 $mail->setSubject('Опрос перешёл в список завершённых.');
                 $mail->setView('surveyChangeActivity');
                 $mail->setData(array('survey' => $survey, 'linksToFiles' => $linksToFiles));
                 $mail->setAttachment($filesToAttachment);
                 echo "[" . date("Y-m-d H:i:s") . "]  try to send mail\n";
                 if (!$mail->send()) {
                     echo "[" . date("Y-m-d H:i:s") . "]  fail \n";
                     print_r($mail->getError());
                     echo PHP_EOL;
                 }
                 $survey->surveyInfo->isActive = $survey->isActive();
                 $survey->surveyInfo->save();
             }
         }
     }
 }
 public function actionDecline($id)
 {
     if (!($model = Invite::model()->findByPk($id)) || !in_array($model->status, [Invite::INVITE_CREATE, Invite::INVITE_ACCEPT])) {
         throw new CHttpException(404);
     }
     if ($model->status == Invite::INVITE_CREATE) {
         $mail = new YiiMailer();
         $mail->setView('invite/decline');
         $mail->setFrom(isset(Yii::app()->params->YiiMailer->Username) ? Yii::app()->params->YiiMailer->Username : Yii::app()->params->adminEmail, 'Система управления учебным расписанием');
         $mail->setTo($model->email);
         $mail->setSubject('Заявка на создание');
         $mail->send();
         if (!$mail->send()) {
             Yii::app()->user->setFlash('error', 'Ошибка при отправке письма');
             $this->redirect(['index']);
         }
     }
     $model->status = Invite::INVITE_DECLINE;
     if ($model->save()) {
         Yii::app()->user->setFlash('success', 'Заявка успешно отклонена');
     } else {
         Yii::app()->user->setFlash('error', 'Ошибка при смене статуса');
     }
     $this->redirect(['index']);
 }
 public function actionForgot()
 {
     $model = new ForgotPasswordForm();
     if (isset($_POST['ForgotPasswordForm'])) {
         $model->attributes = $_POST['ForgotPasswordForm'];
         //$this->refresh();
         if ($model->validate()) {
             $tempPassword = Randomness::randomString(16, true);
             $model = User::model()->findByAttributes(array('email' => $model->email));
             $model->isNewPassword = true;
             $model->password = $tempPassword;
             if ($model->save()) {
                 //use 'passwordrest' view from views/mail
                 $mail = new YiiMailer('passwordReset', array('tempPassword' => $tempPassword));
                 //$mail->setSmtp('smtp.gmail.com', 465, 'ssl', true, '*****@*****.**', 'your_password');
                 //render HTML mail, layout is set from config file or with $mail->setLayout('layoutName')
                 //$mail->render();smtp.secureserver.net
                 $mail->IsSMTP();
                 $mail->Host = 'smtp.teksavvy.com';
                 //$mail->SMTPAuth = true;
                 //$mail->Host = 'smtpout.secureserver.net';
                 $mail->Port = 25;
                 //$mail ->Username ='******';
                 //$mail -> Password ='******';
                 //set properties as usually with PHPMailer
                 $mail->From = Yii::app()->params['nonReplyEmail'];
                 $mail->FromName = Yii::app()->name;
                 $mail->Subject = Yii::app()->name . ' - Password Reset';
                 $mail->AddAddress(YII_DEBUG ? Yii::app()->params['adminEmail'] : $model->email);
                 //$mail->AddAddress(YII_DEBUG?Yii::app()->params['adminEmail']);
                 //$mail->AddAddress('*****@*****.**');
                 //send
                 if ($mail->Send()) {
                     $mail->ClearAddresses();
                     Yii::app()->user->setFlash('success-', Yii::t('app', 'msg.success.password_reset'));
                 } else {
                     Yii::app()->user->setFlash('error-', 'Error while sending email: ' . $mail->ErrorInfo);
                 }
                 $this->refresh(true);
             }
         }
     }
     $this->render('application.modules.account.views.common.forgot', array('model' => $model));
 }
Exemplo n.º 8
0
 public static function sendRecoveryPasswordEmail($user, $newPassword)
 {
     $mail = new YiiMailer();
     $mail->setLayout('mail');
     $mail->setView('recoveryPassword');
     $mail->setData(array('administrator' => $user, 'new_password' => $newPassword));
     $mail->setFrom('*****@*****.**', Yii::app()->params['SITE_NAME']);
     $mail->setTo($user->username);
     $mail->setSubject(Yii::t(Yii::app()->params['TRANSLATE_FILE'], 'Instruction to recovery password from ' . Yii::app()->params['SITE_NAME'] . ' system'));
     if ($mail->send()) {
         return null;
     } else {
         return $mail->getError();
     }
 }
Exemplo n.º 9
0
    public function actionUusi_tuote()
    {
        $model = new Viivakoodi();
        $this->performAjaxValidation($model);
        if (isset($_POST['Viivakoodi'])) {
            $model->attributes = $_POST['Viivakoodi'];
            if (isset($_POST['tuoteen_tyyppi'])) {
                $model->tuoteen_tyyppi = implode("//", $_POST['tuoteen_tyyppi']);
            }
            if ($model->save()) {
                Yii::app()->user->setState('UusiEsikatselu', null);
                $sahkopostinSisalto = ' Hyväksymällä tuotteen se näytetään kaikille. <br>
			<p><a href="' . Yii::app()->request->baseUrl . '/index.php/viivakoodi/update?id=' . $model->id . '">Muokkaa</a></p>';
                if (!$this->onkoSuperAdmin()) {
                    $mail = new YiiMailer();
                    $asetukset = Asetukset::model()->findbypk(1);
                    //$mail->clearLayout();//if layout is already set in config
                    $mail->setFrom('*****@*****.**', 'MIINUS.FI');
                    $mail->setTo($asetukset->admin_mail);
                    $mail->setSubject('Uusi tuote on lisätty. ID-' . $model->id);
                    $mail->setBody($sahkopostinSisalto);
                    $mail->send();
                }
                $this->redirect(array('/site/ruoka_paivakirja'));
            } else {
                var_dump($model->getErrors());
            }
        }
        $this->render('uusi_tuote', array('model' => $model, 'state' => Yii::app()->user->UusiEsikatselu));
    }
Exemplo n.º 10
0
 public function register()
 {
     if (!$this->validate()) {
         return false;
     }
     $user = new User();
     $user->setFullName($this->fio);
     $user->username = $this->email;
     $user->email = $this->email;
     $user->password = md5($this->password);
     $user->passwordConfirm = md5($this->passwordConfirmation);
     $user->organizationName = $this->organizationName;
     $user->organizationPhone = $this->organizationPhone;
     $user->mobilePhone = $this->mobilePhone;
     $user->isKnownFromSearch = $this->isKnownFromSearch;
     $user->isKnownFromRecommendation = $this->isKnownFromRecommendation;
     $user->isKnownFromInetAdvert = $this->isKnownFromInetAdvert;
     $user->isKnownFromMaps = $this->isKnownFromMaps;
     $user->isKnownFromOther = $this->isKnownFromOther;
     if (!$user->save()) {
         return false;
     }
     $auth = Yii::app()->authManager;
     $defaultRole = $auth->getAuthItem(User::DEFAULT_ROLE);
     if ($defaultRole) {
         $auth->assign(User::DEFAULT_ROLE, $user->id);
     }
     $mail = new YiiMailer();
     $mail->setFrom(Yii::app()->params['noReplyEmail']);
     $mail->setTo(Yii::app()->params['notificationEmail']);
     $mail->setSubject('Заявка на регистрацию нового пользователя');
     $mail->setView('userRegistration');
     $mail->setData(array('user' => $user));
     if (!$mail->send()) {
         error_log('Cannot send email about registered user: ' . $mail->getError());
     }
     return true;
 }
Exemplo n.º 11
0
    /**
     * Updates a particular model.
     * If update is successful, the browser will be redirected to the 'view' page.
     */
    public function actionEdit()
    {
        $model = $this->loadUser();
        $profile = $model->profile;
        // ajax validator
        if (isset($_POST['ajax']) && $_POST['ajax'] === 'profile-form') {
            echo UActiveForm::validate(array($model, $profile));
            Yii::app()->end();
        }
        if (isset($_POST['User'])) {
            // Uusi myyja
            if (isset(Yii::app()->user->myyja) and $model->hyvaksy_hylka_kirje == 0) {
                $message = 'Uusi myyjä on rekisteröitynyt sähköposti osoitteella ' . $model->email . ':<br>
		 <a href="http://' . $_SERVER['HTTP_HOST'] . '/index.php/site/uusi_myyja?tila=1&id=' . $model->id . '&code=' . $model->myyja_vahvistus . '">Hyväksy myyjä</a>
		 <a href="http://' . $_SERVER['HTTP_HOST'] . '/index.php/site/uusi_myyja?tila=0&id=' . $model->id . '&code=' . $model->myyja_vahvistus . '">Hylkää myyjä</a>';
                $asetukset = Asetukset::model()->findbypk(1);
                $mail = new YiiMailer();
                $mail->setFrom('*****@*****.**', 'MIINUS.FI');
                $mail->setTo($asetukset->admin_mail);
                $mail->setSubject('Uusi myyjä');
                $mail->setBody($message);
                $mail->send();
                $model->hyvaksy_hylka_kirje = 1;
            }
            // Uusi myyja
            if (isset(Yii::app()->user->myyja)) {
                $_POST['Profile']['sukupuoli'] = 1;
                $_POST['Profile']['muokkaa_energia_suositusta'] = 1;
                $_POST['Profile']['ppkkvvvv'] = '---';
                $_POST['Profile']['tavoitepaino'] = '---';
            } else {
                $_POST['Profile']['pankkitilinumero'] = '---';
                $_POST['Profile']['nayttonimi'] = '---';
                $_POST['Profile']['bic_koodi'] = '---';
                $_POST['Profile']['alv_velvollinen'] = 1;
            }
            $model->attributes = $_POST['User'];
            $profile->attributes = $_POST['Profile'];
            if ($model->validate() && $profile->validate()) {
                $model->save();
                $profile->save();
                Yii::app()->user->updateSession();
                //Yii::app()->user->setFlash('profileMessage',UserModule::t("Changes is saved."));
                if (isset(Yii::app()->user->myyja)) {
                    $this->redirect(Yii::app()->request->baseUrl . '/index.php/site/myyja');
                } else {
                    $this->redirect(Yii::app()->request->baseUrl . '/index.php/site/ruoka_paivakirja');
                }
            } else {
                $profile->validate();
            }
        }
        if (isset(Yii::app()->user->myyja)) {
            $this->render('edit_myyja', array('model' => $model, 'profile' => $profile));
        } else {
            $this->render('edit', array('model' => $model, 'profile' => $profile));
        }
    }
Exemplo n.º 12
0
 public function send()
 {
     $mailer = new YiiMailer();
     $maildata = $this->args;
     if ($this->view) {
         $mailer->setView($this->view);
     }
     $mailer->setData($maildata);
     $mailer->setFrom($this->from, $this->fromUser);
     $mailer->setTo($this->to);
     $mailer->setSubject($this->subject);
     $mailer->setBody($this->body);
     $sent = $mailer->send();
     if ($sent) {
         return array('status' => true, 'error' => '');
     } else {
         return array('status' => false, 'error' => $mailer->getError());
     }
 }
Exemplo n.º 13
0
 public static function sendEmail($subject, $to_email, $body, $from_email, $from_name)
 {
     $mail = new YiiMailer();
     $mail->setView('confirm');
     $mail->setData(array('data' => $body));
     $mail->setFrom($from_email, $from_name);
     $mail->setSubject($subject);
     $mail->setTo($to_email);
     if ($mail->send()) {
         return TRUE;
     }
     return FALSE;
 }
Exemplo n.º 14
0
 public function run($args)
 {
     //Do some cron processing...
     $cronResult = "Cron job finished successfuly";
     $mail = new YiiMailer();
     //use "cron" view from views/mail
     $mail->setView('cron');
     $mail->setData(array('message' => $cronResult, 'name' => get_class($this), 'description' => 'Cron job', 'mailer' => $mail));
     //set properties
     $mail->setFrom('*****@*****.**', 'Console application');
     $mail->setSubject($cronResult);
     $mail->setTo('*****@*****.**');
     $mail->setAttachment(Yii::getPathOfAlias('webroot.files') . '/yii-1.1.0-validator-cheatsheet.pdf');
     //if you want to use SMTP, configure it in config file or use something like:
     $mail->setSmtp('smtp.gmail.com', 465, 'ssl', true, '*****@*****.**', 'your_password');
     // GMail example
     //send
     if ($mail->send()) {
         echo 'Mail sent successfuly';
     } else {
         echo 'Error while sending email: ' . $mail->getError();
     }
     echo PHP_EOL;
 }
Exemplo n.º 15
0
 public function sendMailSorry($email)
 {
     try {
         $this->title = "Mail test";
         $mail = new YiiMailer();
         $mail->setView('sorry');
         $mail->setFrom('*****@*****.**', 'John Doe');
         $mail->setSubject('Confirm your order');
         $mail->setTo($email);
         $mail->send();
         var_dump($mail->getError());
     } catch (Exception $e) {
         var_dump($e->getMessage());
     }
 }
Exemplo n.º 16
0
 public function afterSave()
 {
     if ($this->getScenario() == 'insert') {
         $user = Users::model()->findByAttributes(['email' => $this->email]);
         if (!$user) {
             $group = Group::model()->findByPk($this->group_id);
             $mail = new YiiMailer();
             $mail->setView('invite');
             $mail->setData(array('group' => $group, 'hash' => $this->hash));
             $mail->setFrom(isset(Yii::app()->params->YiiMailer->Username) ? Yii::app()->params->YiiMailer->Username : Yii::app()->params->adminEmail, 'Система управления учебным расписанием');
             $mail->setTo($this->email);
             $mail->setSubject('Приглашение');
             $mail->send();
         }
     }
 }
Exemplo n.º 17
0
 private function email_report($email, $message)
 {
     $data = array('message' => $message, 'name' => $email, 'email' => $email, 'description' => 'Echofish Report');
     $mail = new YiiMailer('report_attachment', $data);
     $mail->IsSMTP();
     $mail->SMTPAuth = false;
     //set properties
     $mail->setFrom(Yii::app()->params['adminEmail'], 'Echofish');
     $mail->setSubject("Echofish Report");
     $mail->setTo($email);
     if (!$mail->send()) {
         var_dump($mail->ErrorInfo);
     }
 }
Exemplo n.º 18
0
 public function actionIndex()
 {
     $form = new FeedbackForm();
     if (Yii::app()->request->isPostRequest) {
         $params = Yii::app()->request->getParam('FeedbackForm');
         $form->setAttributes($params);
         if ($form->validate()) {
             $mail = new YiiMailer();
             $mail->setView('feedback');
             $mail->setData(['form' => $form]);
             $mail->setFrom($form->email, $form->name);
             $mail->setReplyTo($form->email);
             $mail->setTo(Yii::app()->params->adminEmail);
             $mail->setSubject('Система расписания: ' . $form->subject);
             if ($mail->send()) {
                 Yii::app()->user->setFlash('success', 'Ваше сообщение отправлено, спасибо!');
                 $form->unsetAttributes();
             } else {
                 Yii::app()->user->setFlash('error', 'Ошибка при отправке');
             }
         }
     }
     $this->render('index', ['model' => $form]);
 }
Exemplo n.º 19
0
 public static function emailStudentActivation($user, $hash)
 {
     $student = Student::model()->with('college', 'program', 'educationLevel')->findByPk($user->user_id);
     $mail = new YiiMailer('studentActivation', array('student' => $student, 'user' => $user, 'hash' => $hash));
     $mail->render();
     $mail->From = Yii::app()->params['nonReplyEmail'];
     $mail->FromName = Yii::app()->name;
     $mail->Subject = Yii::app()->name . ' - Student account verification';
     $mail->AddAddress(YII_DEBUG ? Yii::app()->params['adminEmail'] : $user->email);
     if ($mail->Send()) {
         $mail->ClearAddresses();
         Yii::log("Mail sent via " . Yii::app()->params['nonReplyEmail'], 'log');
         Yii::log("Mail sent successfully to " . (YII_DEBUG ? Yii::app()->params['adminEmail'] : $user->email), 'log');
         return true;
     } else {
         Yii::log("Email error: " . $mail->getError(), 'log');
         return false;
     }
 }
Exemplo n.º 20
0
 public function generarToken()
 {
     $a = array('correo' => $this->correo, 'estado' => 1);
     $validar = Usuario::model()->findByAttributes($a);
     if ($validar) {
         $token = md5('tm' . $this->correo . (rand() + time()) . 'TM');
         $validar->updateByPk($validar->id, array('llave_activacion' => $token, 'estado' => 3));
         $mail = new YiiMailer();
         $mail->setView('recuperar-clave');
         $mail->setData(array('token' => $token));
         $mail->render();
         $mail->Subject = 'Recupera tu contraseña de puntos TM';
         $mail->AddAddress($this->correo);
         $mail->From = '*****@*****.**';
         $mail->FromName = 'Puntos TM';
         $mail->Send();
     }
     return true;
 }
Exemplo n.º 21
0
 public function afterSave()
 {
     if ($this->getIsNewRecord()) {
         $admins = array_map(function ($user) {
             /** @var Users $user */
             return $user->email;
         }, array_filter(Users::model()->findAll(), function ($user) {
             /** @var Users $user */
             return in_array('admin', array_keys($user->groups));
         }));
         $mail = new YiiMailer();
         $mail->setView('invite/new');
         $mail->setFrom(isset(Yii::app()->params->YiiMailer->Username) ? Yii::app()->params->YiiMailer->Username : Yii::app()->params->adminEmail, 'Система управления учебным расписанием');
         $mail->setTo($admins);
         $mail->setSubject('Новая заявка');
         $mail->send();
     }
     return parent::afterSave();
 }
Exemplo n.º 22
0
 public function run($args)
 {
     //Do some cron processing...
     $cronResult = "Cron job finished successfuly";
     $mail = new YiiMailer();
     //use "cron" view from views/mail
     $mail->setView('cron');
     $mail->setData(array('message' => $cronResult, 'name' => get_class($this), 'description' => 'Cron job', 'mailer' => $mail));
     //render HTML mail, layout is set from config file or with $mail->setLayout('layoutName')
     $mail->render();
     //set properties as usually with PHPMailer
     $mail->From = '*****@*****.**';
     $mail->FromName = 'Console application';
     $mail->Subject = $cronResult;
     $mail->AddAddress('*****@*****.**');
     //send
     if ($mail->Send()) {
         $mail->ClearAddresses();
         echo 'Mail sent successfully';
     } else {
         echo 'Error while sending email: ' . $mail->ErrorInfo;
     }
     echo PHP_EOL;
 }
Exemplo n.º 23
0
 /**
  * Displays the contact page
  */
 public function actionContact()
 {
     $model = new ContactForm();
     if (Yii::app()->request->isPostRequest) {
         $model->attributes = Yii::app()->request->getPost('ContactForm');
         if ($model->validate()) {
             $mail = new YiiMailer('contact', array('message' => $model->body, 'name' => $model->name, 'phone' => $model->phone, 'description' => Yii::t('site', 'Contact form')));
             $mail->setFrom($model->email, $model->name);
             $mail->setSubject(Yii::t('site', 'Контактная форма'));
             $mail->setTo('*****@*****.**');
             if ($mail->send()) {
                 Yii::app()->user->setFlash('success', Yii::t('site', 'Thank you for contacting us. We will respond to you as soon as possible.'));
                 $this->refresh();
             } else {
                 Yii::app()->user->setFlash('danger', $mail->getError());
                 //                    Yii::app()->user->setFlash('danger', Yii::t('site', 'Something went wrong, please, try again later'));
             }
         }
     }
     $this->render('contact', array('model' => $model));
 }
Exemplo n.º 24
0
 /**
  * Displays the contact page
  */
 public function actionContact()
 {
     $model = new ContactForm();
     if (isset($_POST['ContactForm'])) {
         $model->attributes = $_POST['ContactForm'];
         if ($model->validate()) {
             //use 'contact' view from views/mail
             $mail = new YiiMailer('contact', array('message' => $model->body, 'name' => $model->name, 'description' => 'Contact form'));
             //set properties
             $mail->setFrom($model->email, $model->name);
             $mail->setSubject($model->subject);
             $mail->setTo(Yii::app()->params['adminEmail']);
             //send
             if ($mail->send()) {
                 Yii::app()->user->setFlash('contact', 'Thank you for contacting us. We will respond to you as soon as possible.');
             } else {
                 Yii::app()->user->setFlash('error', 'Error while sending email: ' . $mail->getError());
             }
             $this->refresh();
         }
     }
     $this->render('contact', array('model' => $model));
 }
Exemplo n.º 25
0
 public static function sendMail($to, $subject, $view, $params)
 {
     if ($view != "empty") {
         $template = Template::model()->findByName($view);
         if ($template != null) {
             self::sendMailWithContent($to, $subject, $template->applyParams($params));
             return;
         }
     }
     $mail = new YiiMailer($view, $params);
     //set properties
     $setting = Yii::app()->params["accounts"]["mail"];
     $mail->setFrom($setting["adminEmail"], $setting["admin"]);
     $mail->setSubject($subject);
     $mail->setTo($to);
     $mail->IsSMTP();
     $mail->Host = $setting["host"];
     $mail->SMTPDebug = 0;
     $mail->SMTPAuth = true;
     $mail->SMTPSecure = $setting["smtp"]["secure"];
     $mail->Host = $setting["smtp"]["host"];
     $mail->Port = $setting["smtp"]["port"];
     $mail->Username = $setting["smtp"]["username"];
     $mail->Password = $setting["smtp"]["password"];
     //send
     if ($mail->send()) {
         return;
     } else {
         echo "Error while sending email: " . $mail->getError();
         return false;
     }
 }
 public function actionCreate()
 {
     //        if (!Yii::app()->user->checkAccess('administrator')) {
     //            throw new Http403Exception();
     //        }
     $wizard = PublicSurveyRequestWizard::loadWizard();
     $surveyRequest = new UserSurveyRequest();
     //SurveyRequestHelper::loadSurveyRequestOfCurrentUser();
     if (Yii::app()->request->isPostRequest) {
         $successRequest = true;
         if ($wizardPost = Yii::app()->request->getPost(get_class($wizard->current()))) {
             if (!empty($_FILES[get_class($wizard->current())])) {
                 foreach (array_keys($_FILES[get_class($wizard->current())]["name"]) as $fileAttrName) {
                     $wizard->current()->{$fileAttrName} = CUploadedFile::getInstance($wizard->current(), $fileAttrName);
                 }
             }
             $wizard->setCurrentData($wizardPost);
             if (Yii::app()->request->getPost('next')) {
                 if ($successRequest = $wizard->current()->validate()) {
                     $wizard->next();
                 }
             }
             if (Yii::app()->request->getPost('prev')) {
                 $wizard->prev(true);
             }
             if (Yii::app()->request->getPost('start')) {
                 if ($successRequest = $wizard->current()->validate()) {
                     $surveyRequest = $this->saveSurveyRequest($wizard, $surveyRequest);
                     $surveyRequest->status = UserSurveyRequest::STATUS_WAITING;
                     $surveyRequest->save();
                     foreach ($wizard->getFiles() as $name => $file) {
                         $attributes = array('name' => $name, 'fileType' => AttachedFile::FILE_TYPE_SIMPLE_ATTACH, 'attachType' => AttachedFile::ATTACH_TYPE_FILE);
                         AttachedFileHelper::uploadFile(new AttachedFile(), $attributes, get_class($surveyRequest), $surveyRequest->id, $file);
                     }
                     $mail = new YiiMailer();
                     $mail->setFrom(Yii::app()->params['noReplyEmail']);
                     $mail->setTo(Yii::app()->params['notificationEmail']);
                     $mail->setSubject('Создание нового брифа');
                     $mail->setView('surveyCreated');
                     $mail->setData(array('controller' => $this, 'wizard' => $wizard, 'surveyRequest' => $surveyRequest));
                     $filesToAttachment = array();
                     foreach ($surveyRequest->files as $file) {
                         $filesToAttachment[$file->filePath] = $file->name;
                     }
                     $mail->setAttachment($filesToAttachment);
                     if (!$mail->send()) {
                         error_log('Cannot send email about survey: ' . $mail->getError());
                     }
                     Yii::app()->user->setFlash('success', "Запрос на создание проекта успешно отправлен. Специалист BCGroup свяжется с Вами в течение дня.");
                     $wizard = new PublicSurveyRequestWizard();
                 }
             }
         }
         if (Yii::app()->request->getPost('save')) {
             $this->saveSurveyRequest($wizard, $surveyRequest);
         } else {
             $wizard->temporarySave();
         }
         if ($successRequest) {
             $this->redirect('create');
         }
     }
     $this->layout = 'publicMain';
     $this->render("create", array('wizard' => $wizard));
 }
Exemplo n.º 27
0
 private static function constructEmailObject()
 {
     //        $mail = new YiiMailer();
     //        $mail->IsSMTP();
     //        $mail->Host = 'smtp.gmail.com';
     //        $mail->Port = 587;
     //        $mail->SMTPSecure= 'tls';
     //        $mail->SMTPAuth = true;
     //        $mail->Username = "******";
     //        $mail->Password = '******';
     //        $mail->setView('contact');
     //        $mail->setLayout('mail');
     //        $mail->setFrom('*****@*****.**', 'Virtual Job Fair');
     //        return $mail;
     $mail = new YiiMailer();
     $mail->IsSMTP();
     $mail->Host = 'smtp.cs.fiu.edu';
     $mail->Port = 25;
     $mail->SMTPAuth = false;
     $mail->setView('contact');
     $mail->setLayout('mail');
     $mail->setFrom('*****@*****.**', 'Virtual Job Fair');
     return $mail;
 }
Exemplo n.º 28
0
// Tarkistukset
if (!isset(Yii::app()->user->tarkistukset)) {
    // ilmoitus kayttoajasta. Tama suoritetaan vain kerran
    $criteria = new CDbCriteria();
    $criteria->order = " id DESC ";
    $criteria->condition = " \n\t\tstatus=1\n\t\tAND (stop - INTERVAL 7 DAY) < NOW()\n\t\tAND ilmoitus_kayttoajasta=0\n\t\tAND koodi!='ilmainen'\n\t";
    $model = Orders::model()->findAll($criteria);
    foreach ($model as $data) {
        $user = User::model()->findbypk($data->user_id);
        if (isset($user->email) and !empty($user->email)) {
            $message = '
			Hei. Käyttöaikasi miinus.fi ohjelmaan päättyy 7 päivän kuluttua. 
			Voit ostaa lisää aikaa menemällä osoitteeseen miinus.fi. 
			Voit ostaa lisää aikaa vaikka heti ja se alkaa vasta sitten, kun vanha käyttöaika on päättynyt.
			';
            $mail = new YiiMailer();
            $mail->setFrom('*****@*****.**', 'MIINUS.FI');
            $mail->setTo($user->email);
            $mail->setSubject('Käyttöaika loppumassa');
            $mail->setBody(str_replace("\n", "<br>", $message));
            if ($mail->send()) {
                Orders::model()->updatebypk($data->id, array('ilmoitus_kayttoajasta' => 1));
            }
        }
    }
}
//Maksun varaus poistaminen jos kavija ei maksettu
$criteria = new CDbCriteria();
$criteria->order = " id DESC ";
$criteria->condition = " \n\t\tstatus=0 AND authcode!='99999'\n\t\tAND (NOW() - INTERVAL 30 MINUTE) > time \n\t";
$model = Orders::model()->deleteAll($criteria);
Exemplo n.º 29
0
 public function SendMailConfirm()
 {
     try {
         $data = BookService::model()->findByAttributes(array('id' => Yii::app()->session['order_id']));
         $this->title = "Mail test";
         $mail = new YiiMailer();
         $mail->setView('confirm');
         $mail->setData(array('data' => $data));
         $mail->setFrom('*****@*****.**', 'John Doe');
         $mail->setSubject('Confirm your order');
         $mail->setTo($data->email);
         $mail->send();
         var_dump($mail->getError());
     } catch (Exception $e) {
         var_dump($e->getMessage());
     }
 }
Exemplo n.º 30
0
 public function sendplainmail($to, $from, $messagedata, $attachment = array(), $test = false)
 {
     $mail = new YiiMailer('default', array('message' => $messagedata->mb_message));
     //set properties
     if (is_object($to)) {
         $mail->setTo($to->u_email);
     } else {
         $mail->setTo($to);
     }
     if (is_object($from)) {
         $mail->setFrom($from->u_email);
     } else {
         $mail->setFrom($from);
     }
     $mail->setSubject($messagedata->mb_subject);
     if (!empty($attachment)) {
         $file = $attachment['file'];
         $filename = $attachment['filename'];
         $mail->setAttachment(array($file => $filename));
     }
     //send
     if ($mail->send() || $_SERVER['HTTP_HOST'] == 'localhost') {
         $messagedata->save();
         $r = true;
     } else {
         Yii::app()->user->setFlash('error', 'Error while sending email: ' . $mail->getError());
         $r = false;
     }
     return $r;
 }