示例#1
0
文件: test.php 项目: vNative/vnative
 /**
  * @before _admin
  */
 public function sendMail()
 {
     $this->noview();
     $cf = Utils::getConfig("cf", "cloudflare");
     try {
         \Shared\Services\Smtp::sendMail($this->org, ['template' => 'testmail', 'user' => $this->user, 'to' => [$cf->api->email], 'subject' => "Testing Mail using SMTP"]);
         var_dump('Mail sent');
     } catch (\Exception $e) {
         var_dump($e->getMessage());
     }
 }
示例#2
0
文件: admin.php 项目: vNative/vnative
 /**
  * @before _secure
  */
 public function notification()
 {
     $this->seo(array("title" => "Notification"));
     $view = $this->getActionView();
     $fields = ['_id', 'name'];
     $arr = User::all(['org_id' => $this->org->_id, 'type' => 'publisher'], $fields);
     $publishers = User::objectArr($arr, $fields);
     $arr = User::all(['org_id' => $this->org->_id, 'type' => 'advertiser'], $fields);
     $advertisers = User::objectArr($arr, $fields);
     $view->set('publishers', $publishers)->set('advertisers', $advertisers);
     switch (RM::post("action")) {
         case 'save':
             $meta = RM::post("meta", "all");
             $message = RM::post("message");
             $success = "Saved Successfully";
             if ($meta !== "all" && (!in_array($meta, array_keys($publishers)) && !in_array($meta, array_keys($advertisers)))) {
                 $view->set('message', "Invalid Request!!");
                 break;
             } else {
                 if ($meta !== "all") {
                     // send mail to the user
                     $usr = User::first(['_id' => $meta], ['name', 'email']);
                     \Shared\Services\Smtp::sendMail($this->org, ['template' => 'notification', 'user' => $usr, 'notification' => $message, 'to' => [$usr->email], 'subject' => "Notification from " . $this->org->name]);
                     $success .= " And Mail sent";
                 }
             }
             $n = new Notification(["org_id" => $this->org->id, "message" => $message, "target" => RM::post("target"), "meta" => $meta]);
             $n->save();
             $view->set("message", $success);
             break;
     }
     if (RM::type() === 'DELETE') {
         $id = RM::get("id");
         $n = Notification::first(["org_id = ?" => $this->org->id, "id = ?" => $id]);
         if ($n) {
             $n->delete();
             $view->set("message", "Deleted Successfully");
         } else {
             $view->set("message", "Notification does not exist");
         }
     }
     $notifications = Notification::all(["org_id = ?" => $this->org->id], [], "created", "desc");
     $view->set("notifications", $notifications);
 }