Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.
joebeeson edited this page Apr 4, 2011 · 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('[email protected]', 'Email subject');

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

<?php
	// Lets add some recipients...
	$email->addRecipient('[email protected]');
	$email->addRecipient('[email protected]', 'cc');
	$email->addRecipient('[email protected]', '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.';
	}