$mail = new ezcMail;
$mail->from = new ezcMailAddress( '[email protected]', 'Adrian Ripburger' );
$mail->addTo( new ezcMailAddress( '[email protected]', 'Maureen Corley' ) );
$mail->subject = "Hi";
$mail->body = new ezcMailText( "I just mail to say I love you!" );
$transport = new ezcMailMtaTransport();
$transport->send( $mail );
By default, the ezcMail class will generate a mail with the Bcc header inside,
and leave it to the SMTP server to strip the Bcc header. This can pose a
problem with some SMTP servers which do not strip the Bcc header
(issue #16154: Bcc headers are not stripped when using SMTP). Use the option
stripBccHeader from {@link ezcMailOptions} to delete the Bcc header from
the mail before it is sent.
Example:
$options = new ezcMailOptions();
$options->stripBccHeader = true; // default value is false
$mail = new ezcMail( $options );
You can also derive your own mail classes from this class if you have
special requirements. An example of this is the ezcMailComposer class which
is a convenience class to send simple mail structures and HTML mail.
There are several headers you can set on the mail object to achieve various
effects:
- Reply-To - Set this to an email address if you want people to reply to an
address other than the from address.
- Errors-To - If the mail can not be delivered the error message will be
sent to this address.
Mostra file
Open project: zetacomponents/mail
Class Usage Examples
Protected Properties
Property
Type
Description
$options
ezcMailOptions
Holds the options for this class.
Public Methods
Method
Description
__construct ( ezcMailOptions $options = null )
Constructs an empty ezcMail object.
__get ( string $name ) : mixed
Returns the property $name.
__isset ( string $name ) : boolean
Returns true if the property $name is set, otherwise false.
__set ( string $name, mixed $value )
Sets the property $name to $value.
addBcc ( ezcMailAddress $address )
Adds the ezcMailAddress $address to the list of 'bcc' recipients.
addCc ( ezcMailAddress $address )
Adds the ezcMailAddress $address to the list of 'cc' recipients.
addTo ( ezcMailAddress $address )
Adds the ezcMailAddress $address to the list of 'to' recipients.
fetchParts ( array(string) $filter = null, boolean $includeDigests = false ) : array(ezcMailPart)
Returns an array of mail parts from the current mail.
generateBody ( ) : string
Returns the generated body part of this mail.
generateHeaders ( ) : string
Returns the generated headers for the mail.
walkParts ( ezcMailPartWalkContext $context, ezcMailPart $mail )
Walks recursively through the mail parts in the specified mail object.
Protected Methods
Method
Description
collectPart ( ezcMailPartWalkContext $context, ezcMailPart $mail )
Saves $mail in the $context object.
Method Details
Constructs an empty ezcMail object.
public __construct ( ezcMailOptions $options = null )
$options
ezcMailOptions
Returns the property $name.
Returns true if the property $name is set, otherwise false.
Sets the property $name to $value.
Adds the ezcMailAddress $address to the list of 'bcc' recipients.
public addBcc ( ezcMailAddress $address )
$address
ezcMailAddress
Adds the ezcMailAddress $address to the list of 'cc' recipients.
public addCc ( ezcMailAddress $address )
$address
ezcMailAddress
Adds the ezcMailAddress $address to the list of 'to' recipients.
public addTo ( ezcMailAddress $address )
$address
ezcMailAddress
This function is used as a callback in the fetchParts() method.
protected static collectPart ( ezcMailPartWalkContext $context, ezcMailPart $mail )
$context
ezcMailPartWalkContext
$mail
ezcMailPart
The array returned contains objects of classes:
- ezcMailText
- ezcMailFile
- ezcMailRfc822Digest
If the method is called with $includeDigests as true, then the returned
array will not contain ezcMailRfc822Digest objects, but instead the mail
parts inside the digests.
The parameter $filter can be used to restrict the returned mail parts,
eg. $filter = array( 'ezcMailFile' ) to return only file mail parts.
A typical use for this function is to get a list of attachments from a mail.
Example:
$mail is an ezcMail object
$parts = $mail->fetchParts();
after the above line is executed, $parts will contain an array of mail parts objects,
for example one ezcMailText object ($parts[0]) and two ezcMailRfc822Digest objects ($parts[1] and $parts[2]).
the ezcMailText object will be used to render the mail text, and the
other two objects will be displayed as links ("view attachment")
when user clicks on one of the two attachments, the parts of that attachment
must be retrieved in order to render the attached digest:
$subparts = $parts[1]->mail->fetchParts();
after the above line is executed, $subparts will contain an array of mail parts objects,
for example one ezcMailText object and one ezcMailFile object
public fetchParts ( array(string) $filter = null, boolean $includeDigests = false ) : array(ezcMailPart)
$filter
array(string)
$includeDigests
boolean
return
array(ezcMailPart)
Returns an empty string if no body has been set.
public generateBody ( ) : string
return
string
This method is called automatically when the mail message is built.
You can re-implement this method in subclasses if you wish to set
different mail headers than ezcMail.
public generateHeaders ( ) : string
return
string
$context is an object of class ezcMailPartWalkContext, which must contain
a valid callback function name to be applied to all mail parts. You can use
the collectPart() method, or create your own callback function which can
for example save the mail parts to disk or to a database.
For the properties you can set to the walk context see: {@link ezcMailPartWalkContext}
Example:
class App
{
public static function saveMailPart( $context, $mailPart )
{
code to save the $mailPart object to disk
}
}
use the saveMailPart() function as a callback in walkParts()
where $mail is an ezcMail object.
$context = new ezcMailPartWalkContext( array( 'App', 'saveMailPart' ) );
$context->includeDigests = true; // if you want to go through the digests in the mail
$mail->walkParts( $context, $mail );
public walkParts ( ezcMailPartWalkContext $context, ezcMailPart $mail )
$context
ezcMailPartWalkContext
$mail
ezcMailPart
Property Details