コード例 #1
0
ファイル: Invite.php プロジェクト: dioscouri/f3-affiliates
 public function emailSubmit()
 {
     // Validate the form inputs
     // for each email address, send the email
     // track that this user sent these invitations
     // redirect back to /invite-friends/email
     $recip_input = $this->app->split($this->input->get('recipients', null, 'string'));
     $recipients = array();
     foreach ($recip_input as $recip) {
         $recip = trim(strtolower($recip));
         if (!empty($recip) && \Mailer\Factory::instance()->sender()->isEmailAddress($recip)) {
             $recipients[] = $recip;
         }
     }
     $data = array('sender_name' => $this->input->get('sender_name', null, 'string'), 'sender_email' => trim(strtolower($this->input->get('sender_email', null, 'string'))), 'recipients' => $recipients, 'message' => $this->input->get('message', null, 'string'));
     try {
         if (empty($data['sender_email']) || !\Mailer\Factory::instance()->sender()->isEmailAddress($data['sender_email'])) {
             throw new \Exception('Your email address is invalid');
         }
         if (empty($data['sender_name'])) {
             throw new \Exception('Your name is invalid');
         }
         if (empty($data['recipients'])) {
             throw new \Exception('Invalid recipient email(s)');
         }
         if (empty($data['message'])) {
             throw new \Exception('Invalid message');
         }
         foreach ($data['recipients'] as $key => $recipient) {
             try {
                 (new \Affiliates\Models\Invites())->bind(array('affiliate_id' => $this->getIdentity()->id, 'sender_email' => $data['sender_email'], 'sender_name' => $data['sender_name'], 'recipient_email' => $recipient, 'message' => $data['message']))->set('__send_email', true)->save();
                 unset($data['recipients'][$key]);
                 \Dsc\System::addMessage('Invitation sent to ' . $recipient, 'success');
             } catch (\Exception $e) {
                 \Dsc\System::addMessage('Invitation not sent to ' . $recipient, 'warning');
                 \Dsc\System::addMessage($e->getMessage(), 'warning');
             }
         }
     } catch (\Exception $e) {
         \Dsc\System::addMessage('Failed to send invitation(s)', 'error');
         \Dsc\System::addMessage($e->getMessage(), 'error');
         \Dsc\System::instance()->setUserState('invite_friends.email.flash_filled', true);
         $this->flash->store($data);
         $this->app->reroute('/affiliate/invite-friends/email');
     }
     $this->flash->store(array());
     $this->app->reroute('/affiliate/invite-friends/email');
 }
コード例 #2
0
ファイル: Preview.php プロジェクト: dioscouri/f3-mailer
 public function email()
 {
     $f3 = \Base::instance();
     $id = $this->inputfilter->clean($f3->get('PARAMS.id'), 'alnum');
     $email = $this->inputfilter->clean($f3->get('GET.email'), 'string');
     $templateModel = (new \Mailer\Models\Templates())->setState('filter.id', $id);
     $this->app->set('id', $id);
     $mailer = \Dsc\System::instance()->get('mailer');
     try {
         $template = $templateModel->getItem();
         if (empty($template->id)) {
             throw new \Exception();
         }
         //get the event
         $event = (new \Mailer\Models\Events())->setState('filter.id', $template->event_id)->getItem();
         $listenerEvent = 'mailerPreview';
         $parts = explode('.', $event->event_name);
         foreach ($parts as $part) {
             $listenerEvent .= ucfirst($part);
         }
         //the preview event should return the variables
         $results = \Dsc\System::instance()->trigger($listenerEvent);
         $variables = $results->getArgument('variables');
         $view = \Dsc\System::instance()->get('theme');
         if (!empty($variables)) {
             $contents = \Mailer\Factory::getEmailContents($event->event_name, $variables);
             $mailer->sendEvent($email, $contents);
             \Dsc\System::addMessage('Sent Email to : ' . $email . '', 'success');
             $this->app->set('contents', $contents);
             echo $view->renderView('Mailer/Admin/Views::preview/index.php');
         } else {
             \Dsc\System::addMessage('No email sent', 'error');
             $view = \Dsc\System::instance()->get('theme');
             $this->app->set('event', $listenerEvent);
             echo $view->renderView('Mailer/Admin/Views::preview/notsupported.php');
         }
     } catch (\Exception $e) {
         \Dsc\System::instance()->addMessage("Invalid Item: " . $e->getMessage(), 'error');
         return;
     }
 }
コード例 #3
0
ファイル: Email.php プロジェクト: dioscouri/f3-mailer
 /**
  * Overrides PHPMailer::send() in order to add to the Mailer queue
  *
  * @return boolean
  */
 public function send()
 {
     // TODO Use \Dsc\System->mailer?
     return \Mailer\Factory::queue($this);
 }