Class for sending an email.

category Zend
package Zend_Mail
copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
license New BSD License
inherited_from \Zend_Mime_Message

 Methods

Public constructor

__construct(string $charset = null) : void

Parameters

$charset

string

Adds an existing attachment to the mail message

addAttachment(\Zend_Mime_Part $attachment) : \Zend_Mail

Parameters

$attachment

\Zend_Mime_Part

Returns

\Zend_MailProvides fluent interface

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

addBcc(string|array $email) : \Zend_Mail

Parameters

$email

stringarray

Returns

\Zend_MailProvides fluent interface

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

addCc(string|array $email, string $name = '') : \Zend_Mail

Parameters

$email

stringarray

$name

string

Returns

\Zend_MailProvides fluent interface

Add a custom header to the message

addHeader(string $name, string $value, boolean $append = false) : \Zend_Mail

Parameters

$name

string

$value

string

$append

boolean

Exceptions

\Zend_Mail_Exception on attempts to create standard headers

Returns

\Zend_MailProvides fluent interface

Append a new Zend_Mime_Part to the current message

addPart(\Zend_Mime_Part $part) 
Inherited

Parameters

$part

\Zend_Mime_Part

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

addTo(string|array $email, string $name = '') : \Zend_Mail

Parameters

$email

stringarray

$name

string

Returns

\Zend_MailProvides fluent interface

Clears the formatted date from the message

clearDate() : \Zend_Mail

Returns

\Zend_MailProvides fluent interface

Clears the default sender from the mail

clearDefaultFrom() : void
Static

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

clearDefaultReplyTo() : void
Static

Clear the default transport property

clearDefaultTransport() 
Static

Clears the sender from the mail

clearFrom() : \Zend_Mail

Returns

\Zend_MailProvides fluent interface

Clear header from the message

clearHeader(string $headerName) : \Zend_Mail

Parameters

$headerName

string

Returns

\Zend_MailProvides fluent inter

Clears the Message-ID from the message

clearMessageId() : \Zend_Mail

Returns

\Zend_MailProvides fluent interface

Clears list of recipient email addresses

clearRecipients() : \Zend_Mail

Returns

\Zend_MailProvides fluent interface

Clears the current Reply-To address from the message

clearReplyTo() : \Zend_Mail

Returns

\Zend_MailProvides fluent interface

Clears the current Return-Path address from the message

clearReturnPath() : \Zend_Mail

Returns

\Zend_MailProvides fluent interface

Clears the encoded subject from the message

clearSubject() : \Zend_Mail

Returns

\Zend_MailProvides fluent interface

Creates a Zend_Mime_Part attachment

