示例#1
0
    function send()
    {
        $emails = array();
        $groups = array();
        if (!isset($_POST['users']) and !isset($_POST['email'])) {
            return;
        }
        $sqlGroups = '';
        if (!empty($_POST['users'])) {
            foreach ($_POST['users'] as $item) {
                if ($item == 'iusers') {
                    $sql = 'SELECT email FROM {{iusers}} WHERE visible=1';
                    $emails = array_merge($emails, DB::getAll($sql, 'email'));
                } elseif ($item == 'subscribers') {
                    $sql = 'SELECT email FROM {{subscribers}}';
                    $emails = array_merge($emails, DB::getAll($sql, 'email'));
                } elseif ($item == 'orders') {
                    $sql = 'SELECT email FROM {{orders}}';
                    $emails = array_merge($emails, DB::getAll($sql, 'email'));
                } else {
                    $groups[] = $item;
                }
            }
            $sqlGroups = 'emailgroups=\'' . implode(',', $_POST['users']) . '\',';
        }
        if (!empty($groups)) {
            $users = Iuser::getGroupUsers($groups, 'email');
            $emails = array_merge($emails, $users);
        }
        $emails[] = $_POST['email'];
        $emails = array_unique($emails);
        $text = View::getRenderFullEmpty('email/notifications', array('text' => $_POST['body'], 'title' => $_POST['subject']));
        foreach ($emails as $email) {
            $mail = new Email();
            $mail->Text($text);
            $mail->Subject($_POST['subject']);
            $mail->From($_POST['emailfrom']);
            $mail->mailTo($email);
            $mail->Send();
        }
        $sql = '
			INSERT INTO {{notification}}
			SET 
				subject=\'' . $_POST['subject'] . '\',
				body=\'' . $_POST['body'] . '\',
				email=\'' . implode(',', $emails) . '\',
				' . $sqlGroups . '
				emailfrom=\'' . $_POST['emailfrom'] . '\',
				cdate=NOW(),
				author=' . $_SESSION['user']['id'] . '
		';
        DB::exec($sql);
    }
示例#2
0
 public static function sendAllOrder($id)
 {
     $data = Orders::getOrderById($id);
     View::$layout = 'empty';
     $text = View::getRenderFullEmpty('email/order', $data);
     $mail = new Email();
     $mail->mailTo($data['email']);
     $mail->Subject('Статус заказа №' . (str_repeat('0', 6 - strlen($id)) . $id) . ' на сайте ' . $_SERVER['HTTP_HOST'] . ' изменен');
     $mail->From('robot@' . str_replace('www.', '', $_SERVER["HTTP_HOST"]));
     $mail->Text($text);
     $mail->Send();
 }