Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Home

joebeeson edited this page · 9 revisions

Mailer is a CakePHP 1.3 plugin for simplifying the sending of emails.

Concepts

  • The sending of an email is handled by interchangeable transport objects (Classes - \Postman\Library\Transport).
  • Emails are independent, reusable objects.
  • Send emails from anywhere: controller, shell, etc.
  • Easy to extend and build upon.

Usage

To begin we have to create an Email object (Classes - \Postman\Library\Email). This object will hold all the various information, recipients, content and attachments that are pertinent to the email being sent.

<?php
    $email = $this->Postman->create('from-address@example.com', 'Email subject');

Now we can begin attaching various pieces of information to the email object.

<?php
    // Lets add some recipients...
    $email->addRecipient('foo@example.com');
    $email->addRecipient('bar@example.com', 'cc');
    $email->addRecipient('baz@example.com', 'bcc');

    // Now maybe some files
    $email->addAttachment('/tmp/report.xls', 'BigReport.xls');
    $email->addAttachment('/tmp/summary.doc', 'Summary.doc');

    // Finally, our email's body
    $email->setTextBody('Hey there guys, check out this report!');
    $email->setHtmlBody('<strong>HI!</strong>. Reports inside.');

At this point our Email object should be all set and we should hand the object off for sending. We will receive a boolean response to indicate success.

<?php
    if ($this->Postman->send($email)) {
        echo 'Success!';
    } else {
        echo 'Ruh-roh.';
    }
Something went wrong with that request. Please try again.