createAttachment(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

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

Parameters

$body

string

$mimeType

string

$disposition

string

$encoding

string

$filename

string

OPTIONAL A filename for the attachment

Returns

\Zend_Mime_PartNewly created Zend_Mime_Part object (to allow advanced settings)

Decodes a MIME encoded string and returns a Zend_Mime_Message object with all the MIME parts set according to the given string

createFromMessage(string $message, string $boundary, string $EOL = \Zend_Mime::LINEEND) : \Zend_Mime_Message
InheritedStatic

Parameters

$message

string

$boundary

string

$EOL

string

EOL string; defaults to {@link Zend_Mime::LINEEND}

Exceptions

\Zend_Exception

Returns

\Zend_Mime_Message

Creates the Message-ID

createMessageId() : string

Returns

string

Generate MIME-compliant message from the current configuration

generateMessage(string $EOL = \Zend_Mime::LINEEND) : string
Inherited

This can be a multipart message if more than one MIME part was added. If only one part is present, the content of this part is returned. If no part had been added, an empty string is returned.

Parts are seperated by the mime boundary as defined in Zend_Mime. If \setMime() has been called before this method, the Zend_Mime object set by this call will be used. Otherwise, a new Zend_Mime object is generated and used.

Parameters

$EOL

string

EOL string; defaults to {@link Zend_Mime::LINEEND}

Returns

string

Return Zend_Mime_Part representing body HTML

getBodyHtml(boolean $htmlOnly = false) : false | \Zend_Mime_Part | string

Parameters

$htmlOnly

boolean

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

Returns

false\Zend_Mime_Partstring

Return text body Zend_Mime_Part or string

getBodyText($textOnly = false) : false | \Zend_Mime_Part | string

Parameters

$textOnly

Returns

false\Zend_Mime_Partstring

Return charset string

getCharset() : string

Returns

string

Returns the formatted date of the message

getDate() : string

Returns

string

Returns the default sender of the mail

getDefaultFrom() : null | array
Static

Returns

nullarrayNull if none was set.

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

getDefaultReplyTo() : null | array
Static

Returns

nullarrayNull if none was set.

Gets the default mail transport for all following uses of unittests

getDefaultTransport() 
Static
todo Allow passing a string to indicate the transport to load
todo Allow passing in optional options for the transport to load

Return encoding of mail headers

getEncodingOfHeaders() : string
deprecated use {@link getHeaderEncoding()} instead

Returns

string

Returns the sender of the mail

getFrom() : string

Returns

string

Return the encoding of mail headers

getHeaderEncoding() : string

Either Zend_Mime::ENCODING_QUOTEDPRINTABLE or Zend_Mime::ENCODING_BASE64

Returns

string

Return mail headers

getHeaders() : void

Returns the Message-ID of the message

getMessageId() : string

Returns

string

Returns the Zend_Mime object in use by the message

getMime() : \Zend_Mime
Inherited

If the object was not present, it is created and returned. Can be used to determine the boundary used in this message.

Returns

\Zend_Mime

Return the boundary string used for the message

getMimeBoundary() : string

Returns

string

Get the (encoded) content of a given part as a string

getPartContent(integer $partnum, string $EOL = \Zend_Mime::LINEEND) : string
Inherited

Parameters

$partnum

integer

$EOL

string

Returns

string

Return a count of message parts

getPartCount() : integer

Returns

integer

Get the headers of a given part as a string

getPartHeaders(integer $partnum, string $EOL = \Zend_Mime::LINEEND) : string
Inherited

Parameters

$partnum

integer

$EOL

string

Returns

string

Get the headers of a given part as an array

getPartHeadersArray(integer $partnum) : array
Inherited

Parameters

$partnum

integer

Returns

array

Returns the list of all Zend_Mime_Parts in the message

getParts() : array
Inherited

Returns

arrayof Zend_Mime_Part

Return list of recipient email addresses

getRecipients() : array

Returns

array(of strings)

Returns the current Reply-To address of the message

getReplyTo() : string | null

Returns

stringnullReply-To address, null when not set

Returns the current Return-Path address of the message

getReturnPath() : string

If no Return-Path header is set, returns the value of \$_from.

Returns

string

Returns the encoded subject of the message

getSubject() : string

Returns

string

Get content type of the message

getType() : string

Returns

string

Check if message needs to be sent as multipart MIME message or if it has only one part.

isMultiPart() : boolean
Inherited

Returns

boolean

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

send(\Zend_Mail_Transport_Abstract $transport = null) : \Zend_Mail

Parameters

$transport

\Zend_Mail_Transport_Abstract

Returns

\Zend_MailProvides fluent interface

Sets the HTML body for the message

setBodyHtml(string $html, string $charset = null, string $encoding = \Zend_Mime::ENCODING_QUOTEDPRINTABLE) : \Zend_Mail

Parameters

$html

string

$charset

string

$encoding

string

Returns

\Zend_MailProvides fluent interface

Sets the text body for the message.

setBodyText(string $txt, string $charset = null, string $encoding = \Zend_Mime::ENCODING_QUOTEDPRINTABLE) : \Zend_Mail

Parameters

$txt

string

$charset

string

$encoding

string

Returns

\Zend_MailProvides fluent interface

Sets Date-header

setDate(\timestamp|string|\Zend_Date $date = null) : \Zend_Mail

Parameters

$date

\timestampstring\Zend_Date

Exceptions

\Zend_Mail_Exception if called subsequent times or wrong date format.

Returns

\Zend_MailProvides fluent interface

Sets Default From-email and name of the message

setDefaultFrom(string $email, $name = null) : void
Static

Parameters

$email

string

$name

Sets Default ReplyTo-address and -name of the message

setDefaultReplyTo(string $email, $name = null) : void
Static

Parameters

$email

string

$name

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

setDefaultTransport(\Zend_Mail_Transport_Abstract $transport) 
Static
todo Allow passing a string to indicate the transport to load
todo Allow passing in optional options for the transport to load

Parameters

$transport

\Zend_Mail_Transport_Abstract

Set the encoding of mail headers

setEncodingOfHeaders(string $encoding) : \Zend_Mail
deprecated Use {@link setHeaderEncoding()} instead.

Parameters

$encoding

string

Returns

\Zend_Mail

Sets From-header and sender of the message

setFrom(string $email, string $name = null) : \Zend_Mail

Parameters

$email

string

$name

string

Exceptions

\Zend_Mail_Exception if called subsequent times

Returns

\Zend_MailProvides fluent interface

Sets From-name and -email based on the defaults

setFromToDefaultFrom() : \Zend_Mail

Returns

\Zend_MailProvides fluent interface

Set the encoding of mail headers

setHeaderEncoding(string $encoding) : \Zend_Mail

Parameters

$encoding

string

Zend_Mime::ENCODING_QUOTEDPRINTABLE or Zend_Mime::ENCODING_BASE64

Returns

\Zend_MailProvides fluent interface

Sets the Message-ID of the message

setMessageId(boolean|string $id = true) : \Zend_Mail

Parameters

$id

booleanstring

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

Exceptions

\Zend_Mail_Exception

Returns

\Zend_MailProvides fluent interface

Set Zend_Mime object for the message

setMime(\Zend_Mime $mime) 
Inherited

This can be used to set the boundary specifically or to use a subclass of Zend_Mime for generating the boundary.

Parameters

$mime

\Zend_Mime

Set an arbitrary mime boundary for the message

setMimeBoundary(string $boundary) : \Zend_Mail

If not set, Zend_Mime will generate one.

Parameters

$boundary

string

Returns

\Zend_MailProvides fluent interface

Sets the given array of Zend_Mime_Parts as the array for the message

setParts(array $parts) 
Inherited

Parameters

$parts

array

Set Reply-To Header

setReplyTo(string $email, string $name = null) : \Zend_Mail

Parameters

$email

string

$name

string

Exceptions

\Zend_Mail_Exception if called more than one time

Returns

\Zend_Mail

Sets ReplyTo-name and -email based on the defaults

setReplyToFromDefault() : \Zend_Mail

Returns

\Zend_MailProvides fluent interface

Sets the Return-Path header of the message

setReturnPath(string $email) : \Zend_Mail

Parameters

$email

string

Exceptions

\Zend_Mail_Exception if set multiple times

Returns

\Zend_MailProvides fluent interface

Sets the subject of the message

setSubject(string $subject) : \Zend_Mail

Parameters

$subject

string

Exceptions

\Zend_Mail_Exception

Returns

\Zend_MailProvides fluent interface

Set content type

setType(string $type) : \Zend_Mail

Should only be used for manually setting multipart content types.

Parameters

$type

string

Content type

Exceptions

\Zend_Mail_Exception for types not supported by Zend_Mime

Returns

\Zend_MailImplements fluent interface

Helper function for adding a recipient and the corresponding header

_addRecipientAndHeader(string $headerName, string $email, string $name) 

Parameters

$headerName

string

$email

string

$name

string

Clear header from the message

_clearHeader(string $headerName) 
deprecated use public method directly

Parameters

$headerName

string

Explode MIME multipart string into seperate parts

_disassembleMime(string $body, string $boundary) : array
InheritedStatic

Parts consist of the header and the body of each MIME part.

Parameters

$body

string

$boundary

string

Exceptions

\Zend_Exception

Returns

array

Encode header fields

_encodeHeader(string $value) : string

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

Parameters

$value

string

Returns

string

Filter of email data

_filterEmail(string $email) : string

Parameters

$email

string

Returns

string

Filter of name data

_filterName(string $name) : string

Parameters

$name

string

Returns

string

Filter of other data

_filterOther(string $data) : string

Parameters

$data

string

Returns

string

Formats e-mail address

_formatAddress(string $email, string $name) : string

Parameters

$email

string

$name

string

Returns

string

Add a header to the message

_storeHeader(string $headerName, string $value, boolean $append = false

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

$headerName

string

$value

string

$append

boolean

 Properties

 

Flag: whether or not email has attachments

$hasAttachments : boolean

Default

false
 

text/html MIME part

$_bodyHtml : false | \Zend_Mime_Part

Default

false
 

text/plain MIME part

$_bodyText : false | \Zend_Mime_Part

Default

false
 

Mail character set

$_charset : string

Default

'iso-8859-1'
 

Date: header

$_date : string

Default

null
 

$_defaultFrom

$_defaultFrom : array

Default

Static
static
 

$_defaultReplyTo

$_defaultReplyTo : array

Default

Static
static
 

$_defaultTransport

$_defaultTransport : \Zend_Mail_Transport_Abstract

Default

null
Static
static
 

From: address

$_from : string

Default

null
 

Encoding of Mail headers

$_headerEncoding : string

Default

\Zend_Mime::ENCODING_QUOTEDPRINTABLE
 

Mail headers

$_headers : array

Default

array()
 

Message-ID: header

$_messageId : string

Default

null
 

The Zend_Mime object for the message

$_mime : \Zend_Mime | null

Default

null
 

MIME boundary string

$_mimeBoundary : string

Default

null
 

The Zend_Mime_Parts of the message

$_parts : array

Default

array()
 

Array of all recipients

$_recipients : array

Default

array()
 

Reply-To header

$_replyTo : string

Default

null
 

Return-Path header

$_returnPath : string

Default

null
 

Subject: header

$_subject : string

Default

null
 

To: addresses

$_to : array

Default

array()
 

Content type of the message

$_type : string

Default

null