Ejemplo n.º 1
0
 public static function addToQueue($to, $cc, $bcc, $scenarioName = "", $data = "")
 {
     $model = new EmailQueue();
     $model->to = $to;
     $model->cc = $cc;
     $model->bcc = $bcc;
     $model->attempts = 0;
     if ($scenarioName) {
         $scenario = EmailTemplatesApi::getTemplateByScenario($scenario);
         if ($scenario) {
             // Change Template Variables here
             $model->from_email = $scenario->from_email;
             $model->from_name = $scenario->from_name;
             $model->subject = $scenario->subject;
             $model->body_html = $scenario->body_html;
             $model->body_plain = $scenario->body_plain;
         }
     } elseif ($data) {
         $model->from_email = $data["from_email"];
         $model->from_name = $data["from_name"];
         $model->subject = $data["subject"];
         $model->body_html = $data["body_html"];
         $model->body_plain = $data["body_plain"];
     } else {
         return false;
     }
     return $model->save();
 }
 /**
  * Displays the contact page
  */
 public function actionContact()
 {
     $model = CustomPage::LoadByRequestUrl('contact-us');
     $this->pageTitle = $model->PageTitle;
     $this->pageDescription = $model->meta_description;
     $this->breadcrumbs = array($model->title => $model->RequestUrl);
     $this->layout = "//layouts/column" . $model->column_template;
     $ContactForm = new ContactForm();
     if (isset($_POST['ContactForm'])) {
         $ContactForm->attributes = $_POST['ContactForm'];
         if ($ContactForm->validate()) {
             $objEmail = new EmailQueue();
             if (!Yii::app()->user->isGuest) {
                 $objCustomer = Customer::GetCurrent();
                 $objEmail->customer_id = $objCustomer->id;
                 $ContactForm->fromName = $objCustomer->mainname;
                 $ContactForm->fromEmail = $objCustomer->email;
             }
             $strHtmlBody = $this->renderPartial('/mail/_contactform', array('model' => $ContactForm), true);
             $strSubject = Yii::t('email', 'Contact Us:') . $ContactForm->contactSubject;
             $objEmail->htmlbody = $strHtmlBody;
             $objEmail->subject = $strSubject;
             $orderEmail = _xls_get_conf('ORDER_FROM', '');
             $objEmail->to = empty($orderEmail) ? _xls_get_conf('EMAIL_FROM') : $orderEmail;
             $objHtml = new HtmlToText();
             //If we get back false, it means conversion failed which 99.9% of the time means improper HTML.
             $strPlain = $objHtml->convert_html_to_text($strHtmlBody);
             if ($strPlain !== false) {
                 $objEmail->plainbody = $strPlain;
             }
             if (!$objEmail->save()) {
                 Yii::log("Error creating email " . print_r($objEmail, true) . " " . print_r($objEmail->getErrors(), true), 'error', 'application.' . __CLASS__ . "." . __FUNCTION__);
             }
             Yii::app()->user->setFlash('success', Yii::t('email', 'Message sent. Thank you for contacting us. We will respond to you as soon as possible.'));
             //Attempt to use an AJAX call to send the email. If it doesn't work, the Download process will catch it anyway.
             $jsScript = "\$.ajax({url:\"" . CController::createUrl('site/sendemail', array("id" => $objEmail->id)) . "\"});";
             Yii::app()->clientScript->registerScript('sendemail', $jsScript, CClientScript::POS_READY);
         } else {
             Yii::app()->user->setFlash('error', Yii::t('cart', 'Please check your form for errors.'));
             if (YII_DEBUG) {
                 Yii::app()->user->setFlash('error', print_r($ContactForm->getErrors(), true));
             }
         }
     }
     if (!Yii::app()->user->isGuest) {
         $objCustomer = Customer::GetCurrent();
         $ContactForm->fromName = $objCustomer->mainname;
         $ContactForm->fromEmail = $objCustomer->email;
     }
     $this->canonicalUrl = $model->canonicalUrl;
     $this->render('contact', array('ContactForm' => $ContactForm, 'model' => $model));
 }
