Example #1
0
    public function sendMailAction()
    {
        $this->_helper->layout()->disableLayout();
        $this->_helper->viewRenderer->setNoRender();
        $data = $this->_request->getParams();
        try {
            Zend_Loader::loadClass("Ht_Utils");
            $mailer = Ht_Utils::getMailer();
            $admin = $this->__getAdministratorInfo();
            if ($mailer && $admin) {
                //$mail->setCharset('UTF-8');
                $mailer->addTo($admin->u_email, $admin->u_name . " " . $admin->u_lastname);
                $mailer->setFrom($data["email"], $data["name"]);
                $appName = $this->getSysSetting(self::CONF_KEY_APPLICATION_NAME);
                $subject = "{$appName}: Application Error!";
                $exception = nl2br($data["exception"]);
                $adminName = $admin->u_name . " " . $admin->u_lastname;
                $msg = $data["message"];
                $senderName = $data["name"];
                $message = <<<MESSAGE
<html>
<head><title>{$subject}</title></head>
<body>
<h3>Dear Khun {$adminName}</h3>
<br />
{$msg}
<br />
<hr />
{$exception}
<br />
<br />
Best Regards,
{$senderName}
</body>
</html>
MESSAGE;
                $mailer->sentMail($subject, $message);
            }
            $this->getDispatcher()->notify(new sfEvent($this, 'system.log', array('message' => array(sprintf('`%s` sent error report success', trim($data["name"]))), 'priority' => 6)));
        } catch (Exception $e) {
            $this->getDispatcher()->notify(new sfEvent($this, 'error.log', array('message' => array(sprintf('`%s` sent error report fail.', $data["name"]), sprintf("Error Message: %s", $e->getMessage()), sprintf("Stack trace: %s", $e->getTraceAsString())), 'priority' => 3)));
            echo "error";
            return;
        }
        echo "success";
    }