示例#1
0
 public function actionSendMail()
 {
     /** @var $cs CClientScript */
     $session = new CHttpSession();
     $session->open();
     if (isset($session['orderVariations']) && is_array($session['orderVariations']) && count($session['orderVariations']) > 0) {
         $ReceiverMail = Settings::model()->find("setting_name='email_to'");
         $message_body = '<!DOCTYPE HTML><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /></head><body><table>';
         $message_body .= isset($_POST['enterprise']) ? '<tr><td colspan="2">' . Yii::t('strings', 'Enterprise') . ':' . $_POST['enterprise'] . "</td></tr>" : '';
         $message_body .= isset($_POST['first_name']) ? '<tr><td colspan="2">' . Yii::t('strings', 'First Name') . ':' . $_POST['first_name'] . "</td></tr>" : '';
         $message_body .= isset($_POST['last_name']) ? '<tr><td colspan="2">' . Yii::t('strings', 'Last Name') . ':' . $_POST['last_name'] . "</td></tr>" : '';
         $message_body .= isset($_POST['address']) ? '<tr><td colspan="2">' . Yii::t('strings', 'Address') . ':' . $_POST['address'] . "</td></tr>" : '';
         $message_body .= isset($_POST['post_code']) ? '<tr><td colspan="2">' . Yii::t('strings', 'Post Code') . ':' . $_POST['post_code'] . "</td></tr>" : '';
         $message_body .= isset($_POST['city']) ? '<tr><td colspan="2">' . Yii::t('strings', 'City') . ':' . $_POST['city'] . "</td></tr>" : '';
         $message_body .= isset($_POST['tel']) ? '<tr><td colspan="2">' . Yii::t('strings', 'Telephone') . ':' . $_POST['tel'] . "</td></tr>" : '';
         $message_body .= isset($_POST['fax']) ? '<tr><td colspan="2">' . Yii::t('strings', 'Fax') . ':' . $_POST['fax'] . "</td></tr>" : '';
         $message_body .= isset($_POST['email']) ? '<tr><td colspan="2">' . Yii::t('strings', 'Email') . ':' . $_POST['email'] . "</td></tr>" : '';
         $message_body .= isset($_POST['notes']) ? '<tr><td colspan="2">' . Yii::t('strings', 'Notes') . ':' . $_POST['notes'] . "</td></tr>" : '';
         $header = 'Content-type: text/html; charset=utf-8' . "\n" . "From: " . $_POST['last_name'] . " " . $_POST['first_name'] . " <" . $_POST['email'] . ">\n";
         $aOrderVariations = $session['orderVariations'];
         foreach ($aOrderVariations as $variation_id) {
             $Product2variation = Product2variation::model()->find('variation_id=' . $variation_id);
             $product = ProductDescription::model()->find('product_id=' . $Product2variation['product_id'] . ' AND language_id=' . $this->language_id);
             $Variation = Variation::model()->find('variation_id=' . $variation_id);
             $VariationDescription = VariationDescription::model()->find('variation_id=' . $variation_id . ' AND language_id=' . $this->language_id);
             $message_body .= Yii::t('strings', '<tr><td colspan="2">' . 'Order product:') . "</td></tr>";
             $message_body .= '<tr><td><img src="' . Yii::app()->request->getBaseUrl(true) . '/uploads/images/' . $Variation['variation_image'] . '" alt="product_image" width="100" height="100"/></td>';
             $message_body .= '<td> -- ' . $VariationDescription['variation_description'] . '(' . $product['product_name'] . ')' . "</td></tr>";
         }
         $message_body .= '</table></body></html>';
         //echo json_encode(array('message' => Yii::t('strings', 'Your order was sent successfully')));
         //exit;
         if (mail($ReceiverMail['setting_value'], Yii::t('strings', 'Order'), $message_body, $header)) {
             $session->destroy();
             echo json_encode(array('message' => Yii::t('strings', 'Your order was sent successfully')));
             exit;
         }
     }
     //$this->render('sendmail');
 }