Beispiel #1
0
 public function actionSendEmail($id, $isFancy = 0)
 {
     $apartment = Apartment::model()->findByPk($id);
     if (!$apartment) {
         throw404();
     }
     if (!param('use_module_request_property')) {
         throw404();
     }
     $model = new SendMailForm();
     if (isset($_POST['SendMailForm'])) {
         $model->attributes = $_POST['SendMailForm'];
         if (!Yii::app()->user->isGuest) {
             $model->senderEmail = Yii::app()->user->email;
             $model->senderName = Yii::app()->user->username;
         }
         $model->ownerId = $apartment->user->id;
         $model->ownerEmail = $apartment->user->email;
         $model->ownerName = $apartment->user->username;
         $model->apartmentUrl = $apartment->getUrl();
         if ($model->validate()) {
             $notifier = new Notifier();
             $notifier->raiseEvent('onRequestProperty', $model, array('forceEmail' => $model->ownerEmail));
             Yii::app()->user->setFlash('success', tt('Thanks_for_request', 'apartments'));
             $model = new SendMailForm();
             // clear fields
         } else {
             $model->unsetAttributes(array('verifyCode'));
             Yii::app()->user->setFlash('error', tt('Error_send_request', 'apartments'));
         }
     }
     if ($isFancy) {
         //Yii::app()->clientscript->scriptMap['*.js'] = false;
         Yii::app()->clientscript->scriptMap['jquery.js'] = false;
         Yii::app()->clientscript->scriptMap['jquery.min.js'] = false;
         Yii::app()->clientscript->scriptMap['jquery-ui.min.js'] = false;
         $this->renderPartial('send_email', array('apartment' => $apartment, 'isFancy' => true, 'model' => $model), false, true);
     } else {
         $this->render('send_email', array('apartment' => $apartment, 'isFancy' => false, 'model' => $model));
     }
 }
 function resendAction()
 {
     $this->view->title = $this->view->translate("Wildfire") . " - " . $this->view->translate("INVITATION_MAIL_SEND");
     //
     $form = new SendMailForm();
     $consumer = $this->_currentUser;
     $isSentSuccessfully = false;
     $sendto = $this->_request->getParam('sendto');
     if ($this->_request->isPost()) {
         //POST
         $formData = $this->_request->getPost();
         if ($form->isValid($formData)) {
             $currentTime = date("Y-m-d H:i:s");
             //get signup_auth_code
             $db = Zend_Registry::get('db');
             $select = $db->select();
             $select->from('signup_auth_code', array('id', 'auth_code'))->join('invitation_email', 'invitation_email.signup_auth_code_id = signup_auth_code.id', null)->where('invitation_email.consumer_id = ?', $this->_currentUser->id)->where('invitation_email.to = ?', $sendto);
             $signup_auth_code_array = $db->fetchAll($select);
             $signup_auth_code_id = $signup_auth_code_array[0]['id'];
             $signup_auth_code = $signup_auth_code_array[0]['auth_code'];
             //send mail
             $emailSubject = $this->view->translate('Invitation_Email_subject');
             $emailBody = $this->view->translate('Invitation_Email_body');
             $stringChange = array('?USERNAME?' => $this->_currentUser['name'], '?EMAIL?' => $this->_currentUser['email'], '?MESSAGE?' => $form->getValue('message'), '?AUTHCODE?' => (string) $signup_auth_code);
             $emailSubject = strtr($emailSubject, $stringChange);
             $emailBody = strtr($emailBody, $stringChange);
             $config = Zend_Registry::get('config');
             $smtpSender = new Zend_Mail_Transport_Smtp($config->smtp->friend->mail->server, array('username' => $config->smtp->friend->mail->username, 'password' => $config->smtp->friend->mail->password, 'auth' => $config->smtp->friend->mail->auth, 'ssl' => $config->smtp->friend->mail->ssl, 'port' => $config->smtp->friend->mail->port));
             //												$smtpSender = new Zend_Mail_Transport_Smtp(
             //																			'smtp.163.com',array(
             //																			'username'=>'*****@*****.**',
             //																			'password'=>'19990402',
             //																			'auth'=>'login'));
             Zend_Mail::setDefaultTransport($smtpSender);
             $mail = new Zend_Mail('utf-8');
             $langNamespace = new Zend_Session_Namespace('Lang');
             if ($langNamespace->lang == 'en' || $langNamespace->lang == 'EN') {
                 $mail->setSubject($emailSubject);
             } else {
                 $mail->setSubject("=?UTF-8?B?" . base64_encode($emailSubject) . "?=");
             }
             $mail->setBodyText($emailBody);
             $mail->setFrom($config->smtp->friend->mail->username, $consumer->name);
             $mail->addHeader('Reply-To', $consumer->email);
             //												$mail->setFrom('*****@*****.**',$this->view->translate('Wildfire'));
             $mail->addTo($sendto);
             //save into invitation_email
             $currentTime = date("Y-m-d H:i:s");
             $invitationEmailModel = new InvitationEmail();
             $invitationEmail = $invitationEmailModel->createRow();
             $invitationEmail->subject = $emailSubject;
             $invitationEmail->content = $form->getValue('message');
             $invitationEmail->consumer_id = $this->_currentUser->id;
             $invitationEmail->to = $sendto;
             $invitationEmail->signup_auth_code_id = $signup_auth_code_id;
             $invitationEmail->date = $currentTime;
             $invitationEmail->save();
             //send mail after saving
             $mail->send();
             $this->view->showMessage = $this->view->translate('INVITATION_MAIL_LIST_PART1_Sucessful');
             $isSentSuccessfully = true;
             if (!$isSentSuccessfully) {
                 $this->view->showMessage = $this->view->translate('INVITATION_MAIL_LIST_PART1_Fail');
             }
         } else {
             $this->view->showMessage = $this->view->translate('INVITATION_MAIL_LIST_PART1_DataError');
         }
     }
 }