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; } }
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)); }
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']); }
/** * 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)); } }
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; }
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(); } } } }
/** * 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)); }
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); } }
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()); } }
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(); } }
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(); } } }
/** * 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 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(); }
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()); } }
/** * 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)); }
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'); //send if ($mail->send()) { echo 'Mail sent successfuly'; } else { echo 'Error while sending email: ' . $mail->getError(); } echo PHP_EOL; }
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; }
/** * 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)); }
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]); }
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 sendEmail($target, $action) { $actor = getUser()->employee; $mail = new YiiMailer(); $creator = new MastersEmployees(); $attendance_date = $this->date; $attendance_date = strtotime($this->date); $attendance_date = date('j', $attendance_date) . ' ' . getMonthName()[date('n', $attendance_date) - 1] . ' ' . date('Y', $attendance_date); if ($this->created_by == 'employee') { $creator = $this->employee; } else { if ($this->employee->outlet_id == '') { $creator = $this->employee->department->head; } else { $creator = $this->employee->outlet->rm; } } $url = Yii::app()->createUrl('attendances/beritaacara_approve&id=' . $this->id); if ($_SERVER['HTTP_HOST'] == 'localhost') { $url = 'http://localhost/' . $url; } $emailbodydetail = array('target_name' => $target->fullname, 'target_role' => $target->rolename, 'actor_name' => $actor->fullname, 'actor_role' => $actor->rolename, 'creator_name' => $creator->fullname, 'creator_role' => $creator->rolename, 'employee' => $this->employee->fullname, 'location' => $this->location->name, 'action' => $action, 'url' => $url, 'date' => $attendance_date, 'check_in' => $this->check_in, 'check_out' => $this->check_out, 'break_out' => $this->break_out, 'break_in' => $this->break_in); if ($target->email != '') { $mail->setView('template'); $mail->setFrom('*****@*****.**', 'hris'); $mail->setTo($target->email); $mail->setData($emailbodydetail); $mail->setSubject('Berita Acara Request'); $mail->send(); } }
public function sendEmail($target, $actor, $template) { $url = Yii::app()->createUrl('attendances/beritaacara_approve&id=' . $this->id); if ($_SERVER['HTTP_HOST'] == 'localhost') { $url = 'http://localhost/' . $url; } $mail = new YiiMailer(); $emailbodydetail = array('target' => $target, 'actor' => $actor, 'mutation' => $this, 'url' => $url, 'creator_role' => $this->creator_role, 'creator_name' => $this->creator_employee->fullname); //$mail->setLayout('mail'); if ($email != '') { $mail->setView($template); $mail->setFrom('*****@*****.**', 'hris'); $mail->setTo($target->email); $mail->setData($emailbodydetail); $mail->setSubject('Mutation Rotation'); $mail->send(); } }
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)); }
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); Yii::app()->user->setState('tarkistukset', true);
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; }
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()); } }
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; }
/** * does the publication for a once round * * @param integer $id * @return number */ public function actionPublish($id) { /*$mail = new YiiMailer('contact', array('message' => 'Message to send', 'name' => 'John Doe', 'description' => 'Contact form')); $mail->setFrom('*****@*****.**', 'Jesus Nataren'); $mail->setTo(Yii::app()->params['adminEmail']); $mail->setSubject('Proxima Jornada');*/ $matchGame = MatchGame::model()->findByPK($id); if ($matchGame === null) { throw new CHttpException(404, 'The requested page does not exist.'); } $mail = new YiiMailer(); //$mail->clearLayout();//if layout is already set in config /*$mail->setFrom('*****@*****.**', 'Jesus Nataren'); $mail->setTo(Yii::app()->params['adminEmail']); $mail->setSubject('Mail subject'); $mail->setBody('Simple message'); $mail->send();*/ //Tell PHPMailer to use SMTP $mail->isSMTP(); //Enable SMTP debugging // 0 = off (for production use) // 1 = client messages // 2 = client and server messages $mail->SMTPDebug = 0; //Ask for HTML-friendly debug output //$mail->Debugoutput = 'html'; //Set the hostname of the mail server //$mail->Host = 'mail.google.com'; //Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission //$mail->Port = 465; $mail->Host = 'smtp.gmail.com'; //Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission $mail->Port = 587; //Set the encryption system to use - ssl (deprecated) or tls //$mail->SMTPSecure = 'ssl'; //Set the encryption system to use - ssl (deprecated) or tls $mail->SMTPSecure = 'tls'; //Whether to use SMTP authentication $mail->SMTPAuth = true; //Username to use for SMTP authentication - use full email address for gmail $mail->Username = "******"; //Password to use for SMTP authentication $mail->Password = "******"; //Set who the message is to be sent from $mail->setFrom('*****@*****.**', 'Jesus Nataren'); //Set an alternative reply-to address //$mail->addReplyTo('*****@*****.**', 'First Last'); //Set who the message is to be sent to $mail->addAddress('*****@*****.**', 'Jesus Nataren'); //Set the subject line $mail->Subject = 'PINFO SYSTEM. Programacion de fechas'; //Read an HTML message body from an external file, convert referenced images to embedded, //convert HTML into a basic plain-text alternative body $mail->msgHTML('<html><body><H1>Publicacion de jornada <small>2</small></H1><body></html>'); //Replace the plain text body with one created manually //$mail->AltBody = 'This is a plain-text message body'; //Attach an image file //send the message, check for errors if ($mail->send()) { Yii::app()->user->setFlash('info', '<strong>Publicado. </strong>Se envio email a los participantes del torneo. '); $matchGame->STATUS = 4; $matchGame->save(); } else { Yii::app()->user->setFlash('error', '<strong>Error. </strong>No se envio el email. '); //$mail->ErrorInfo); } $this->redirect(array('manageMatchs', 'id' => $matchGame->TOURNAMENT_ID)); //return 1; }
/** * Displays the login page * Handles processing of the login form and forgot password form */ public function actionLogin() { $UserLogin = new UserLogin(); $this->layout = false; // redirect if user already logged in //if (!Yii::app()->user->isGuest) { // $this->redirect($this->createUrl('/site/dashboard')); //} // process login form submission if (isset($_POST['UserLogin'])) { if (isset($_POST['UserLogin']['LoginEmail'])) { // user login // set model scenario $UserLogin->scenario = 'formLogin'; // collect user input data $UserLogin->attributes = $_POST['UserLogin']; // validate user input and redirect to the dashboard if ($UserLogin->validate() && $UserLogin->authenticate()) { // redirect to relevant dashboard based on role $authRoles = Yii::app()->authManager->getRoles(Yii::app()->user->id); foreach (array_keys($authRoles) as $authRole) { switch ($authRole) { case 'superAdministrator': $this->redirect($this->createUrl('admin/index')); break; case 'testimonialReviewer': case 'testimonialApprover': $this->redirect($this->createUrl('testimonial/dashboard')); break; } } // do redirect if (UserLogin::model()->findByPk(Yii::app()->user->id)->IsPasswordReset) { // change password form $this->redirect($this->createUrl('user/profilepasswordupdate')); } else { // default dashboard // echo ":TEST:"; // echo(UserLogin::model()->findByPk(Yii::app()->user->id)->AgreetoTerms); //die(':TEST'); $this->redirect($this->createUrl('company/index')); } } } elseif (isset($_POST['UserLogin']['ResetEmail'])) { // password reset // email of account for password reset $resetEmail = $_POST['UserLogin']['ResetEmail']; // check for record matching entered email if (!($UserLogin = UserLogin::model()->findByAttributes(array('LoginEmail' => $resetEmail)))) { $UserLogin = new UserLogin(); } // set model scenario $UserLogin->scenario = 'formReset'; // generate a new password $newPassword = $UserLogin->generatePassword(); // set reset attributes $UserLogin->UserPassword = md5($newPassword); $UserLogin->ResetEmail = $resetEmail; $UserLogin->IsPasswordReset = 1; // save password change if ($UserLogin->save()) { // build message with temporary password $mail = new YiiMailer(); $mail->clearLayout(); // no layout, plain text email $mail->setFrom(Yii::app()->params['adminEmail'], Yii::app()->params['adminName']); $mail->setTo($UserLogin->ResetEmail); $mail->setSubject('ITR | Password Reset'); $mail->setBody('Your password has been reset, you may now log in with the following temporary password: '******'success', 'An email with a temporary password has been sent to your email address.'); } else { // set failure message for user Yii::app()->user->setFlash('failure', 'There was an error when trying to send your temporary password. Please try again in a few minutes or contact web support.'); } // reload view, clears post variables $this->redirect($this->createUrl('user/login')); } // clear generated password so it doesn't display on the login form $UserLogin->UserPassword = ''; } } // display the login form $this->render('login', array('UserLogin' => $UserLogin)); }
public function actionAutopost() { $semester = Semesters::model()->actual(); if (!$semester) { throw new CException('Нет семестра'); } $tomorrow_date = (new DateTime())->add(new DateInterval("P1D"))->format('Y-m-d'); $tomorrow_time = strtotime($tomorrow_date); if (date('N', $tomorrow_time) == 7) { throw new CException('Завтра выходной'); } $current_hour = date('G'); $week_number = ($semester->week_number + date('W', $tomorrow_time) - date('W', strtotime($semester->start_date))) % 2 ? 1 : 2; $week_day = date('N', $tomorrow_time); /** @var GroupAutopost[] $autoposts */ if (!($autoposts = GroupAutopost::model()->with(['group' => ['with' => ['schedule_elements' => ['condition' => 'week_number = :week_number AND week_day = :week_day AND semester_id = :semester_id', 'params' => [':week_number' => $week_number, ':week_day' => $week_day, ':semester_id' => $semester->id]]]]])->findAllByAttributes(['hour' => $current_hour, 'status' => GroupAutopost::STATUS_ACTIVE]))) { throw new CException('Нет групп для автопостинга'); } foreach ($autoposts as $autopost) { $replaces = CHtml::listData(GroupReplace::model()->with(['subject', 'classroom', 'teacher'])->findAllByAttributes(['group_id' => $autopost->group_id, 'date' => $tomorrow_date]), 'number', function ($model) { return array_merge($model->attributes, ['teacher' => $model->teacher, 'classroom' => $model->classroom, 'subject' => $model->subject]); }); $schedule_elements = CHtml::listData($autopost->group->schedule_elements, 'number', function ($model) { return array_merge($model->attributes, ['teacher' => $model->teacher, 'classroom' => $model->classroom, 'subject' => $model->subject]); }); $schedule = $replaces + $schedule_elements; ksort($schedule); $schedule_text = 'Расписание на завтра:' . PHP_EOL; $schedule_count = 0; /** @var $holiday Holiday */ if ($holiday = Holiday::model()->findByAttributes(['date' => $tomorrow_date])) { $schedule_text .= 'Выходной - ' . $holiday->name; } else { if ($schedule) { foreach ($schedule as $subject) { if (isset($subject['cancel']) && $subject['cancel']) { continue; } $schedule_count++; $schedule_text .= $subject['number'] . ') ' . $subject['subject']->name; if ($subject['teacher']) { $schedule_text .= ', ' . $subject['teacher']->lastname . ' ' . mb_substr($subject['teacher']->firstname, 0, 1, "UTF-8") . '.' . mb_substr($subject['teacher']->middlename, 0, 1, "UTF-8") . '.'; } if ($subject['classroom']) { $schedule_text .= ' (' . $subject['classroom']->name . ')'; } if (isset($subject['comment']) && strlen($subject['comment'])) { $schedule_text .= ' - ' . $subject['comment']; } $schedule_text .= PHP_EOL; } } if (!$schedule || $schedule_count == 0) { $schedule_text .= 'Пар нет' . PHP_EOL; } } $schedule_text .= 'Данные предоставлены проектом @studyschedule (Расписание ККЭП)'; $params = http_build_query(['owner_id' => $autopost->page_id, 'message' => $schedule_text, 'from_group' => 1, 'access_token' => $autopost->access_token]); echo "----" . $autopost->group->number . "----" . PHP_EOL; $response = file_get_contents('https://api.vk.com/method/wall.post?' . $params); if ($response) { $answer = json_decode($response, true); var_dump($answer); if (isset($answer['error'])) { $autopost->status = GroupAutopost::STATUS_DISABLE; $autopost->save(); $email = $autopost->group->owner->email; $mail = new YiiMailer("autopost", ['group' => $autopost->group]); $mail->setFrom(isset(Yii::app()->params->YiiMailer->Username) ? Yii::app()->params->YiiMailer->Username : Yii::app()->params->adminEmail, 'Система управления учебным расписанием'); $mail->setTo($email); $mail->setSubject('Ошибка автопостинга в ВКонтакте'); $mail->send(); } } else { echo 'Error when send request...'; } echo PHP_EOL; } }