コード例 #1
0
/**
 * Send an email notification
 *
 * @param string $hook   Hook name
 * @param string $type   Hook type
 * @param bool   $result Was the email already sent
 * @param array  $params Hook parameters
 * @return bool
 */
function notifications_html_handler_send_email_notification($hook, $type, $result, $params)
{
    if ($result === true) {
        // email was already sent by some other handler
        return;
    }
    $notification = elgg_extract('notification', $params);
    $notification = elgg_trigger_plugin_hook('format', 'notification', $params, $notification);
    if (!$notification instanceof \Elgg\Notifications\Notification) {
        return false;
    }
    $sender = $notification->getSender();
    $recipient = $notification->getRecipient();
    if (!$sender instanceof \ElggEntity) {
        return false;
    }
    if (!$recipient instanceof \ElggEntity || !$recipient->email) {
        return false;
    }
    $to = new Zend\Mail\Address($recipient->email, $recipient->getDisplayName());
    if (!$sender instanceof ElggUser && $sender->email) {
        // If there's an email address, use it - but only if it's not from a user.
        $from_email = $sender->email;
        $from_name = $sender->getDisplayName();
    } else {
        $site = elgg_get_site_entity();
        $from_email = elgg_get_plugin_setting('from_email', 'notifications_html_handler', $site->email);
        if (!$from_email) {
            $from_email = "noreply@{$site->getDomain()}";
        }
        $from_name = elgg_get_plugin_setting('from_name', 'notifications_html_handler', $site->name);
    }
    $from = new Zend\Mail\Address($from_email, $from_name);
    $email_params = array_merge((array) $notification->params, $params);
    $email_params['notification'] = $notification;
    return notifications_html_handler_send_email($from->toString(), $to->toString(), $notification->subject, $notification->body, $email_params);
}
コード例 #2
0
 /**
  * Format an email address and name into a formatted email address
  *
  * eg "Some name <*****@*****.**>"
  *
  * @param string $email the email address
  * @param string $name  the name
  *
  * @return string
  */
 public static function getFormattedEmailAddress($email, $name = null)
 {
     $mail = new \Zend\Mail\Address($email, $name);
     return $mail->toString();
 }