Class: Mailer

Mailer is a wrapper around Zend_Mail configured from Elefant's global mail settings.

Usage:

<?php

// Using Mailer::send() as a wrapper:
$mail = Mailer::send (array (
    'to'          => array ('user@example.com', 'Joe User'),
    'from'        => array ('me@widgets.com', 'Alternate Sender'),
    'cc'          => array ('me@widgets.com', 'CC This Guy'),
    'bcc'         => array ('me@widgets.com', 'BCC This Guy'),
    'reply_to'    => array ('me@widgets.com', 'Reply to This Guy'),
    'subject'     => 'Subject line',
    'text'        => 'This is a plain text message.',
    'html'        => 'This is an <b>html</b> message.',
    'attachments' => array (
        'File data...',
        // or
        new Zend_Mime_Part ('File data...')
    )
);

// Using the Zend_Mail object directly:
$mail = Mailer::getInstance ();
$mail->setBodyText ('This is an email message.');
$mail->setSubject ('Subject line');
$mail->addTo ('user@example.com', 'Joe User');
// Etc.
$mail->send ();

?>

Properties

private static $config

The parsed configurations from the [Mailer] section of the global configuration.

private static $mailer

Zend_Mail object.

private static $transport

Zend_Mail_Transport object.

public static $error = false

If getInstance() fails, this will contain the error message.

Methods

public static getInstance ($clear = true)

Configures and fetches a singleton instance of Zend_Mail. Also clears settings from previous use onthe Zend_Mail object unless you call getInstance(false).

public static send ($msg, $send = true)

Send a single message to a recipient. Handy for one-off messages. Returns the Zend_Mail object after calling send(), unless false is passed as the second parameter, in which case send() is not called and the Zend_Mail object is returned immediately.

public perform ()

Handles jobs from a Resque queue if use_resque = On is set in the [Mailer] configuration. Mailer will automatically queue messages when this setting is set, and this method performs the job at a later time.