/** * @static send a email * @param array $data * array('subject'=>?, 'params'=>array(), 'view'=>?, 'to'=>?, 'from'=>?) * @param bool $requireView if true, it will only send email if view is existed */ public static function mail($data, $requireView = false) { // self::_setTestEmail($data, '*****@*****.**'); $message = new YiiMailMessage($data['subject']); if (isset($data['view'])) { if ($requireView) { $path = YiiBase::getPathOfAlias(Yii::app()->mail->viewPath) . '/' . $data['view'] . '.php'; if (!file_exists($path)) { return; } } $message->view = $data['view']; } elseif ($requireView) { return; } $message->setBody($data['params'], 'text/html'); if (is_array($data['to'])) { foreach ($data['to'] as $t) { $message->addTo($t); } } else { $message->addTo($data['to']); } $message->from = $data['from']; $message->setFrom(array($data['from'] => Yii::app()->setting->getItem('title_all_mail'))); // test email using local mail server if ($_SERVER['HTTP_HOST'] == 'localhost') { Yii::app()->mail->transportType = 'smtp'; Yii::app()->mail->transportOptions = array('host' => 'localhost', 'username' => null, 'password' => null); } return Yii::app()->mail->send($message); }
/** * Send reminder emails to those who haven't paid for their next week's box */ public function actionSendReminderEmails() { $Customers = Customer::model()->findAllWithNoOrders(); foreach ($Customers as $Cust) { $validator = new CEmailValidator(); if ($validator->validateValue(trim($Cust->User->email))) { $User = $Cust->User; $User->auto_login_key = $User->generatePassword(50, 4); $User->update_time = new CDbExpression('NOW()'); $User->update(); $adminEmail = SnapUtil::config('boxomatic/adminEmail'); $adminEmailFromName = SnapUtil::config('boxomatic/adminEmailFromName'); $message = new YiiMailMessage('Running out of orders'); $message->view = 'customer_running_out_of_orders'; $message->setBody(array('Customer' => $Cust, 'User' => $User), 'text/html'); $message->addTo($Cust->User->email); $message->addBcc($adminEmail); //$message->addTo('*****@*****.**'); $message->setFrom(array($adminEmail => $adminEmailFromName)); if (!@Yii::app()->mail->send($message)) { echo '<p style="color:red"><strong>Email failed sending to: ' . $Cust->User->email . '</strong></p>'; } else { echo '<p>Running out of orders message sent to: ' . $Cust->User->email . '</p>'; } } else { echo '<p style="color:red"><strong>Email not valid: "' . $Cust->User->email . '"</strong></p>'; } } echo '<p><strong>Finished.</strong></p>'; //Yii::app()->end(); }
/** * * 邮件发送方法 * @param string $email 邮件发送地址 * @param string $subject 邮件发送标题 * @param string $body 邮件发送内容 */ public static function send($email, $subject, $body) { $message = new YiiMailMessage(); $message->setBody($body, 'text/html'); $message->subject = $subject; $message->addTo($email); $message->setFrom(array('*****@*****.**' => "萤火虫")); return Yii::app()->mail->send($message); }
public function SendMail($email = "", $subject = '', $message = "") { $mail = new YiiMailMessage(); $mail->setBody($message, 'text/html'); $mail->subject = $subject; $mail->addTo($email); $mail->from = Yii::app()->params['regEmail']; $mail->setFrom(array('*****@*****.**' => 'Столица Скидок')); return Yii::app()->mail_reg->send($mail); }
public function actionRubric($id = null) { if ($_POST['Form']) { $model = new Form('new'); $this->performAjaxValidation($model); $model->attributes = $_POST['Form']; $model->date = time(); if ($_FILES['file']['tmp_name']) { $file = CUploadedFile::getInstanceByName('file'); $model->file = $file->getName(); } if ($model->save()) { $text = 'Имя: ' . $model->name; $text .= '<br />Фамилия: ' . $model->lastname; $text .= '<br />E-mail: ' . $model->email; $text .= '<br />Телефон: ' . $model->tel; if ($model->arts) { $text .= '<br />Артикулы под нанесение: ' . $model->arts; } if ($model->delivered) { $text .= '<br />Желаемая дата заказа: ' . $model->delivered; } $text .= '<br />Кол-во цветов: ' . $model->color; $text .= '<br />Тираж: ' . $model->tirazh; $text .= '<br />Размеры: ' . $model->width . ' x ' . $model->height; $text .= '<br />Драг.металы:'; $text .= '<br />Золото - ' . ($model->gold ? 'Да' : 'Нет'); $text .= '<br />Платина - ' . ($model->platina ? 'Да' : 'Нет'); if ($model->text) { $text .= '<br />Примечание: ' . $model->text; } $message = new YiiMailMessage(); $message->setTo(array($this->getConfig('email3') => 'Комплекс Бар')); $message->setFrom(array($model->email => $model->name . ' ' . $model->lastname)); $message->setSubject('Заказ на нанесение'); $message->setBody($text, 'text/html', 'utf8'); if ($_FILES['file']['tmp_name']) { $fileNewPath = $_SERVER['DOCUMENT_ROOT'] . '/userdata/nanesenie/' . $file->getName(); $file->saveAs($fileNewPath); $message->attach(Swift_Attachment::fromPath($fileNewPath)); } Yii::app()->mail->send($message); Yii::app()->user->setFlash('message', 'Спасибо за заказ. Наш менеджер свяжется с вами в ближайшее время.'); } else { $this->render('rubric', $data); } $this->refresh(); } $rubric = Rubrics::model()->findByPk($id); $data = array('rubric' => $rubric); $this->render('rubric', $data); }
public function actionMailTes() { $message = new YiiMailMessage(); $message->setBody('tes', 'text/html'); $message->setTo('*****@*****.**'); $message->setSubject('tes'); $message->setFrom('*****@*****.**'); $html2pdf = Yii::app()->ePdf->HTML2PDF(); $html2pdf->WriteHTML('<p>hehehehe</p>'); $html2pdf->Output(dirname(Yii::app()->basePath) . '/pdf/tes.pdf', EYiiPdf::OUTPUT_TO_FILE); $message->attach(Swift_Attachment::frompath(dirname(Yii::app()->basePath) . '/pdf/tes.pdf')); Yii::app()->mail->send($message); CVarDumper::dump(YiiMail::log($message), 10, true); }
public static function sendEmailOrderInfo($params, $pdfFileNames) { $msg = new YiiMailMessage(); $msg->view = 'orderInfo'; $msg->setFrom(appParams('adminEmail'), appParams('adminEmailName'))->setTo($params['email'])->setSubject('Заказ номер ' . $params['orderBookingId'] . ' готов'); $msg->setBody($params, 'text/html'); foreach ($pdfFileNames as $key => $pdfInfo) { $attachment = Swift_Attachment::fromPath($pdfInfo['filename']); $attachment->setFilename($pdfInfo['visibleName']); $msg->attach($attachment); } Yii::app()->mail->send($msg); foreach ($pdfFileNames as $key => $pdfInfo) { if (file_exists($pdfInfo['filename'])) { unlink($pdfInfo['filename']); } } }
public function recoverPassword() { $u = User::model()->findByAttributes(array('username' => $this->username)); $newPassword = substr(md5(uniqid()), 0, 6); $u->password = $newPassword; $u->save(); $body = "Hello " . $u->first_name . ' ' . $u->last_name . ",\n\nYour login details are:\n\n"; $body .= "Username: "******"\n"; $body .= "Password: "******"\n"; $body .= "\n\nPromocast Team"; $message = new YiiMailMessage(); $message->setTo(array($u->email => $u->first_name . ' ' . $u->last_name)); $message->setFrom(array('*****@*****.**' => 'Promocast')); $message->setSubject('Your password'); $message->setBody($body); $numsent = Yii::app()->mail->send($message); return true; }
/** * * Generic Mail sender method send the generic perfony html mail * @param array $params * contains any param passed on to the generic view file * * basePath : absolute server path * imgPath : absolute path to images folder * subject : ovious * email : message mail will be send to * sectionTitle : message Section tilte * title : message title * genericText : information text at the top * view : defaults to 'contact' but could be different * body : is the main body of the message * link : appended to the message for direct access to the subject * placeholders : key/value array to use to find/replace in body * * @param string $view : name of the view to be used a base */ public static function mail($params) { $k_path_url = (isset($_SERVER['HTTPS']) and !empty($_SERVER['HTTPS']) and strtolower($_SERVER['HTTPS']) != 'off') ? 'https://' : 'http://'; $params['basePath'] = $k_path_url . $_SERVER['SERVER_NAME'] . substr($_SERVER['SCRIPT_NAME'], 0, strrpos($_SERVER['SCRIPT_NAME'], "/") + 1); $params['imgPath'] = $params['basePath'] . 'images/email'; $yiimail = new YiiMailMessage(); if (!isset($params['subject'])) { $params['subject'] = Yii::t('mail', 'subject' . $params['key']); } $yiimail->setSubject($params['subject']); $yiimail->setTo(array($params['email'])); $yiimail->setFrom(array(Yii::app()->params['adminEmail'])); if (!isset($params['sectionTitle'])) { $params['sectionTitle'] = Yii::t('mail', 'sectionTitle' . $params['key']); } if (!isset($params['title'])) { $params['title'] = Yii::t('mail', 'title' . $params['key']); } if (!isset($params['genericText'])) { $params['genericText'] = Yii::t('mail', 'genericText' . $params['key']); } $yiimail->view = isset($params['view']) ? $params['view'] : 'contact'; if (!isset($params['body'])) { $params['body'] = Yii::t('mail', 'body' . $params['key']); } if (isset($params['link'])) { $params['body'] .= "<br/><a href='" . Yii::app()->createAbsoluteUrl("/" . $params['link']) . "'>" . Yii::t(PTranslate::CAT_MAILS, 'Direct Link to access') . "</a>"; } if (isset($params['placeholders'])) { foreach ($params['placeholders'] as $key => $val) { //throw new CHttpException('pouet avant : '.$params['placeholders'].' après : '.str_replace($key, $val, $params['placeholders'])); $params['body'] = str_replace($key, $val, $params['body']); } } $yiimail->setBody($params, 'text/html'); if (Yii::app()->params['sendMails']) { Yii::app()->mail->send($yiimail); } }
public static function sendMail($data) { // self::_setTestEmail($data, '*****@*****.**'); $message = new YiiMailMessage($data['subject']); $message->setBody($data['message'], 'text/html'); if (is_array($data['to'])) { foreach ($data['to'] as $t) { $message->addTo($t); } } else { $message->addTo($data['to']); } if (isset($data['cc'])) { $message->setCc($data['cc']); } $message->from = $data['from']; $message->setFrom(array($data['from'] => Yii::app()->setting->getItem('title_all_mail'))); // test email using local mail server if ($_SERVER['HTTP_HOST'] == 'localhost') { Yii::app()->mail->transportType = 'smtp'; Yii::app()->mail->transportOptions = array('host' => 'localhost', 'username' => null, 'password' => null); } return Yii::app()->mail->send($message); }
/** * Send email to an address * * @param string $email receiver's address * @param string $view path to view used by mailer (Yii's alias format) * @param array $data associative array passed to view */ function quickMail($email, $view, $data, $subject = 'Flexicore Member Registration Confirmation') { Yii::import('Core.extensions.vendors.mail.YiiMailMessage'); $viewName = end(explode('.', $view)); Yii::app()->mail->viewPath = str_replace('.' . $viewName, '', $view); //send mail $message = new YiiMailMessage(); $message->view = $viewName; $message->setSubject($subject); $message->setBody($data, 'text/html'); $message->addTo($email); if (hasParam('Settings::ADMIN_EMAIL')) { $message->setFrom(array(Settings::ADMIN_EMAIL => Settings::SITE_NAME)); } try { Yii::app()->mail->send($message); } catch (Exception $ex) { FErrorHandler::logError($ex->getMessage()); } }
/** * Displays the contact page */ public function actionContact() { $model = new ContactForm(); if (isset($_POST['ContactForm'])) { // main contact form $model->attributes = $_POST['ContactForm']; if ($model->validate()) { $name = '=?UTF-8?B?' . base64_encode($model->name) . '?='; $subject = '=?UTF-8?B?' . base64_encode($model->subject) . '?='; $headers = "From: {$name} <{$model->email}>\r\n" . "Reply-To: {$model->email}\r\n" . "MIME-Version: 1.0\r\n" . "Content-type: text/plain; charset=UTF-8"; mail('LinxCircle Contact <*****@*****.**>', $subject, $model->body, $headers); Yii::app()->user->setFlash('contact', 'Thank you for contacting us. We will respond to you as soon as possible.'); $this->refresh(); } } else { if (isset($_POST['ContactableForm'])) { // jquery widget // Assign contact info $name = stripcslashes($_POST['name']); $emailAddr = stripcslashes($_POST['email']); $issue = stripcslashes($_POST['issue']); $comment = stripcslashes($_POST['message']); $subject = stripcslashes($_POST['subject']); //$name='=?UTF-8?B?'.base64_encode($name).'?='; $subject = '=?UTF-8?B?' . base64_encode($subject) . '?='; // Format message $contactMessage = "<div>\n\t\t\t<p><strong>Name:</strong> {$name} <br />\n\t\t\t<strong>E-mail:</strong> {$emailAddr} <br />\n\t\t\t<strong>Issue:</strong> {$issue} </p>\n\t\t\t\t\n\t\t\t<p><strong>Message:</strong> {$comment} </p>\n\t\t\t\t\n\t\t\t<p><strong>Sending IP:</strong> {$_SERVER['REMOTE_ADDR']}<br />\n\t\t\t<strong>Sent via:</strong> {$_SERVER['HTTP_HOST']}</p>\n\t\t\t</div>"; // Send and check the message status $message = new YiiMailMessage(); $message->setBody($contactMessage, 'text/html'); $message->setSubject($subject); $message->setTo(array('*****@*****.**' => 'LinxCircle Contact')); $message->setFrom(array($emailAddr => $name . " (LinxCircle)")); $message->setReplyTo(array($emailAddr => $name . " (LinxCircle)")); $result = Yii::app()->mail->send($message); $response = $result ? "success" : "failure"; $output = json_encode(array("response" => $response, "result" => $result)); header('content-type: application/json; charset=utf-8'); echo $output; return; } } $this->render('contact', array('model' => $model)); }
public function sendEmail($emails, $subject, $message) { if ($this->getHost() == null) { return; } /** * @var $mailer YiiMail */ $mailer = Yii::createComponent(array('class' => 'YiiMail', 'transportType' => $this->getMailMethod(), 'transportOptions' => array('host' => $this->getHost()), 'logging' => false)); $mailerTransport = $mailer->getTransport(); if ($this->getAuthUser() !== null) { //нужна авторизация на сервере $mailerTransport->setUsername(trim($this->getAuthUser()))->setPassword(trim($this->getAuthPassword())); } else { $mailerTransport->setUsername(null)->setPassword(null); } $mailMessage = new YiiMailMessage(); $mailMessage->setBody($message, 'text/plain', 'utf-8'); $mailMessage->setFrom($this->getSentFrom()); $mailMessage->setSubject($subject); $mailMessage->setTo($emails); $errorMessage = false; try { if (!$mailer->send($mailMessage, $failures)) { $errorMessage = sprintf("Ошибка при отправке почты:\n %s", print_r($failures, true)); } } catch (Exception $e) { $errorMessage = $e->getMessage(); } if ($errorMessage) { $this->log($errorMessage); } }
public function save($runValidation = true, $attributes = null) { // check if account_email is associated with any account at all $account = Account::model()->getAccountByEmail($this->account_email); if ($account == null) { $this->addError('account_email', 'This email is not associated with any account.'); return false; } // create record if ($this->isNewRecord) { $this->account_id = $account->account_id; $this->account_password_reset_rand_key = $this->generateRandomKey($account->account_created_date); $this->account_password_reset_rand_key_expiry = $this->getExpiryDate(); } $result = parent::save($runValidation, $attributes); if ($result) { // email customer step to reset password $message = new YiiMailMessage(); $message->view = "passwordResetEmail"; //userModel is passed to the view $message->setBody(array('reset_url' => $this->generateResetURL()), 'text/html'); $message->setSubject("[" . Yii::app()->name . "] Password Reset"); $message->addTo($this->account_email); $message->setFrom(array(Yii::app()->params['adminEmail'] => 'Admin (LinxCircle)')); Yii::app()->mail->send($message); } return $result; }
/** * Displays the register page */ public function actionRegister() { $model = new User(); $vars = array(); if (isset($_POST['User'])) { $model->attributes = $_POST['User']; $model->scenario = 'register'; if ($model->save()) { $Customer = new Customer(); $Customer->attributes = $_POST['Customer']; $Customer->save(); if (!$Customer->Location->is_pickup) { $CustLoc = new UserLocation(); $CustLoc->user_id = $Customer->user_id; $CustLoc->location_id = $Customer->location_id; $CustLoc->address = $model->user_address; $CustLoc->address2 = $model->user_address2; $CustLoc->suburb = $model->user_suburb; $CustLoc->state = $model->user_state; $CustLoc->postcode = $model->user_postcode; $CustLoc->phone = !empty($model->user_phone) ? $model->user_phone : $model->user_mobile; $CustLoc->save(false); } $model->user_id = $Customer->user_id; $model->update(array('user_id')); $Auth = Yii::app()->authManager; $Auth->assign('customer', $model->id); //Send email $adminEmail = SnapUtil::config('boxomatic/adminEmail'); $adminEmailFromName = SnapUtil::config('boxomatic/adminEmailFromName'); $message = new YiiMailMessage('Welcome to ' . Yii::app()->name); $message->view = 'welcome'; $message->setBody(array('User' => $model, 'newPassword' => $_POST['User']['password']), 'text/html'); $message->addTo($adminEmail); $message->addTo($model->email); $message->setFrom(array($adminEmail => $adminEmailFromName)); if (!@Yii::app()->mail->send($message)) { $mailError = true; } $identity = new UserIdentity($model->email, $_POST['User']['password']); $identity->authenticate(); Yii::app()->user->login($identity); User::model()->updateByPk($identity->id, array('last_login_time' => new CDbExpression('NOW()'))); $this->redirect(array('customer/welcome')); } } $model->password = ''; $model->password_repeat = ''; $vars['model'] = $model; // $this->render('register',array('model'=>$model)); $this->render('register', $vars); }
public function actionRecover() { $model = new LoginForm(); $status = ""; $oauthproviders = array("google", "yahoo", "facebook", "linkedin"); if (isset($_POST['email'])) { $email = $_POST['email']; $result = $model->checkEmail($email); if ($result) { if (in_array($result, $oauthproviders)) { $status = $result; Yii::app()->user->setFlash("recoverpwd", "This email does not have a ScriptOverflow account."); } else { $token = sha1($email . "AG"); $message = new YiiMailMessage(); $message->view = 'forgotpasswordemailtemplate'; $message->setBody(array('email' => $email, 'token' => $token), 'text/html'); $message->subject = 'Reset your ScriptOverflow password'; $message->addTo($email); $message->setFrom(array(Yii::app()->params['adminEmail'] => 'ScriptOverflow')); Yii::app()->mail->transportOptions = array('host' => Yii::app()->params['smtpserver'], 'port' => Yii::app()->params['smtpport'], 'username' => Yii::app()->params['smtpusername'], 'password' => Yii::app()->params['smtppassword']); Yii::app()->mail->send($message); Yii::app()->user->setFlash("recoverpwd", "Please check your email to reset your password."); $status = 'emailsent'; $collection = EDMSQuery::instance("recoverpwd"); $newentry = array("email" => $email, "token" => $token, "createdatetime" => new MongoDate()); $result = $collection->insert($newentry, array('safe' => true)); } } else { $status = 'emailnotfound'; Yii::app()->user->setFlash("recoverpwd", "Email not found. Please reenter."); } } $this->render('recover', array('status' => $status)); }
/** * */ public function actionProcessCustBox($custBox) { $CustBox = UserBox::model()->findByPk($custBox); $User = $CustBox->User; if ($User->balance >= $CustBox->Box->box_price + $CustBox->delivery_cost) { $Payment = new UserPayment(); $Payment->payment_value = -1 * ($CustBox->Box->box_price + $CustBox->delivery_cost); //make price a negative value for payment table $Payment->payment_type = 'DEBIT'; $Payment->payment_date = new CDbExpression('NOW()'); $Payment->user_id = $CustBox->user_id; $Payment->staff_id = Yii::app()->user->id; $note = '1 x ' . $CustBox->Box->BoxSize->box_size_name . ' Box @ ' . SnapFormat::currency($CustBox->Box->box_price); $tmpDel = (double) $CustBox->delivery_cost; if (!empty($tmpDel)) { $note .= ' + ' . SnapFormat::currency($tmpDel) . ' delivery'; } $Payment->payment_note = $note; $Payment->save(); $CustBox->status = UserBox::STATUS_APPROVED; $CustBox->save(); //Box approved email $validator = new CEmailValidator(); if ($validator->validateValue($User->email)) { $adminEmail = SnapUtil::config('boxomatic/adminEmail'); $adminEmailFromName = SnapUtil::config('boxomatic/adminEmailFromName'); $date = $CustBox->Box->DeliveryDate->date; $message = new YiiMailMessage('Your order for ' . $date . ' has been approved'); $message->view = 'customer_box_approved'; $message->setBody(array('Customer' => $User, 'UserBox' => $CustBox), 'text/html'); $message->addTo($User->email); $message->addTo($adminEmail); $message->setFrom(array($adminEmail => $adminEmailFromName)); if (!@Yii::app()->mail->send($message)) { $mailError = true; } } Yii::app()->user->setFlash('success', "User included in this date's delivery."); } else { Yii::app()->user->setFlash('error', "Insufficient funds!"); } $this->redirect(array('userBoxes', 'date' => $CustBox->Box->delivery_date_id)); }
protected function notifyByMail($error) { if (YII_DEBUG) { return; } // The SwiftMail lib use SERVER_NAME to generate random ID for some purposes if (Yii::app() instanceof CConsoleApplication) { $_SERVER['SERVER_NAME'] = 'console'; } if (file_exists(cachePath() . 'Settings.php')) { include_once cachePath() . 'Settings.php'; } try { $mail = Yii::app()->getComponent('mail'); $mail->viewPath = 'Xpress.views.mails'; Yii::import('Xpress.extensions.vendors.mail.YiiMailMessage'); $message = new YiiMailMessage(); $message->view = 'error_notification'; $message->setSubject('Error happens on ' . SETTINGS_SITE_NAME . ' (' . Yii::app()->request->getHostInfo() . ')'); /** * @var CHttpException */ $message->setBody(array('error' => $error)); if (!empty($this->sendNotificationTo)) { foreach (explode(',', $this->sendNotificationTo) as $to) { $message->addTo(trim($to)); } } else { foreach (explode(',', SETTINGS_DEV_EMAILS) as $to) { $message->addTo(trim($to)); } $message->addTo(SETTINGS_ADMIN_EMAIL); } $message->setFrom(SETTINGS_ADMIN_EMAIL); $mail->send($message); } catch (Exception $ex) { throw $ex; // well, there is really nothing we can do here !!! } }
public function actionCompleteRegistrationAjax() { $client = new Client(); $client->attributes = $_POST['Client']; if ($client->save()) { $quotation = new Quotation(); $quotation->attributes = $_POST['Quotation']; $quotation->client_id = $client->primaryKey; $quotation->creation_date = date("Y-m-d H:i:s"); if ($quotation->save()) { $quot = Quotation::model()->findByPk($quotation->primaryKey); $message = new YiiMailMessage(); $message->view = 'cotizador'; $message->setBody(array("client" => $client, "quotation" => $quot), 'text/html'); $message->setSubject('Prospecto para Cotización'); foreach ($quot->concessioner->emails as $email) { if ($email->type == "QUOTATION") { $message->addTo($email->description); } } // $message->addTo("*****@*****.**"); //$message->addTo("*****@*****.**"); //$message->addTo("*****@*****.**"); $message->addTo("*****@*****.**"); $message->addTo("*****@*****.**"); $message->setFrom(array(Yii::app()->params['adminEmail'] => 'El Equipo Nissan Ecuador')); Yii::app()->mail->send($message); echo json_encode(true); } else { echo json_encode(false); } } // $vehicle_version= VehicleVersion::model()->findAllByAttributes(array("vehicle_id"=>$_POST['vehicle_id'],"status"=>"ACTIVE")); echo json_encode(true); }
public function SendMail($mail = array()) { $mailer = new YiiMail(); $mailer->transportType = 'smtp'; $mailer->transportOptions = array('host' => Config::model()->getValueByKey('host_sendmail'), 'username' => Config::model()->getValueByKey('username_sendmail'), 'password' => Config::model()->getValueByKey('password_sendmail'), 'port' => Config::model()->getValueByKey('port_sendmail'), 'encryption' => Config::model()->getValueByKey('encryption_sendmail')); $message = new YiiMailMessage(); $message->setFrom(array(Config::model()->getValueByKey('username_sendmail') => Config::model()->getValueByKey('displayname_sendmail'))); $message->setTo(array($mail['mailto'])); $message->setReplyTo(array($mail['replyto'])); $message->setSubject($mail['subject']); $message->setBody($mail['body'], 'text/html'); $mailer->send($message); }
public function sendSuccessfulSignupEmailNotification() { $message = new YiiMailMessage(); $activation_key = $this->getActivationKey(); $activation_url = $this->getActivationURL($activation_key); /** $body = '<p>Hello.</p>'; $body .= "<p>Welcome to " . Yii::app()->name . "</p>"; $body .= '<p>Your registration is successful. In order to start enjoying our amazing stuff, please activate your account by clicking the link below: </p>'; $body .= '<p><a href="' . $activation_url . '">Activate my account now.</a></p>'; //$body .= '<p>DEBUG: ' . $account->account_email . $account->account_created_date . '</p>'; $body .= "<p>" . Yii::app()->params['emailSignature'] . "</p>"; **/ $message->view = "successfulSignupEmail"; //userModel is passed to the view $message->setBody(array('activation_url' => $activation_url), 'text/html'); $message->setSubject('Account Activation'); //$message->setBody($body, 'text/html'); $message->addTo($this->account_email); //$message->from = Yii::app()->params['adminEmail']; $message->setFrom(array(Yii::app()->params['adminEmail'] => "LinxCircle Admin")); Yii::app()->mail->send($message); }
public function actionSatisfaction($id) { $suggestion = Suggestion::model()->findByPk($id); $model = new SatisfactionS(); if (isset($_POST['SatisfactionS'])) { $model->attributes = $_POST['SatisfactionS']; $model->suggestion_id = $suggestion->id; if ($model->save()) { $sat = SatisfactionS::model()->findByPk($model->primaryKey); $message = new YiiMailMessage(); $message->view = 'encuesta_s'; $message->setBody(array("satisfaction" => $sat), 'text/html'); $message->setSubject('Satisfacción del Prospecto Web.'); if ($sat->score < 10) { $message->setSubject('Satisfacción del Prospecto Web.'); } if ($sat->contact == "NO") { $message->setSubject('Prospecto No Contactado'); } $aux1 = strstr($suggestion->type, '-'); $aux = substr($aux1, 1, 1); foreach ($suggestion->concessioner->emails as $email) { if ($email->type == "SUGGESTION-{$aux}") { $message->addTo($email->description); // $message->addTo('*****@*****.**'); if ($email->type == "SUGGESTION-O") { $message->addTo("*****@*****.**"); } $message->setFrom(array(Yii::app()->params['adminEmail'] => 'El Equipo Nissan Ecuador')); } } //$message->addTo("*****@*****.**"); $message->setFrom(array(Yii::app()->params['adminEmail'] => 'El Equipo Nissan Ecuador')); Yii::app()->mail->send($message); $this->render('satisfaction_finished', array('suggestion' => $suggestion)); } } else { if ($suggestion) { $this->render('satisfaction', array('model' => $model, 'suggestion' => $suggestion)); } } }
public function actionRequestResetPw($state = '') { if (Yii::app()->params['reset_token_hours'] <= 0) { throw new CHttpException(404, Yii::t('mc', 'The requested page does not exist.')); } $model = new User(); $model->unsetAttributes(); if (isset($_POST['User'])) { $state = 'info'; $user = false; if (strlen(@$_POST['User']['email'])) { $model->email = '=' . $_POST['User']['email']; $prov = $model->search(); if ($prov->itemCount === 1) { $user = $prov->getData(); $user = $user[0]; } } if (!$user || $user->email !== $_POST['User']['email']) { Yii::app()->user->setFlash('reset-error', Yii::t('mc', 'No account found for this email address.')); } else { $ll = substr(md5($user->id . '_' . time() . '_' . rand()), 8, 22); $tt = time() + Yii::app()->params['reset_token_hours'] * 3600; $l = $tt . 'l' . $ll; $user->reset_hash = md5($tt . '_' . $ll); if (!$user->save(false)) { Yii::log('Error saving password reset hash for user ' . $user->name); Yii::app()->user->setFlash('reset-error', Yii::t('mc', 'Error generating password reset token.')); } $message = new YiiMailMessage(); $message->setFrom(array(Yii::app()->params['admin_email'] => Yii::app()->params['admin_name'])); $message->setTo(array($user->email => $user->name)); $message->view = 'resetPw'; $message->setBody(array('name' => $user->name, 'l' => $l, 'host' => Yii::app()->request->getHostInfo(), 'panel' => Yii::app()->request->getBaseUrl(true))); Yii::log('Sending password reset email'); if (!Yii::app()->mail->send($message)) { Yii::log('Error sending assign password reset link to ' . $user->email); Yii::app()->user->setFlash('reset-error', Yii::t('mc', 'Error sending password reset link.')); } else { Yii::app()->user->setFlash('reset-success', Yii::t('mc', 'A password reset link has been sent to your email address.')); } } $this->redirect(array('site/requestResetPw', 'state' => 'info')); } $this->render('requestResetPw', array('model' => $model, 'state' => $state)); }
/** * password recovery */ public function actionPassrecovery() { $model = new User('passrecovery'); if (isset($_POST['User'])) { $model->attributes = $_POST['User']; $user = User::model()->findByAttributes(array('email' => $model->email)); if ($user === null) { $model->addError('password', Yii::t('app', 'No such user with this email.')); } else { $passchange_url = Yii::app()->createAbsoluteUrl('user/passchange', ['code' => md5($user->password)]); $message = new YiiMailMessage(); $message->view = 'passrecovery'; $message->setBody(['passchange_url' => $passchange_url], 'text/html'); $message->subject = Yii::t('mail', 'Password recovery'); $message->addTo($user->email); $message->setFrom(['*****@*****.**' => Yii::app()->name . ' Notification']); if (Yii::app()->mail->send($message)) { Yii::app()->user->setFlash('info', Yii::t('app', "На ваш почтовый ящик отправлено письмо с дальнейшими инструкциями.")); $this->redirect(Yii::app()->homeUrl); } } } // display the passrecovery form $this->render('passrecovery', array('model' => $model)); }
public function actionDiagnostic() { $medio = "default"; if (isset($_GET["medio"])) { $medio = $_GET["medio"]; } $client = new Client(); $vehicle = new VehicleClient(); $replacement = new Replacement(); $criteria2 = new CDbCriteria(); //$criteria2->condition = 'id = 1 OR id = 2 OR id = 9 OR id = 10 OR id = 11 OR id = 13 OR id = 14 OR id= 15 OR id = 16'; $concessioners = Concessioner::model()->findAllbyAttributes(array(), $criteria2); $criteria = new CDbCriteria(); //$criteria->condition = 'id != 36'; $criteria->order = 'name'; $versions = VehicleVersion::model()->with('vehicle')->findAllbyAttributes(array(), $criteria); if (isset($_POST['ajax']) && $_POST['ajax'] === 'replacement-form') { echo CActiveForm::validate($client); Yii::app()->end(); } if (isset($_POST['siguiente'])) { if (isset($_POST['Client']) && isset($_POST['Replacement']) && isset($_POST['VehicleClient'])) { $client = new Client(); $client->attributes = $_POST['Client']; $client->save(); $vehicle = new VehicleClient(); $vehicle->attributes = $_POST['VehicleClient']; //die(print_r($vehicle->attributes)); $vehicle->kilometer = "1"; $vehicle->save(); $replacement = new Replacement(); $replacement->attributes = $_POST['Replacement']; $replacement->client_id = $client->primaryKey; $replacement->vehicle_id = $vehicle->primaryKey; if ($replacement->save()) { $rep = Replacement::model()->findByPk($replacement->primaryKey); $message = new YiiMailMessage(); $message->view = 'repuesto'; $message->setBody(array("replacement" => $rep), 'text/html'); $message->setSubject('Prospecto para repuesto'); foreach ($rep->concessioner->emails as $email) { if ($email->type == "REPLACEMENT") { $message->addTo($email->description); } } $message->addTo("*****@*****.**"); $message->addTo("*****@*****.**"); $message->addTo("*****@*****.**"); $message->addTo("*****@*****.**"); $message->setFrom(array(Yii::app()->params['adminEmail'] => 'El Equipo Nissan Ecuador')); Yii::app()->mail->send($message); $this->render('result', array("client" => $client, "vehicle" => $vehicle, "replacement" => $replacement)); } else { $this->render('error'); } } //$this->render('index',array('concessioners'=>$concessioners,"client"=>$client,"vehicle"=>$vehicle,"replacement"=>$replacement)); } else { $this->render('index_d', array('concessioners' => $concessioners, "client" => $client, "vehicle" => $vehicle, "replacement" => $replacement, "versions" => $versions, "medio" => $medio)); } }
public function actionTest() { $message = new YiiMailMessage(); $message->view = '48hours_repuesto'; $message->setSubject('¿Cotizamos sus respuestos?'); $message->setBody(array(), 'text/html'); $message->addTo("*****@*****.**"); $message->addTo("*****@*****.**"); $message->setFrom(array(Yii::app()->params['adminEmail'] => 'El Equipo Nissan Ecuador')); if (Yii::app()->mail->send($message)) { echo "envio 1"; } $message = new YiiMailMessage(); $message->view = '48hours_sugerencia'; $message->setSubject('¿Un asesor comercial se ha contactado con usted?'); $message->setBody(array(), 'text/html'); $message->addTo("*****@*****.**"); $message->addTo("*****@*****.**"); $message->setFrom(array(Yii::app()->params['adminEmail'] => 'El Equipo Nissan Ecuador')); if (Yii::app()->mail->send($message)) { echo "envio 2"; } die(""); }
/** * Отправляет почтовые уведомления о новом комментарии в посте. Вызывается из self::afterCommentAdd(). * * @param Comment $comment - добавленный комментарий * @param Comment $parent - родительский комментарий (пустой объект, если в корень) */ protected function comment_mail($comment, $parent, $debug = false) { $subj = "Комментарий в посте "; if ($this->title == "") { $subj .= "{$this->author->login} от " . Yii::app()->dateFormatter->formatDateTime($this->cdate, "medium", "short"); } else { $subj = "\"{$this->title}\""; } // Шлём уведомления на почту автору поста, если это не мой пост if ($this->author->id != Yii::app()->user->id and $this->author->ini_get(User::INI_MAIL_COMMENTS)) { $msg = new YiiMailMessage($subj); $msg->view = "comment_post"; $msg->setFrom(array(Yii::app()->params["commentEmail"] => Yii::app()->user->login . " - комментарий")); $msg->addTo($this->author->email); $msg->setBody(array("comment" => $comment, "post" => $this), "text/html"); Yii::app()->mail->send($msg); if ($debug) { $debug_text = "From: " . print_r($msg->from, true) . "\nTo: " . print_r($msg->to, true) . "\nSubj: {$msg->subject}\n{$msg->body}\n\n"; file_put_contents($_SERVER["DOCUMENT_ROOT"] . "/{$msg->view}.email.html", $debug_text); } } // Шлём уведомление на почту автору комментария, на который ответили, если я отвечал не себе и не автору поста (в последнем случае, он уже получил уведомление) if ($parent->id and $parent->author->id != Yii::app()->user->id and $parent->author->id != $this->author->id and $parent->author->ini_get(User::INI_MAIL_COMMENTS)) { $msg = new YiiMailMessage($subj); $msg->view = "comment_reply"; $msg->setFrom(array(Yii::app()->params["commentEmail"] => Yii::app()->user->login . " - комментарий")); $msg->addTo($parent->author->email); $msg->setBody(array("comment" => $comment, "parent" => $parent, "post" => $this), "text/html"); Yii::app()->mail->send($msg); if ($debug) { $debug_text = "From: " . print_r($msg->from, true) . "\nTo: " . print_r($msg->to, true) . "\nSubj: {$msg->subject}\n{$msg->body}\n\n"; file_put_contents($_SERVER["DOCUMENT_ROOT"] . "/{$msg->view}.email.html", $debug_text); } } return true; }
public function actionSendResetPassword($field = 'email', $field_value, $userClassName = 'User', $mailViewPath = 'XUser.views.emails', $mailViewName = 'reset_new_password') { Yii::import('XUser.models.' . $userClassName); $user = new $userClassName(); $user = $user->model()->find($field . '=:value', array(':value' => $field_value)); if (is_null($user)) { errorHandler()->log('The user does not exsist.'); $this->result = false; return false; } $new_password = randomString('lower', 10); $user->password = md5($new_password); if (!$user->update(array('password'))) { errorHandler()->log('Resting password has been failed.'); $this->result = false; return false; } // send email to user Yii::app()->mail->viewPath = $mailViewPath; $message = new YiiMailMessage(); $message->view = $mailViewName; $message->setBody(array('user' => $user, 'new_password' => $new_password), 'text/html'); $message->subject = 'Your new password at ' . SETTINGS_SITE_NAME; $message->addTo($user->email); $message->setFrom(array(SETTINGS_MAIL_SERDER_ADDRESS => SETTINGS_MAIL_SENDER_NAME)); Yii::app()->mail->send($message); $this->result = true; }
public function send() { if (!$this->validate()) { return false; } if (!$this->isNewRecord) { throw new CHttpException(500, "Системная ошибка Mail::send::notNewRecord"); } if (!$this->buddy instanceof User) { throw new CHttpException(500, "Системная ошибка Mail::send::buddyNotUser"); } // 2. Помещаем письмо в свои исходящие $sent = clone $this; $sent->folder = self::SENT; $sent->user_id = Yii::app()->user->id; $sent->buddy_id = $this->buddy->id; $sent->seen = true; // 1. Помещаем письмо в инбокс получателя $this->folder = self::INBOX; $this->user_id = $this->buddy->id; $this->buddy_id = Yii::app()->user->id; $this->seen = false; if (!$this->save()) { return false; } if (!$sent->save()) { return false; } // 3. Если нужно, шлём почту получателю if ($this->buddy->ini_get(User::INI_MAIL_PMAIL)) { $msg = new YiiMailMessage("Вам письмо! Тема: \"" . $this->subj . "\""); $msg->view = "mail"; $msg->setFrom(array(Yii::app()->params["systemEmail"] => Yii::app()->user->login . " - письмо")); $msg->addTo($this->buddy->email); $msg->setBody(array("message" => $this), "text/html"); Yii::app()->mail->send($msg); } return true; }
public function actionCompleteRegistrationAjax() { $client = new Client(); $client->attributes = $_POST['Client']; if ($client->save()) { $drive = new Drive(); $drive->attributes = $_POST['Drive']; $drive->client_id = $client->primaryKey; $drive->creation_date = date("Y-m-d H:i:s"); if ($drive->save()) { $driv = Drive::model()->findByPk($drive->primaryKey); $message = new YiiMailMessage(); $message->view = 'pruebamanejo'; $message->setBody(array("client" => $client, "drive" => $driv), 'text/html'); $message->setSubject('Solicitud Prueba de Manejo'); foreach ($driv->concessioner->emails as $email) { // if($email->type=="DRIVE"){ if ($email->type == "QUOTATION") { $message->addTo($email->description); } } // $message->addTo("*****@*****.**"); // $message->addTo("*****@*****.**"); $message->addTo("*****@*****.**"); $message->addTo("*****@*****.**"); $message->setFrom(array(Yii::app()->params['adminEmail'] => 'El Equipo Nissan Ecuador')); Yii::app()->mail->send($message); echo json_encode(true); } else { echo json_encode(false); } } }