Ejemplo n.º 3
0
 /**
  * Create the email notifications and save to the db.
  *
  * @param Cart/ShoppingCart $objCart
  * @return void
  * @throws Exception
  */
 public static function emailReceipts($objCart)
 {
     if ($objCart instanceof Cart === false && $objCart instanceof ShoppingCart == false) {
         Yii::log("Invalid Cart Object passed. Emails notifications not created", 'error', 'application.' . __CLASS__ . "." . __FUNCTION__);
         throw new Exception(Yii::t('checkout', 'Error creating email notifications, the cart was not valid.'));
     }
     if (_xls_get_conf('EMAIL_SEND_CUSTOMER', 0) == 1) {
         $strHtmlBody = Yii::app()->controller->renderPartial('/mail/_customerreceipt', array('cart' => $objCart), true);
         $strSubject = _xls_format_email_subject('EMAIL_SUBJECT_CUSTOMER', $objCart->customer->first_name . ' ' . $objCart->customer->last_name, $objCart->id_str);
         $objEmail = new EmailQueue();
         $objEmail->customer_id = $objCart->customer_id;
         $objEmail->htmlbody = $strHtmlBody;
         $objEmail->cart_id = $objCart->id;
         $objEmail->subject = $strSubject;
         $objEmail->to = $objCart->customer->email;
         // If we get back false, it means conversion failed which 99.9% of
         // the time means improper HTML.
         $strPlain = strip_tags($strHtmlBody);
         if ($strPlain !== false) {
             $objEmail->plainbody = $strPlain;
         }
         $objEmail->save();
     }
     if (_xls_get_conf('EMAIL_SEND_STORE', 0) == 1) {
         $strHtmlBody = Yii::app()->controller->renderPartial('/mail/_customerreceipt', array('cart' => $objCart), true);
         $strSubject = _xls_format_email_subject('EMAIL_SUBJECT_OWNER', $objCart->customer->first_name . ' ' . $objCart->customer->last_name, $objCart->id_str);
         $objEmail = new EmailQueue();
         $objEmail->customer_id = $objCart->customer_id;
         $objEmail->htmlbody = $strHtmlBody;
         $objEmail->cart_id = $objCart->id;
         $objEmail->subject = $strSubject;
         $orderEmail = _xls_get_conf('ORDER_FROM', '');
         $objEmail->to = empty($orderEmail) ? _xls_get_conf('EMAIL_FROM') : $orderEmail;
         // If we get back false, it means conversion failed which 99.9% of
         // the time means improper HTML.
         $strPlain = strip_tags($strHtmlBody);
         if ($strPlain !== false) {
             $objEmail->plainbody = $strPlain;
         }
         $objEmail->save();
     }
 }
Ejemplo n.º 4
0
 public function actionEmail()
 {
     if (Yii::app()->user->isGuest) {
         _xls_404();
     }
     $model = new ShareForm();
     if (isset($_POST['ShareForm'])) {
         $model->attributes = $_POST['ShareForm'];
         if ($model->validate()) {
             $strCode = $model->code;
             //Make sure code we've been passed is valid
             $objWishlist = Wishlist::model()->findByAttributes(array('gift_code' => $strCode));
             if (!$objWishlist->Visible) {
                 _xls_404();
             }
             if (!Yii::app()->user->isGuest) {
                 $objCustomer = Customer::model()->findByPk(Yii::app()->user->Id);
                 $model->fromEmail = $objCustomer->email;
                 $model->fromName = $objCustomer->fullname;
             }
             $strHtmlBody = $this->renderPartial('/mail/_cart', array('model' => $model), true);
             $strSubject = _xls_format_email_subject('EMAIL_SUBJECT_WISHLIST', $objWishlist->customer->fullname, null);
             $objEmail = new EmailQueue();
             $objEmail->customer_id = $objWishlist->customer_id;
             $objEmail->htmlbody = $strHtmlBody;
             $objEmail->subject = $strSubject;
             $objEmail->to = $model->toEmail;
             $objHtml = new HtmlToText();
             //If we get back false, it means conversion failed which 99.9% of the time means improper HTML.
             $strPlain = $objHtml->convert_html_to_text($strHtmlBody);
             if ($strPlain !== false) {
                 $objEmail->plainbody = $strPlain;
             }
             $objEmail->save();
             $response_array = array('status' => "success", 'message' => Yii::t('wishlist', 'Your wish list has been sent'), 'url' => CController::createUrl('site/sendemail', array("id" => $objEmail->id)), 'reload' => true);
         } else {
             $response_array['status'] = 'error';
             $response_array['errormsg'] = _xls_convert_errors($model->getErrors());
         }
         echo json_encode($response_array);
     }
 }
