示例#1
0
 public function execute(&$params)
 {
     $eml = new InlineEmail();
     // make subject optional in order to support legacy flows
     $eml->requireSubjectOnCustom = false;
     $options =& $this->config['options'];
     $eml->to = $this->parseOption('to', $params);
     $historyFlag = false;
     if (isset($params['model'])) {
         $historyFlag = true;
         $eml->targetModel = $params['model'];
     }
     if (isset($options['cc']['value'])) {
         $eml->cc = $this->parseOption('cc', $params);
     }
     if (isset($options['bcc']['value'])) {
         $eml->bcc = $this->parseOption('bcc', $params);
     }
     //$eml->from = array('address'=>$this->parseOption('from',$params),'name'=>'');
     $eml->credId = $this->parseOption('from', $params);
     if ($eml->credentials && $eml->credentials->user) {
         $eml->setUserProfile($eml->credentials->user->profile);
     }
     //printR ($eml->from, true);
     $eml->subject = $this->parseOption('subject', $params);
     // "body" option (deliberately-entered content) takes precedence over template
     if (isset($options['body']['value']) && !empty($options['body']['value'])) {
         $eml->scenario = 'custom';
         $eml->message = InlineEmail::emptyBody($this->parseOption('body', $params));
         $prepared = $eml->prepareBody();
         // $eml->insertSignature(array('<br /><br /><span style="font-family:Arial,Helvetica,sans-serif; font-size:0.8em">','</span>'));
     } elseif (!empty($options['template']['value'])) {
         $eml->scenario = 'template';
         $eml->template = $this->parseOption('template', $params);
         $prepared = $eml->prepareBody();
     } else {
         $prepared = true;
         // no email body
     }
     if (!$prepared) {
         // InlineEmail failed validation
         $errors = $eml->getErrors();
         return array(false, array_shift($errors));
     }
     list($success, $message) = $this->checkDoNotEmailFields($eml);
     if (!$success) {
         return array($success, $message);
     }
     $result = $eml->send($historyFlag);
     if (isset($result['code']) && $result['code'] == 200) {
         if (YII_UNIT_TESTING) {
             return array(true, $eml->message);
         } else {
             return array(true, "");
         }
     } else {
         return array(false, Yii::t('app', "Email could not be sent"));
     }
 }
示例#2
0
 public function testActionHeader()
 {
     $this->eml = new InlineEmail('template');
     $template = $this->docs('testEmailTemplate');
     $this->eml->template = $template->id;
     $this->eml->modelId = $this->contacts('testAnyone')->id;
     $this->eml->modelName = 'Contacts';
     $this->eml->subject = 'Test Email Subject';
     $this->eml->from = array('name' => 'Sales Rep', 'address' => '*****@*****.**');
     $this->eml->to = '"Testfirstname Testlastname" <*****@*****.**>';
     $this->eml->prepareBody();
     $record = $this->eml->insertInBody($this->eml->actionHeader, 1, 1);
     $this->assertTrue((bool) preg_match('/<body>(.*)<\\/body>/um', $record, $matches), "Body isn't an HTML document. What's going on here? Body = " . $record);
     $content = $matches[1];
     //		$contentLines = explode('<br />', $content);
     //		$subjectLine = $contentLines[0];
     //		$fromLine = $contentLines[1];
     //		$toLine = $contentLines[2];
     $this->assertRegExp('/(<strong>Subject: <\\/strong>.*)<br \\/>/u', $content);
     $this->assertRegExp('/(<strong>From: <\\/strong>.*)<br \\/>/u', $content);
     $this->assertRegExp('/(<strong>To: <\\/strong>.*)<br \\/>/u', $content);
 }
示例#3
0
 public function actionInviteUsers()
 {
     if (isset($_POST['emails'])) {
         $list = $_POST['emails'];
         $body = "Hello,\n\nYou are receiving this email because your X2Engine administrator has invited you to create an account.\nPlease click on the link below to create an account at X2Engine!\n\n";
         $subject = "Create Your X2Engine User Account";
         $list = trim($list);
         $emails = explode(',', $list);
         foreach ($emails as &$email) {
             $key = substr(str_shuffle(str_repeat('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789', 16)), 0, 16);
             $user = new User('invite');
             $email = trim($email);
             $user->inviteKey = $key;
             $user->temporary = 1;
             $user->emailAddress = $email;
             $user->status = 0;
             $userList = User::model()->findAllByAttributes(array('emailAddress' => $email, 'temporary' => 1));
             foreach ($userList as $userRecord) {
                 if (isset($userRecord)) {
                     $userRecord->delete();
                 }
             }
             $user->save();
             $link = CHtml::link('Create Account', (@$_SERVER['HTTPS'] == 'on' ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . $this->createUrl('/users/users/createAccount', array('key' => $key)));
             $mail = new InlineEmail();
             $mail->to = $email;
             // Get email password
             $cred = Credentials::model()->getDefaultUserAccount(Credentials::$sysUseId['systemResponseEmail'], 'email');
             if ($cred == Credentials::LEGACY_ID) {
                 $cred = Credentials::model()->getDefaultUserAccount(Yii::app()->user->id, 'email');
             }
             if ($cred != Credentials::LEGACY_ID) {
                 $mail->credId = $cred;
             }
             $mail->subject = $subject;
             $mail->message = $body . "<br><br>" . $link;
             $mail->contactFlag = false;
             if ($mail->prepareBody()) {
                 $mail->deliver();
             } else {
             }
         }
         $this->redirect('admin');
     }
     $this->render('inviteUsers');
 }