ZMail

From HTML5 Builder
Jump to: navigation, search

The ZMail component provides a mail delivery system with interchangeable transport methods.

Usage

To send a mail with a ZMail component just set it up with the proper information, and run its send() method.

Properties

In addition to its own properties (documented below), this component also inherits the following properties:

Attachments

List of paths to the files to be added to the email as attachment. Those files must be available on the server.

On HTML5 Builder, enter a path on each line. From PHP, use an array instead:

$this->ComponentName->Attachments = array("/srv/files/file1.png", "/srv/files/file2.html");

Note: You can provide additional data for each attachment from the OnCustomizeAttachment event.

Bcc

List of blind carbon copy recipients. See To for usage details.

BodyHTML

HTML version of the body of the email. This content will be displayed on those email readers that support and allow HTML content on the email message. On the rest, the BodyText will be displayed instead.

BodyText

Plain text version of the body of the email. If BodyHTML is not set, this will be the message of the email. If there is a BodyHTML defined, its content will be displayed on those email readers that support and allow HTML content on the email message, and BodyText will only be displayed on the rest.

Cc

List of carbon copy recipients. See To for usage details.

FromEmail

Email address of the sender. For example: jane.doe@example.com.

FromName

Name of the sender. For example: Jane Doe.

Headers

You can customize your email message further by defining advanced headers not available here as properties. There is a list of available headers here.

Headers must match the following syntax: Header Name: Header Value. From HTML5 Builder, you can define a header on each line. From PHP, use an array instead:

$this->ComponentName->Headers = array("Date: Thu, 29 Mar 2012 13:14:00 +0100", "X-Accept-Language: en-us, en");

Subject

Text defining the subject of the email message. For example: Notes about our last meeting.

To

List of direct recipients of the email message (see also Cc and Bcc).

For each recipient, you must provide an email address and name. From PHP, you can do it like this:

$this->ComponentName->To = array("john.doe@example.com" => "John Doe", "other.recipient@example.com" => "Other Recipient");

Transport

A component defining a method to send the email. The list of available components is available here.

Methods

send

Sends the email using the provided ZMail settings:

$this->ComponentName->send();

PHP Events

OnCustomizeAttachment

Assign an event handler to this event to customize the attachments and the way they are handled.

The event will be called once for each attachment, and will get the path of the attachment as a single-value one-item array on the $params parameter. Use the path to identify the attachment on each call.

You can either return an empty array, or use it to set some options for the attachment the call was made for. These are the options you can set, all of them optional:

body
Attachment binary content. It would replace the content of the file pointed by the path of the attachment.
mimetype
File MIME type. Zend Framework MIME constants are allowed.
disposition
The way the content will be attached to the email, either inside the message itself (inline) or as a normal separated attachment (attachment).
encoding
Attachment encoding. Zend Framework MIME constants are allowed.
filename
Display name for the attached file.

For example, the following event handler would define the attached index.php file as a text file, to be inlined on the email body:

function attachIndexInline($sender, $params)
{
  $result = array();
  foreach($params as $path) {
    if($path === "index.php")
    {
      $result["mimetype"]  = Zend_Mime::TYPE_TEXT;
      $result["disposition"] = Zend_Mime::DISPOSITION_INLINE;
    }
  }
  return($result);
}