Ejemplo n.º 5
0
 public function executeEmailBulkQueue(sfWebRequest $request)
 {
     $subject = $request->getParameter('subject');
     $to = $request->getParameter('recipients');
     $sender_email = $request->getParameter('sender_email');
     $sender_name = $request->getParameter('sender_name');
     $message = $request->getParameter('message');
     $send_date = $request->getParameter('send_date');
     $priority = $request->getParameter('priority');
     $errors = array();
     // validate recievers
     if (empty($to)) {
         $errors['email'][0] = 'please specify email address';
     } else {
         $recievers = explode(',', $to);
         $pat = '/^([^@\\s]+)@((?:[-a-z0-9]+\\.)+[a-z]{2,})$/i';
         $full_pat = '/^([- a-z0-9]+)\\<(([^@\\s]+)@((?:[-a-z0-9]+\\.)+[a-z]{2,}))\\>$/i';
         $emails = array();
         foreach ($recievers as $reciever) {
             $reciever = trim($reciever);
             if (empty($reciever)) {
                 continue;
             }
             if (preg_match($full_pat, $reciever, $matches)) {
                 $emails[$matches[2]] = $matches[1];
             } elseif (preg_match($pat, $reciever, $matches)) {
                 $emails[$matches[0]] = '';
             } else {
                 if (!isset($errors['email'])) {
                     $errors['email'] = array();
                 }
                 $errors['email'][] = $reciever . ' is unrecognizable email';
             }
         }
     }
     // validate subject
     if (empty($subject)) {
         $errors['subject'] = 'subject required';
     }
     // validate send_date
     if (empty($send_date)) {
         $errors['send_date'] = 'Send date required';
     }
     // validate sender
     $v_email = new sfValidatorEmail(array(), array('invalid' => 'please specify email address'));
     try {
         $sender_email = $v_email->clean($sender_email);
     } catch (sfValidatorError $e) {
         $errors['sender_email'] = $e->__toString();
     }
     // attachments
     $upload_dir = sfConfig::get('sf_upload_dir') . '/' . 'bulk-email-attachments' . '/';
     $files = array();
     foreach ($request->getFiles() as $file) {
         if ($file[0]['error'] != 0) {
             continue;
         }
         if (move_uploaded_file($file[0]["tmp_name"], $upload_dir . $file[0]["name"])) {
             $files[] = array('path' => $upload_dir, 'name' => $file[0]['name']);
         } else {
             //echo '<h1>Error while uploading '.$file[0]["tmp_name"].'/'.$file[0]["name"].' to '.$upload_dir . $file[0]["name"].'</h1>';
             $error['attachment'] = 'Error while uploading ' . $file[0]["name"];
         }
     }
     // catch errors
     if ($errors) {
         $this->email_templates = EmailTemplatePeer::getByPersonId($this->getUser()->getId());
         $this->errors = $errors;
         $this->recipients = $to;
         $this->subject = $subject;
         $this->sender_email = $sender_email;
         $this->sender_name = $sender_name;
         $this->message = $message;
         $this->priority = $priority;
         $this->send_date = $send_date;
         if (!empty($error['attachment'])) {
             $this->attachement_error = $error['attachment'];
         }
         $this->setTemplate('sendBulkQueue');
         return sfView::SUCCESS;
     }
     $email_letter = new EmailLetter();
     $email_letter->setSubject($subject);
     $email_letter->setSenderEmail($sender_email);
     $email_letter->setSenderName($sender_name);
     $email_letter->setBody($message);
     $email_letter->setAttachFilePath(serialize($files));
     $email_letter->setRecipients(implode(',', array_keys($emails)));
     $email_letter->save();
     $email_queue = new EmailQueue();
     $email_queue->setPersonId($this->getUser()->getId());
     $email_queue->setLetterId($email_letter->getId());
     $email_queue->setRequestDate(date('Y-m-d H:i:s', time()));
     $email_queue->setSendDate($send_date);
     $email_queue->setPriority($priority);
     $email_queue->setSendStatus('pending');
     $email_queue->save();
     /*
         $this->getComponent('mail', 'sendBulkQueue', array(
           'subject' => $subject,
           'recievers' => $emails,
           'sender' => array($sender_email => $sender_name),
           'body' => $message,
           'files' => $files,
         ));
     */
     $this->getUser()->setFlash('success', 'Bulk email have successfully queued!');
     $this->redirect($request->getReferer());
 }
