API Documentation

Zend/Mail.php

Show: inherited
Table of Contents

Zend Framework

LICENSE

This source file is subject to the new BSD license that is bundled with this package in the file LICENSE.txt. It is also available through the world-wide-web at this URL: http://framework.zend.com/license/new-bsd If you did not receive a copy of the license and are unable to obtain it through the world-wide-web, please send an email to license@zend.com so we can send you a copy immediately.

Category
Zend  
Copyright
Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)  
License
New BSD License  
Package
Zend_Mail  
Version
$Id: Mail.php 24594 2012-01-05 21:27:01Z matthew $  

\Zend_Mail

Package: Zend\Mail

Class for sending an email.

Parent(s)
\Zend_Mime_Message
Category
Zend  
Copyright
Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)  
License
New BSD License  

Properties

Propertyprotectedfalse|\Zend_Mime_Part  $_bodyHtml= 'false'

text/html MIME part

Default valuefalseDetails
Type
false\Zend_Mime_Part
Propertyprotectedfalse|\Zend_Mime_Part  $_bodyText= 'false'

text/plain MIME part

Default valuefalseDetails
Type
false\Zend_Mime_Part
Propertyprotectedstring  $_charset= ''iso-8859-1''

Mail character set

Default value'iso-8859-1'Details
Type
string
Propertyprotectedstring  $_date= 'null'

Date: header

Default valuenullDetails
Type
string
Propertyprotectedarray  $_defaultFrom= ''
static

Details
Type
array
Static
 
Propertyprotectedarray  $_defaultReplyTo= ''
static

Details
Type
array
Static
 
Propertyprotected\Zend_Mail_Transport_Abstract  $_defaultTransport= 'null'
static

Default valuenullDetails
Type
\Zend_Mail_Transport_Abstract
Static
 
Propertyprotectedstring  $_from= 'null'

From: address

Default valuenullDetails
Type
string
Propertyprotectedstring  $_headerEncoding= 'Zend_Mime::ENCODING_QUOTEDPRINTABLE'

Encoding of Mail headers

Default valueZend_Mime::ENCODING_QUOTEDPRINTABLEDetails
Type
string
Propertyprotectedarray  $_headers= 'array()'

Mail headers

Default valuearray()Details
Type
array
Propertyprotectedstring  $_messageId= 'null'

Message-ID: header

Default valuenullDetails
Type
string
Propertyprotectedstring  $_mimeBoundary= 'null'

MIME boundary string

Default valuenullDetails
Type
string
Propertyprotectedarray  $_recipients= 'array()'

Array of all recipients

Default valuearray()Details
Type
array
Propertyprotectedstring  $_replyTo= 'null'

Reply-To header

Default valuenullDetails
Type
string
Propertyprotectedstring  $_returnPath= 'null'

Return-Path header

Default valuenullDetails
Type
string
Propertyprotectedstring  $_subject= 'null'

Subject: header

Default valuenullDetails
Type
string
Propertyprotectedarray  $_to= 'array()'

To: addresses

Default valuearray()Details
Type
array
Propertyprotectedstring  $_type= 'null'

Content type of the message

Default valuenullDetails
Type
string
Propertypublicboolean  $hasAttachments= 'false'

Flag: whether or not email has attachments

Default valuefalseDetails
Type
boolean

Methods

methodpublic__construct( string $charset = null ) : void

Public constructor

Parameters
Name Type Description
$charset string
methodprotected_addRecipientAndHeader( string $headerName, string $email, string $name ) : void

Helper function for adding a recipient and the corresponding header

Parameters
Name Type Description
$headerName string
$email string
$name string
methodprotected_clearHeader( string $headerName ) : void

Clear header from the message

Parameters
Name Type Description
$headerName string
Details
Deprecated
use public method directly  
methodprotected_encodeHeader( string $value ) : string

Encode header fields

Encodes header content according to RFC1522 if it contains non-printable characters.

Parameters
Name Type Description
$value string
Returns
Type Description
string
methodprotected_filterEmail( string $email ) : string

Filter of email data

Parameters
Name Type Description
$email string
Returns
Type Description
string
methodprotected_filterName( string $name ) : string

Filter of name data

