Path

ez components / documentation / api reference / 1.0 / mail


eZ Components 1.0

Mail: ezcMailComposer

[ Tutorial ] [ Class tree ] [ Element index ] [ ChangeLog ] [ Credits ]

Class: ezcMailComposer

Convenience class for writing mail. [source]
This class allows you to create text and/or HTML mail with attachments. If you need to create more advanced mail use the ezcMail class and build the body from scratch.
ezcMailComposer is used with the following steps:
  1. Create a composer object.
  2. Set the subject and recipients.
  3. Set the plainText and htmlText message parts. You can set only one or both. If you set both, the client will display the htmlText if it supports HTML. Otherwise the client will display plainText.
  4. Add any attachments.
  5. Call the build method.
This example shows how to send an HTML mail with a text fallback and attachments. The HTML message has an inline image.
 1.  $mail new ezcMailComposer();
 2.  $mail->from new ezcMailAddress'john@doe.com''John Doe' );
 3.  $mail->addTonew ezcMailAddress'cindy@doe.com''Cindy Doe' ) );
 4.  $mail->subject "Example of an HTML email with attachments";
 5.  $mail->plainText "Here is the text version of the mail. This is displayed if the client can not understand HTML";
 6.  $mail->htmlText "<html>Here is the HTML version of your mail with an image: <img src='file://path_to_image.jpg' /></html>";
 7.  $mail->addAttachment'path_to_attachment.file' );
 8.  $mail->build();
 9.  $transport new ezcMailTransportMta();
10.  $transport->send$mail );
This class has the following properties:
  • string plainText, contains the message of the mail in plain text.
  • string htmlText, contains the message of the mail in HTML. You should also provide the text of the HTML message in the plainText property. Both will be sent and the receiver will see the HTML message if his/her client supports HTML. If the HTML message contains links to local images and/or files these will be included into the mail when generateBody is called. Links to local files must start with "file://" in order to be recognized.

Parents

ezcMailPart
   |
   --ezcMail
      |
      --ezcMailComposer

Inherited Constants

From ezcMail:
ezcMail::BASE64    Base 64 encoding.
ezcMail::BINARY    Binary encoding.
ezcMail::EIGHT_BIT    8 bit encoding.
ezcMail::QUOTED_PRINTABLE    Quoted printable encoding.
ezcMail::SEVEN_BIT    7 bit encoding.

Method Summary

public ezcMailComposer __construct( )
Constructs an empty ezcMailComposer object.
public void addAttachment( $fileName )
Adds the file $fileName to the list of attachments.
public void build( )
Builds the complete email message in RFC822 format.
public mixed __get( $name )
Returns the property $name.
public void __set( $name, $value )
Sets the property $name to $value.

Inherited Methods

From ezcMail :
public ezcMail ezcMail::__construct()
Constructs an empty ezcMail object.
public void ezcMail::addBcc()
Adds the ezcMailAddress $address to the list of 'bcc' recipients.
public void ezcMail::addCc()
Adds the ezcMailAddress $address to the list of 'cc' recipients.
public void ezcMail::addTo()
Adds the ezcMailAddress $address to the list of 'to' recipients.
public string ezcMail::generateBody()
Returns the generated body part of this mail.
public string ezcMail::generateHeaders()
Returns the generated headers for the mail.
public mixed ezcMail::__get()
Returns the property $name.
public void ezcMail::__set()
Sets the property $name to $value.
From ezcMailPart :
public void ezcMailPart::appendExcludeHeaders()
The array $headers will be excluded when the headers are generated.
public string ezcMailPart::generate()
Returns the complete mail part including both the header and the body as a string.
public abstract string ezcMailPart::generateBody()
Returns the body of this part as a string.
public string ezcMailPart::generateHeaders()
Returns the headers set for this part as a RFC 822 string.
public string ezcMailPart::getHeader()
Returns the value of the header $name.
public void ezcMailPart::setHeader()
Sets the header $name to the value $value.

Methods

__construct

ezcMailComposer __construct( )
Constructs an empty ezcMailComposer object.

Redefinition of

Method Description
ezcMail::__construct() Constructs an empty ezcMail object.

addAttachment

void addAttachment( string $fileName )
Adds the file $fileName to the list of attachments.

Parameters

Name Type Description
$fileName string  

Throws

ClassDescription
ezcBaseFileNotFoundException if $fileName does not exists.
ezcBaseFilePermissionProblem if $fileName could not be read.

build

void build( )
Builds the complete email message in RFC822 format.
This method must be called before the message is sent.

Throws

ClassDescription
ezcBaseFileNotFoundException if any of the attachment files can not be found.

__get

mixed __get( string $name )
Returns the property $name.

Parameters

Name Type Description
$name string  

Throws

ClassDescription
ezcBasePropertyNotFoundException if the property does not exist.

Redefinition of

Method Description
ezcMail::__get() Returns the property $name.

__set

void __set( string $name, mixed $value )
Sets the property $name to $value.

Parameters

Name Type Description
$name string  
$value mixed  

Throws

ClassDescription
ezcBasePropertyNotFoundException if the property does not exist.

Redefinition of

Method Description
ezcMail::__set() Sets the property $name to $value.

Last updated: Thu, 31 Jan 2008