Пример #1
0
 function sendEmail($subject, $body, $to, $from_email = false, $from_name = false, $reply_to = false, $text = "")
 {
     // No from email? Use the no-reply address.
     if (!$from_email) {
         $from_email = "no-reply@" . (isset($_SERVER["HTTP_HOST"]) ? str_replace("www.", "", $_SERVER["HTTP_HOST"]) : str_replace(array("http://www.", "https://www.", "http://", "https://"), "", DOMAIN));
         $from_name = "BigTree CMS";
     }
     // Parse out from name and reply-to name
     $from = trim($from_email);
     if ($from_name === false && strpos($from, "<") !== false && substr($from, -1, 1) == ">") {
         $from_pieces = explode("<", $from);
         $from_name = trim($from_pieces[0]);
         $from_email = substr($from_pieces[1], 0, -1);
     }
     $reply = trim($reply_to);
     if (strpos($reply, "<") !== false && substr($reply, -1, 1) == ">") {
         $reply_pieces = explode("<", $reply);
         $reply_name = trim($reply_pieces[0]);
         $reply_to = substr($reply_pieces[1], 0, -1);
     }
     if ($this->Service == "local") {
         return BigTree::sendEmail($to, $subject, $body, $text, $from_name ? "{$from_name} <{$from_email}>" : $from_email, $reply_to);
     } elseif ($this->Service == "mandrill") {
         return $this->sendMandrill($subject, $body, $to, $from_email, $from_name, $reply_to, $text);
     } elseif ($this->Service == "mailgun") {
         return $this->sendMailgun($subject, $body, $to, $from_email, $from_name, $reply_to, $text);
     } elseif ($this->Service == "postmark") {
         return $this->sendPostmark($subject, $body, $to, $from_email, $from_name, $reply_to, $text);
     } elseif ($this->Service == "sendgrid") {
         return $this->sendSendGrid($subject, $body, $to, $from_email, $from_name, $reply_to, $text);
     } else {
         throw new Exception("Unknown Email Service");
     }
 }
Пример #2
0
 static function forgotPassword($email)
 {
     global $bigtree;
     $home_page = sqlfetch(sqlquery("SELECT `nav_title` FROM `bigtree_pages` WHERE id = 0"));
     $site_title = $home_page["nav_title"];
     $email = sqlescape($email);
     $user = sqlfetch(sqlquery("SELECT * FROM bigtree_users WHERE email = '{$email}'"));
     if (!$user) {
         return false;
     }
     $hash = sqlescape(md5(md5(md5(uniqid("bigtree-hash" . microtime(true))))));
     sqlquery("UPDATE bigtree_users SET change_password_hash = '{$hash}' WHERE id = '" . $user["id"] . "'");
     $login_root = ($bigtree["config"]["force_secure_login"] ? str_replace("http://", "https://", ADMIN_ROOT) : ADMIN_ROOT) . "login/";
     $html = file_get_contents(BigTree::path("admin/email/reset-password.html"));
     $html = str_ireplace("{www_root}", WWW_ROOT, $html);
     $html = str_ireplace("{admin_root}", ADMIN_ROOT, $html);
     $html = str_ireplace("{site_title}", $site_title, $html);
     $html = str_ireplace("{reset_link}", $login_root . "reset-password/{$hash}/", $html);
     $es = new BigTreeEmailService();
     // Only use a custom email service if a from email has been set
     if ($es->Settings["bigtree_from"]) {
         $reply_to = "no-reply@" . (isset($_SERVER["HTTP_HOST"]) ? str_replace("www.", "", $_SERVER["HTTP_HOST"]) : str_replace(array("http://www.", "https://www.", "http://", "https://"), "", DOMAIN));
         $es->sendEmail("Reset Your Password", $html, $user["email"], $es->Settings["bigtree_from"], "BigTree CMS", $reply_to);
     } else {
         BigTree::sendEmail($user["email"], "Reset Your Password", $html);
     }
     BigTree::redirect($login_root . "forgot-success/");
     return true;
 }