Parameters
Name Type Description
$name string
Returns
Type Description
string
methodprotected_filterOther( string $data ) : string

Filter of other data

Parameters
Name Type Description
$data string
Returns
Type Description
string
methodprotected_formatAddress( string $email, string $name ) : string

Formats e-mail address

Parameters
Name Type Description
$email string
$name string
Returns
Type Description
string
methodprotected_storeHeader( string $headerName, string $value, bool $append = false ) : void

Add a header to the message

Adds a header to this message. If append is true and the header already exists, raises a flag indicating that the header should be appended.

Parameters
Name Type Description
$headerName string
$value string
$append bool
methodpublicaddAttachment( \Zend_Mime_Part $attachment ) : \Zend_Mail

Adds an existing attachment to the mail message

Parameters
Name Type Description
$attachment \Zend_Mime_Part
Returns
Type Description
\Zend_Mail Provides fluent interface
methodpublicaddBcc( string|array $email ) : \Zend_Mail

Adds Bcc recipient, $email can be an array, or a single string address

Parameters
Name Type Description
$email string|array
Returns
Type Description
\Zend_Mail Provides fluent interface
methodpublicaddCc( string|array $email, string $name = '' ) : \Zend_Mail

Adds Cc-header and recipient, $email can be an array, or a single string address

Parameters
Name Type Description
$email string|array
$name string
Returns
Type Description
\Zend_Mail Provides fluent interface
methodpublicaddHeader( string $name, string $value, boolean $append = false ) : \Zend_Mail

Add a custom header to the message

Parameters
Name Type Description
$name string
$value string
$append boolean
Returns
Type Description
\Zend_Mail Provides fluent interface
Throws
Exception Description
\Zend_Mail_Exception on attempts to create standard headers
methodpublicaddTo( string|array $email, string $name = '' ) : \Zend_Mail

Adds To-header and recipient, $email can be an array, or a single string address

Parameters
Name Type Description
$email string|array
$name string
Returns
Type Description
\Zend_Mail Provides fluent interface
methodpublicclearDate( ) : \Zend_Mail

Clears the formatted date from the message

Returns
Type Description
\Zend_Mail Provides fluent interface
methodpublicclearDefaultFrom( ) : void
static

Clears the default sender from the mail

methodpublicclearDefaultReplyTo( ) : void
static

Clears the default ReplyTo-address and -name from the mail

methodpublicclearDefaultTransport( ) : void
static

Clear the default transport property

methodpublicclearFrom( ) : \Zend_Mail

Clears the sender from the mail

Returns
Type Description
\Zend_Mail Provides fluent interface
methodpublicclearHeader( string $headerName ) : \Zend_Mail

Clear header from the message

Parameters
Name Type Description
$headerName string
Returns
Type Description
\Zend_Mail Provides fluent inter
methodpublicclearMessageId( ) : \Zend_Mail

Clears the Message-ID from the message

Returns
Type Description
\Zend_Mail Provides fluent interface
methodpublicclearRecipients( ) : \Zend_Mail

Clears list of recipient email addresses

Returns
Type Description
\Zend_Mail Provides fluent interface
methodpublicclearReplyTo( ) : \Zend_Mail

Clears the current Reply-To address from the message

Returns
Type Description
\Zend_Mail Provides fluent interface
methodpublicclearReturnPath( ) : \Zend_Mail

Clears the current Return-Path address from the message

Returns
Type Description
\Zend_Mail Provides fluent interface
methodpublicclearSubject( ) : \Zend_Mail

Clears the encoded subject from the message

Returns
Type Description
\Zend_Mail Provides fluent interface
methodpubliccreateAttachment( string $body, string $mimeType = Zend_Mime::TYPE_OCTETSTREAM, string $disposition = Zend_Mime::DISPOSITION_ATTACHMENT, string $encoding = Zend_Mime::ENCODING_BASE64, string $filename = null ) : \Zend_Mime_Part

Creates a Zend_Mime_Part attachment

Attachment is automatically added to the mail object after creation. The attachment object is returned to allow for further manipulation.

Parameters
Name Type Description
$body string
$mimeType string
$disposition string
$encoding string
$filename string

OPTIONAL A filename for the attachment

