Beispiel #1
0
 /**
  * Subscribe
  *
  * Statuses:
  * 0 - error
  * 1 - success
  * 2 - already subscribed
  *
  * @Post("/subscribe")
  */
 public function subscribeAction()
 {
     $this->view->disable();
     if ($this->request->isAjax()) {
         $email = $this->request->get("email", "email");
         $status = 1;
         // If a person is already subscribed
         if (Subscribers::findFirst("email='{$email}'")) {
             $status = 2;
         } else {
             try {
                 $client = new PostmarkClient($this->config->POSTMARK->POSTMARK_API);
                 $message = ['To' => $email, 'From' => $this->config->POSTMARK->POSTMARK_FROM, 'Subject' => $this->strings->Subscribe_subject, 'HtmlBody' => "<html><body>{$this->strings->Subscribe_body}</body></html>"];
                 $send = $client->sendEmailBatch([$message]);
                 $subscribe = new Subscribers();
                 $subscribe->email = $email;
                 $subscribe->added = time();
                 if (!$subscribe->save()) {
                     $status = 0;
                 }
             } catch (PostmarkException $ex) {
                 if ($ex) {
                     $status = 0;
                 }
             }
         }
         echo $status;
     }
 }