Back to Mail class

Method getInstance

public static \Joomla\CMS\Mail\Mail
getInstance
(mixed $id = 'Joomla', mixed $exceptions = true)
Returns the global email object, only creating it if it doesn't already exist.
Parameters
  • string $id The id string for the Mail instance [optional]
  • bool $exceptions Flag if Exceptions should be thrown [optional]
Returns
  • \Joomla\CMS\Mail\Mail The global Mail object
Since
  • 1.7.0
Class: Mail
Project: Joomla

Method getInstance - Source code

/**
 * Returns the global email object, only creating it if it doesn't already exist.
 *
 * NOTE: If you need an instance to use that does not have the global configuration
 * values, use an id string that is not 'Joomla'.
 *
 * @param   string   $id          The id string for the Mail instance [optional]
 * @param   boolean  $exceptions  Flag if Exceptions should be thrown [optional]
 *
 * @return  Mail  The global Mail object
 *
 * @since   1.7.0
 */
public static function getInstance($id = 'Joomla', $exceptions = true)
{
    if (empty(static::$instances[$id])) {
        static::$instances[$id] = new static($exceptions);
    }
    return static::$instances[$id];
}