Returns
Type Description
\Zend_Mime_Part Newly created Zend_Mime_Part object (to allow advanced settings)
methodpubliccreateMessageId( ) : string

Creates the Message-ID

Returns
Type Description
string
methodpublicgetBodyHtml( bool $htmlOnly = false ) : false|\Zend_Mime_Part|string

Return Zend_Mime_Part representing body HTML

Parameters
Name Type Description
$htmlOnly bool

Whether to return the body HTML only, or the MIME part; defaults to false, the MIME part

Returns
Type Description
false|\Zend_Mime_Part|string
methodpublicgetBodyText( bool $textOnly = false ) : false|\Zend_Mime_Part|string

Return text body Zend_Mime_Part or string

Parameters
Name Type Description
$textOnly bool

textOnly Whether to return just the body text content or the MIME part; defaults to false, the MIME part

Returns
Type Description
false|\Zend_Mime_Part|string
methodpublicgetCharset( ) : string

Return charset string

Returns
Type Description
string
methodpublicgetDate( ) : string

Returns the formatted date of the message

Returns
Type Description
string
methodpublicgetDefaultFrom( ) : null|array
static

Returns the default sender of the mail

Returns
Type Description
null|array Null if none was set.
methodpublicgetDefaultReplyTo( ) : null|array
static

Returns the default Reply-To Address and Name of the mail

Returns
Type Description
null|array Null if none was set.
methodpublicgetDefaultTransport( ) : void
static

Gets the default mail transport for all following uses of unittests

Details
Todo
Allow passing a string to indicate the transport to load  
Todo
Allow passing in optional options for the transport to load  
methodpublicgetEncodingOfHeaders( ) : string

Return encoding of mail headers

Returns
Type Description
string
Details
Deprecated
use {@link getHeaderEncoding()} instead  
methodpublicgetFrom( ) : string

Returns the sender of the mail

Returns
Type Description
string
methodpublicgetHeaderEncoding( ) : string

Return the encoding of mail headers

Either Zend_Mime::ENCODING_QUOTEDPRINTABLE or Zend_Mime::ENCODING_BASE64

Returns
Type Description
string
methodpublicgetHeaders( ) : void

Return mail headers

methodpublicgetMessageId( ) : string

Returns the Message-ID of the message

Returns
Type Description
string
methodpublicgetMimeBoundary( ) : string

Return the boundary string used for the message

Returns
Type Description
string
methodpublicgetPartCount( ) : integer

Return a count of message parts

Returns
Type Description
integer
methodpublicgetRecipients( ) : array

Return list of recipient email addresses

Returns
Type Description
array (of strings)
methodpublicgetReplyTo( ) : string|null

Returns the current Reply-To address of the message

Returns
Type Description
string|null Reply-To address, null when not set
methodpublicgetReturnPath( ) : string

Returns the current Return-Path address of the message

If no Return-Path header is set, returns the value of {@link $_from}.

Returns
Type Description
string
methodpublicgetSubject( ) : string

Returns the encoded subject of the message

Returns
Type Description
string
methodpublicgetType( ) : string

Get content type of the message

Returns
Type Description
string
methodpublicsend( \Zend_Mail_Transport_Abstract $transport = null ) : \Zend_Mail

Sends this email using the given transport or a previously set DefaultTransport or the internal mail function if no default transport had been set.

Parameters
Name Type Description
$transport \Zend_Mail_Transport_Abstract
Returns
Type Description
\Zend_Mail Provides fluent interface
methodpublicsetBodyHtml( string $html, string $charset = null, string $encoding = Zend_Mime::ENCODING_QUOTEDPRINTABLE ) : \Zend_Mail

Sets the HTML body for the message

Parameters
Name Type Description
$html string
$charset string
$encoding string
Returns
Type Description
\Zend_Mail Provides fluent interface
methodpublicsetBodyText( string $txt, string $charset = null, string $encoding = Zend_Mime::ENCODING_QUOTEDPRINTABLE ) : \Zend_Mail

Sets the text body for the message.

Parameters
Name Type Description
$txt string
$charset string
$encoding string
Returns
Type Description
\Zend_Mail Provides fluent interface
methodpublicsetDate( \timestamp|string|\Zend_Date $date = null ) : \Zend_Mail

