This repository has been archived by the owner. 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.


  • 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.


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.

	$email = $this->Postman->create('', 'Email subject');

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

	// Lets add some recipients...
	$email->addRecipient('', 'cc');
	$email->addRecipient('', '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.

	if ($this->Postman->send($email)) {
		echo 'Success!';
	} else {
		echo 'Ruh-roh.';