Exemplo n.º 1
0
 function sendRegConfirm($customer)
 {
     $cust_info = $customer;
     $my = JFactory::getUser();
     $database = JFactory::getDBO();
     $cart = $this->getInstance("cart", "digicomModel");
     $configs = $this->getInstance("Config", "digicomModel");
     $configs = $configs->getConfigs();
     $mes = new stdClass();
     $mes->body = "Template is empty";
     $sql = "SELECT * FROM #__digicom_mailtemplates where `type`='register'";
     $database->setQuery($sql);
     $db = JFactory::getDBO();
     $db->setQuery($sql);
     $mes = $db->loadObjectList();
     $mes = $mes[0];
     $message = $mes->body;
     JTable::addIncludePath(JPATH_COMPONENT_SITE . DS . 'tables');
     $email = $this->getTable("Mail");
     $date = JFactory::getDate();
     $timestamp = $date->toUnix();
     $email->date = $timestamp;
     $email->flag = "register";
     $email->email = trim($my->email);
     $subject = $mes->subject;
     // Replace all variables in template
     $flag = "order";
     $promo = $cart->get_promo($cust_info);
     if ($promo->id > 0) {
         $promoid = $promo->id;
         $promocode = $promo->code;
     } else {
         $promoid = '0';
         $promocode = '0';
     }
     $app = JFactory::getApplication();
     $sitename = trim($configs->get('store_name', 'DigiCom Store')) != '' ? $configs->get('store_name', 'DigiCom Store') : $app->getCfg('sitename');
     $siteurl = trim($configs->get('store_url', '')) != '' ? $configs->get('store_url', '') : $mosConfig_live_site;
     $ship_add = DigiComSiteHelperDigiCom::get_customer_shipping_add($my->id);
     $message = str_replace("[SHIPPING_ADDRESS]", $ship_add, $message);
     $message = str_replace("[SITENAME]", $sitename, $message);
     $message = str_replace("[CUSTOMER_COMPANY_NAME]", $my->company, $message);
     $message = str_replace("../%5BSITEURL%5D", $siteurl, $message);
     $message = str_replace("%5BSITEURL%5D", $siteurl, $message);
     $message = str_replace("[SITEURL]", $siteurl, $message);
     $query = "select `lastname` from `#__digicom_customers` where `id`=" . $my->id;
     $database->setQuery($query);
     $lastname = $database->loadResult();
     $message = str_replace("[CUSTOMER_USER_NAME]", $my->username, $message);
     $message = str_replace("[CUSTOMER_FIRST_NAME]", $my->name, $message);
     $message = str_replace("[CUSTOMER_LAST_NAME]", $lastname, $message);
     $message = str_replace("[CUSTOMER_EMAIL]", $my->email, $message);
     $message = str_replace("[TODAY_DATE]", date($configs->get('time_format', 'd-m-Y'), $timestamp), $message);
     $message = str_replace("[CUSTOMER_PASSWORD]", $customer['password_confirm'], $message);
     $displayed = array();
     $product_list = '';
     $email->body = $message;
     //subject
     $subject = str_replace("[SHIPPING_ADDRESS]", $ship_add, $subject);
     $subject = str_replace("[SITENAME]", $sitename, $subject);
     $subject = str_replace("[CUSTOMER_COMPANY_NAME]", $my->copany, $subject);
     $subject = str_replace("../%5BSITEURL%5D", $siteurl, $subject);
     $subject = str_replace("%5BSITEURL%5D", $siteurl, $subject);
     $subject = str_replace("[SITEURL]", $siteurl, $subject);
     $subject = str_replace("[CUSTOMER_USER_NAME]", $my->username, $subject);
     $subject = str_replace("[CUSTOMER_FIRST_NAME]", $my->name, $subject);
     $subject = str_replace("[CUSTOMER_LAST_NAME]", $lastname, $subject);
     $subject = str_replace("[CUSTOMER_EMAIL]", $my->email, $subject);
     $subject = str_replace("[TODAY_DATE]", date($configs->get('time_format', 'd-m-Y'), $timestamp), $subject);
     $subject = str_replace("[CUSTOMER_PASSWORD]", $customer['password_confirm'], $subject);
     $subject = html_entity_decode($subject, ENT_QUOTES);
     $message = html_entity_decode($message, ENT_QUOTES);
     // Send email to user
     //			global $mosConfig_mailfrom, $mosConfig_fromname, $configs;
     $mosConfig_mailfrom = $app->getCfg("mailfrom");
     $mosConfig_fromname = $app->getCfg("fromname");
     if ($configs->get('usestoremail', 1) == '1' && strlen(trim($configs->get('store_name', 'DigiCom Store'))) > 0 && strlen(trim($configs->get('store_email', ''))) > 0) {
         $adminName2 = $configs->get('store_name', 'DigiCom Store');
         $adminEmail2 = $configs->get('store_email', '');
     } else {
         if ($mosConfig_mailfrom != "" && $mosConfig_fromname != "") {
             $adminName2 = $mosConfig_fromname;
             $adminEmail2 = $mosConfig_mailfrom;
         } else {
             $query = "SELECT name, email" . "\n FROM #__users" . "\n WHERE LOWER( usertype ) = 'superadministrator'" . "\n OR LOWER( usertype ) = 'super administrator'";
             $database->setQuery($query);
             $rows = $database->loadObjectList();
             $row2 = $rows[0];
             $adminName2 = $row2->name;
             $adminEmail2 = $row2->email;
         }
     }
     $mailSender = JFactory::getMailer();
     $mailSender->IsHTML(true);
     $mailSender->addRecipient($my->email);
     $mailSender->setSender(array($adminEmail2, $adminName2));
     $mailSender->setSubject($subject);
     $mailSender->setBody($message);
     if (!$mailSender->Send()) {
         //			<Your error code management>
     } else {
         $email->store();
     }
     //			mosMail( $adminEmail2, $adminName2, $my->email, $subject, $message, 1 ); // Send mail
     if ($configs->get('sendmailtoadmin', 1) != 0) {
         $mailSender = JFactory::getMailer();
         $mailSender->IsHTML(true);
         $mailSender->addRecipient($adminEmail2);
         $mailSender->setSender(array($adminEmail2, $adminName2));
         $mailSender->setSubject($subject);
         $mailSender->setBody($message);
         if (!$mailSender->Send()) {
             //					<Your error code management>
         } else {
             $email->store();
         }
         $site_config = JFactory::getConfig();
         $tzoffset = $site_config->get('offset');
         $today = date('Y-m-d H:i:s', time() + $tzoffset);
         $sql = "insert into #__digicom_logs(`userid`, `emailname`, `to`, `subject`, `body`, `send_date`) values (" . $my->id . ", 'New Customer Email', '" . $my->email . "', '" . addslashes(trim($subject)) . "', '" . addslashes($message) . "', '" . $today . "')";
         $db->setQuery($sql);
         $db->query();
     }
 }