Sets Date-header

Parameters
Name Type Description
$date \timestamp|string|\Zend_Date
Returns
Type Description
\Zend_Mail Provides fluent interface
Throws
Exception Description
\Zend_Mail_Exception if called subsequent times or wrong date format.
methodpublicsetDefaultFrom( string $email, string $name = null ) : void
static

Sets Default From-email and name of the message

Parameters
Name Type Description
$email string
$name string

Optional $name

methodpublicsetDefaultReplyTo( string $email, string $name = null ) : void
static

Sets Default ReplyTo-address and -name of the message

Parameters
Name Type Description
$email string
$name string

Optional $name

methodpublicsetDefaultTransport( \Zend_Mail_Transport_Abstract $transport ) : void
static

Sets the default mail transport for all following uses of Zend_Mail::send();

Parameters
Name Type Description
$transport \Zend_Mail_Transport_Abstract
Details
Todo
Allow passing a string to indicate the transport to load  
Todo
Allow passing in optional options for the transport to load  
methodpublicsetEncodingOfHeaders( string $encoding ) : \Zend_Mail

Set the encoding of mail headers

Parameters
Name Type Description
$encoding string
Returns
Type Description
\Zend_Mail
Details
Deprecated
Use {@link setHeaderEncoding()} instead.  
methodpublicsetFrom( string $email, string $name = null ) : \Zend_Mail

Sets From-header and sender of the message

Parameters
Name Type Description
$email string
$name string
Returns
Type Description
\Zend_Mail Provides fluent interface
Throws
Exception Description
\Zend_Mail_Exception if called subsequent times
methodpublicsetFromToDefaultFrom( ) : \Zend_Mail

Sets From-name and -email based on the defaults

Returns
Type Description
\Zend_Mail Provides fluent interface
methodpublicsetHeaderEncoding( string $encoding ) : \Zend_Mail

Set the encoding of mail headers

Parameters
Name Type Description
$encoding string

Zend_Mime::ENCODING_QUOTEDPRINTABLE or Zend_Mime::ENCODING_BASE64

Returns
Type Description
\Zend_Mail Provides fluent interface
methodpublicsetMessageId( boolean|string $id = true ) : \Zend_Mail

Sets the Message-ID of the message

Parameters
Name Type Description
$id boolean|string

true :Auto false :No set null :No set string:Sets given string (Angle brackets is not necessary)

Returns
Type Description
\Zend_Mail Provides fluent interface
Throws
Exception Description
\Zend_Mail_Exception
methodpublicsetMimeBoundary( string $boundary ) : \Zend_Mail

Set an arbitrary mime boundary for the message

If not set, Zend_Mime will generate one.

Parameters
Name Type Description
$boundary string
Returns
Type Description
\Zend_Mail Provides fluent interface
methodpublicsetReplyTo( string $email, string $name = null ) : \Zend_Mail

Set Reply-To Header

Parameters
Name Type Description
$email string
$name string
Returns
Type Description
\Zend_Mail
Throws
Exception Description
\Zend_Mail_Exception if called more than one time
methodpublicsetReplyToFromDefault( ) : \Zend_Mail

Sets ReplyTo-name and -email based on the defaults

Returns
Type Description
\Zend_Mail Provides fluent interface
methodpublicsetReturnPath( string $email ) : \Zend_Mail

Sets the Return-Path header of the message

Parameters
Name Type Description
$email string
Returns
Type Description
\Zend_Mail Provides fluent interface
Throws
Exception Description
\Zend_Mail_Exception if set multiple times
methodpublicsetSubject( string $subject ) : \Zend_Mail

Sets the subject of the message

Parameters
Name Type Description
$subject string
Returns
Type Description
\Zend_Mail Provides fluent interface
Throws
Exception Description
\Zend_Mail_Exception
methodpublicsetType( string $type ) : \Zend_Mail

Set content type

Should only be used for manually setting multipart content types.

Parameters
Name Type Description
$type string

Content type

Returns
Type Description
\Zend_Mail Implements fluent interface
Throws
Exception Description
\Zend_Mail_Exception for types not supported by Zend_Mime
Documentation was generated by DocBlox 0.15.1.