Ejemplo n.º 6
0
 public function createErrorEmail($ResultDescription)
 {
     //For certain errors, send the admin email
     if (stripos($ResultDescription, "contradicts information") !== false) {
         //Send email
         $objEmail = new EmailQueue();
         $objEmail->htmlbody = "Amazon Error: " . $ResultDescription;
         $objEmail->subject = "Amazon Error";
         $orderEmail = _xls_get_conf('ORDER_FROM', '');
         $objEmail->to = empty($orderEmail) ? _xls_get_conf('EMAIL_FROM') : $orderEmail;
         Yii::log($objEmail->htmlbody, 'error', 'application.' . __CLASS__ . "." . __FUNCTION__);
         if (!$objEmail->save()) {
             Yii::log("Error saving Email " . print_r($objEmail->getErrors(), true), 'error', 'application.' . __CLASS__ . "." . __FUNCTION__);
         }
     }
 }
Ejemplo n.º 7
0
 public function actionForgotpassword()
 {
     $model = new LoginForm();
     if (isset($_POST['LoginForm'])) {
         Yii::log(print_r($_POST['LoginForm']['email'] . ": Requested a Password Reset Link", true), 'error', 'application.' . __CLASS__ . "." . __FUNCTION__);
         $model->attributes = $_POST['LoginForm'];
         if (empty($model->email)) {
             $response_array = array('status' => "failure", 'message' => Yii::t('global', 'Please enter your email before clicking this link.'));
             echo json_encode($response_array);
             Yii::app()->end();
         }
         $objCustomer = Customer::model()->findByAttributes(array('record_type' => Customer::REGISTERED, 'email' => $model->email));
         if ($objCustomer instanceof Customer) {
             if (is_null($objCustomer->password)) {
                 $response_array = array('status' => "failure", 'message' => Yii::t('global', 'Your email address was found but only as a registered Facebook user. Log in via Facebook.'));
                 echo json_encode($response_array);
                 return;
             }
             if (!$objCustomer->GenerateTempPassword()) {
                 $response_array = array('status' => "failure", 'message' => Yii::t('global', 'Could not reset password, please contact the site administrator.'));
                 echo json_encode($response_array);
                 return;
             }
             $strHtmlBody = $this->renderPartial('/mail/_resetpassword', array('model' => $objCustomer), true);
             $strSubject = Yii::t('global', 'Password reset');
             $objEmail = new EmailQueue();
             $objEmail->htmlbody = $strHtmlBody;
             $objEmail->subject = $strSubject;
             $objEmail->to = $objCustomer->email;
             $objEmail->save();
             $response_array = array('status' => "success", 'message' => Yii::t('wishlist', 'Check your email for password reset link.'), 'url' => CController::createUrl('site/sendemail', array("id" => $objEmail->id)), 'reload' => true);
             echo json_encode($response_array);
         } else {
             $response_array = array('status' => "failure", 'message' => Yii::t('global', 'Your email address was not found in our system.'));
             echo json_encode($response_array);
         }
     } else {
         $response_array = array('status' => "failure", 'message' => Yii::t('global', 'Please enter your email before clicking this link.'));
         echo json_encode($response_array);
     }
 }
