Wicked::mail PHP Method

mail() public static method

Mails a notification message after encoding the headers and adding the standard username/time line.
public static mail ( string $message, array $headers = [] )
$message string The message text to send out.
$headers array Additional headers to add to the email.
    public static function mail($message, $headers = array())
    {
        global $conf, $registry;
        /* Make sure there's a place configured to send the email. */
        if (empty($conf['wicked']['notify_address'])) {
            return;
        }
        if ($GLOBALS['registry']->getAuth()) {
            $prefix = $GLOBALS['registry']->getAuth();
        } else {
            $prefix = 'guest [' . $_SERVER['REMOTE_ADDR'] . ']';
        }
        $message = $prefix . '  ' . date('r') . "\n\n" . $message;
        /* In case we don't get a user's email address to send the
         * notification from, what should we fall back to for the From:
         * header? */
        $default_from_addr = !empty($conf['wicked']['guest_address']) ? $conf['wicked']['guest_address'] : $conf['wicked']['notify_address'];
        if ($GLOBALS['registry']->getAuth()) {
            $identity = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Identity')->create();
            $from = $identity->getValue('fullname');
            if (empty($from)) {
                $from = $registry->get('name');
            }
            $from_addr = $identity->getValue('from_addr');
            if (empty($from_addr)) {
                $from_addr = $default_from_addr;
            }
        } else {
            $from = $registry->get('name') . ' Guest';
            $from_addr = $default_from_addr;
        }
        $mail = new Horde_Mime_Mail(array('body' => $message, 'To' => $conf['wicked']['notify_address'], 'From' => $from . '<' . $from_addr . '>', 'User-Agent' => 'Wicked ' . $GLOBALS['registry']->getVersion(), 'Precedence' => 'bulk', 'Auto-Submitted' => 'auto-replied'));
        foreach (array_keys($headers) as $hkey) {
            $mail->addHeader($hkey, $headers[$hkey]);
        }
        try {
            $mail->send($GLOBALS['injector']->getInstance('Horde_Mail'));
        } catch (Horde_Mime_Exception $e) {
            $GLOBALS['notification']->push($e);
        }
    }

Usage Example

Esempio n. 1
0
 public function handleAction()
 {
     $pagename = $this->referrer();
     $page = Wicked_Page::getPage($pagename);
     if ($page->allows(Wicked::MODE_REMOVE)) {
         $version = Horde_Util::getFormData('version');
         if (empty($version)) {
             $GLOBALS['wicked']->removeAllVersions($pagename);
             $GLOBALS['notification']->push(sprintf(_("Successfully deleted \"%s\"."), $pagename), 'horde.success');
             Wicked::mail("Deleted page: {$pagename}\n", array('Subject' => '[' . $GLOBALS['registry']->get('name') . '] deleted: ' . $pagename));
             Wicked::url('Wiki/Home', true)->redirect();
         }
         $GLOBALS['wicked']->removeVersion($pagename, $version);
         $GLOBALS['notification']->push(sprintf(_("Deleted version %s of \"%s\"."), $version, $pagename), 'horde.success');
         Wicked::mail("Deleted version: {$version} of {$pagename}\n", array('Subject' => '[' . $GLOBALS['registry']->get('name') . '] deleted: ' . $pagename . ' [' . $version . ']'));
         Wicked::url($pagename, true)->redirect();
     }
     $GLOBALS['notification']->push(sprintf(_("You don't have permission to delete \"%s\"."), $pagename), 'horde.warning');
     Wicked::url($this->referrer(), true)->redirect();
 }
All Usage Examples Of Wicked::mail