Ejemplo n.º 8
0
 public function sendEmailTest()
 {
     $objEmail = new EmailQueue();
     $objEmail->subject = "Test email from " . _xls_get_conf('STORE_NAME');
     $orderEmail = _xls_get_conf('ORDER_FROM', '');
     $objEmail->to = empty($orderEmail) ? _xls_get_conf('EMAIL_FROM') : $orderEmail;
     $objEmail->htmlbody = "<h1>You have successfully received your test email.</h1>";
     $objEmail->save();
     $blnResult = _xls_send_email($objEmail->id, true);
     if ($blnResult) {
         Yii::app()->user->setFlash('warning', 'Test email successfully sent to ' . $objEmail->to . '.');
     } else {
         Yii::app()->user->setFlash('error', 'Error - the test email failed sending to ' . $objEmail->to . '.');
         $objEmail->delete();
     }
 }
Ejemplo n.º 9
0
 /**
  * Create an Email receipt for both the customer and the store, if needed. This goes to our emailqueue table
  * @param $objCart
  */
 public static function EmailReceipts($objCart)
 {
     if (_xls_get_conf('EMAIL_SEND_CUSTOMER', 0) == 1) {
         $strHtmlBody = Yii::app()->controller->renderPartial('/mail/_customerreceipt', array('cart' => $objCart), true);
         $strSubject = _xls_format_email_subject('EMAIL_SUBJECT_CUSTOMER', $objCart->customer->first_name . ' ' . $objCart->customer->last_name, $objCart->id_str);
         $objEmail = new EmailQueue();
         $objEmail->customer_id = $objCart->customer_id;
         $objEmail->htmlbody = $strHtmlBody;
         $objEmail->cart_id = $objCart->id;
         $objEmail->subject = $strSubject;
         $objEmail->to = $objCart->customer->email;
         // If we get back false, it means conversion failed which 99.9% of
         // the time means improper HTML.
         $strPlain = strip_tags($strHtmlBody);
         if ($strPlain !== false) {
             $objEmail->plainbody = $strPlain;
         }
         $objEmail->save();
     }
     if (_xls_get_conf('EMAIL_SEND_STORE', 0) == 1) {
         $strHtmlBody = Yii::app()->controller->renderPartial('/mail/_customerreceipt', array('cart' => $objCart), true);
         $strSubject = _xls_format_email_subject('EMAIL_SUBJECT_OWNER', $objCart->customer->first_name . ' ' . $objCart->customer->last_name, $objCart->id_str);
         $objEmail = new EmailQueue();
         $objEmail->customer_id = $objCart->customer_id;
         $objEmail->htmlbody = $strHtmlBody;
         $objEmail->cart_id = $objCart->id;
         $objEmail->subject = $strSubject;
         $orderEmail = _xls_get_conf('ORDER_FROM', '');
         $objEmail->to = empty($orderEmail) ? _xls_get_conf('EMAIL_FROM') : $orderEmail;
         // If we get back false, it means conversion failed which 99.9% of
         // the time means improper HTML.
         $strPlain = strip_tags($strHtmlBody);
         if ($strPlain !== false) {
             $objEmail->plainbody = $strPlain;
         }
         $objEmail->save();
     }
 }