Mail_Mime
[ class tree: Mail_Mime ] [ index: Mail_Mime ] [ all elements ]

Class: Mail_mime

Source Location: /Mail_Mime-1.10.0/Mail/mime.php

Class Overview


The Mail_Mime class provides an OO interface to create MIME enabled email messages. This way you can create emails that contain plain-text bodies, HTML bodies, attachments, inline images and specific headers.


Author(s):

Version:

  • Release: @package_version@

Copyright:

  • 2003-2006 PEAR <pear-group@php.net>

Variables

Methods


Inherited Variables

Inherited Methods


Class Details

[line 83]
The Mail_Mime class provides an OO interface to create MIME enabled email messages. This way you can create emails that contain plain-text bodies, HTML bodies, attachments, inline images and specific headers.


[ Top ]


Class Variables

$build_params = array(
        // What encoding to use for the headers
        // Options: quoted-printable or base64
        'head_encoding' => 'quoted-printable',
        // What encoding to use for plain text
        // Options: 7bit, 8bit, base64, or quoted-printable
        'text_encoding' => 'quoted-printable',
        // What encoding to use for html
        // Options: 7bit, 8bit, base64, or quoted-printable
        'html_encoding' => 'quoted-printable',
        // What encoding to use for calendar part
        // Options: 7bit, 8bit, base64, or quoted-printable
        'calendar_encoding' => 'quoted-printable',
        // The character set to use for html
        'html_charset'  => 'ISO-8859-1',
        // The character set to use for text
        'text_charset'  => 'ISO-8859-1',
        // The character set to use for calendar part
        'calendar_charset'  => 'UTF-8',
        // The character set to use for headers
        'head_charset'  => 'ISO-8859-1',
        // End-of-line sequence
        'eol'           => "\r\n",
        // Delay attachment files IO until building the message
        'delay_file_io' => false,
        // Default calendar method
        'calendar_method' => 'request',
        // multipart part preamble (RFC2046 5.1.1)
        'preamble' => '',
    )

[line 132]

Build parameters
  • Access: protected

Type:   array


[ Top ]

$calbody =

[line 104]

Contains the text/calendar part of the email
  • Access: protected

Type:   string


[ Top ]

$headers = array()

[line 125]

Headers for the mail
  • Access: protected

Type:   array


[ Top ]

$htmlbody =

[line 97]

Contains the html part of the email
  • Access: protected

Type:   string


[ Top ]

$html_images = array()

[line 111]

list of the attached images
  • Access: protected

Type:   array


[ Top ]

$parts = array()

[line 118]

list of the attachements
  • Access: protected

Type:   array


[ Top ]

$txtbody =

[line 90]

Contains the plain text part of the email
  • Access: protected

Type:   string


[ Top ]



Method Detail

__construct (Constructor)   [line 173]

void __construct( [mixed $params = array()])

Constructor function
  • Access: public

Parameters:

mixed   $params   —  Build parameters that change the way the email is built. Should be an associative array. See $_build_params.

[ Top ]

addAlternativePart   [line 584]

object The addAlternativePart( [mixed $obj = null])

Adds a multipart/alternative part to a mimePart object (or creates one), and returns it during the build process.
  • Return: multipart/mixed mimePart object
  • Access: protected

Parameters:

mixed   $obj   —  The object to add the part to, or anything else if a new object is to be created.

[ Top ]

addAttachment   [line 402]

mixed addAttachment( mixed $file, [string $c_type = 'application/octet-stream'], [string $name = ''], [bool $isfile = true], [string $encoding = 'base64'], [string $disposition = 'attachment'], [string $charset = ''], [string $language = ''], [string $location = ''], [string $n_encoding = null], [string $f_encoding = null], [string $description = ''], [string $h_charset = null], [array $add_headers = array()])

Adds a file to the list of attachments.
  • Return: True on success or PEAR_Error object
  • Access: public

Parameters:

mixed   $file   —  The file name or the file contents itself, it can be also Mail_mimePart object
string   $c_type   —  The content type
string   $name   —  The filename of the attachment Only use if $file is the contents
bool   $isfile   —  Whether $file is a filename or not. Defaults to true
string   $encoding   —  The type of encoding to use. Defaults to base64. Possible values: 7bit, 8bit, base64 or quoted-printable.
string   $disposition   —  The content-disposition of this file Defaults to attachment. Possible values: attachment, inline.
string   $charset   —  The character set of attachment's content.
string   $language   —  The language of the attachment
string   $location   —  The RFC 2557.4 location of the attachment
string   $n_encoding   —  Encoding of the attachment's name in Content-Type By default filenames are encoded using RFC2231 method Here you can set RFC2047 encoding (quoted-printable or base64) instead
string   $f_encoding   —  Encoding of the attachment's filename in Content-Disposition header.
string   $description   —  Content-Description header
string   $h_charset   —  The character set of the headers e.g. filename If not specified, $charset will be used
array   $add_headers   —  Additional part headers. Array keys can be in form of <header_name>:<parameter_name>

[ Top ]

addAttachmentPart   [line 660]

object The addAttachmentPart( object $obj, mixed $value)

Adds an attachment subpart to a mimePart object and returns it during the build process.
  • Return: image mimePart object
  • Access: protected

Parameters:

object   $obj   —  The mimePart to add the image to
mixed   $value   —  The attachment information array or Mail_mimePart object

[ Top ]

addBcc   [line 1269]

void addBcc( string $email)

Add an email to the Bcc (blank carbon copy) header (multiple calls to this method are allowed)
  • Access: public

Parameters:

string   $email   —  The email direction to add

[ Top ]

addBodyPart   [line 1581]

object The addBodyPart( mixed $obj, string $body, string $ctype, string $type)

Adds a subpart to the mimePart object and returns it during the build process.
  • Return: mimePart object
  • Access: protected

Parameters:

mixed   $obj   —  The object to add the part to, or anything else if a new object is to be created.
string   $body   —  Part body
string   $ctype   —  Part content type
string   $type   —  Internal part type

[ Top ]

addCalendarPart   [line 549]

object The addCalendarPart( [mixed $obj = null])

Adds a calendar subpart to the mimePart object and returns it during the build process.
  • Return: text mimePart object
  • Access: protected

Parameters:

mixed   $obj   —  The object to add the part to, or anything else if a new object is to be created.

[ Top ]

addCc   [line 1252]

void addCc( string $email)

Add an email to the Cc (carbon copy) header (multiple calls to this method are allowed)
  • Access: public

Parameters:

string   $email   —  The email direction to add

[ Top ]

addHTMLImage   [line 331]

bool addHTMLImage( string $file, [string $c_type = 'application/octet-stream'], [string $name = ''], [bool $isfile = true], [string $content_id = null])

Adds an image to the list of embedded images.

Images added this way will be added as related parts of the HTML message.

To correctly match the HTML image with the related attachment HTML should refer to it by a filename (specified in $file or $name arguments) or by cid:<content-id> (specified in $content_id arg).

  • Return: True on success
  • Access: public

Parameters:

string   $file   —  The image file name OR image data itself
string   $c_type   —  The content type
string   $name   —  The filename of the image. Used to find the image in HTML content.
bool   $isfile   —  Whether $file is a filename or not. Defaults to true
string   $content_id   —  Desired Content-ID of MIME part Defaults to generated unique ID

[ Top ]

addHtmlImagePart   [line 631]

object The addHtmlImagePart( object $obj, array $value)

Adds an html image subpart to a mimePart object and returns it during the build process.
  • Return: image mimePart object
  • Access: protected

Parameters:

object   $obj   —  The mimePart to add the image to
array   $value   —  The image information

[ Top ]

addHtmlPart   [line 535]

object The addHtmlPart( [mixed $obj = null])

Adds a html subpart to the mimePart object and returns it during the build process.
  • Return: html mimePart object
  • Access: protected

Parameters:

mixed   $obj   —  The object to add the part to, or anything else if a new object is to be created.

[ Top ]

addMixedPart   [line 565]

object The addMixedPart( [array $params = array()])

Creates a new mimePart object, using multipart/mixed as the initial content-type and returns it during the build process.
  • Return: multipart/mixed mimePart object
  • Access: protected

Parameters:

array   $params   —  Additional part parameters

[ Top ]

addRelatedPart   [line 608]

object The addRelatedPart( [mixed $obj = null])

Adds a multipart/related part to a mimePart object (or creates one), and returns it during the build process.
  • Return: multipart/mixed mimePart object
  • Access: protected

Parameters:

mixed   $obj   —  The object to add the part to, or anything else if a new object is to be created

[ Top ]

addTextPart   [line 521]

object The addTextPart( [mixed $obj = null])

Adds a text subpart to the mimePart object and returns it during the build process.
  • Return: text mimePart object
  • Access: protected

Parameters:

mixed   $obj   —  The object to add the part to, or anything else if a new object is to be created.

[ Top ]

addTo   [line 1235]

void addTo( string $email)

Add an email to the To header (multiple calls to this method are allowed)
  • Access: public

Parameters:

string   $email   —  The email direction to add

[ Top ]

basename   [line 1359]

string basename( string $filename)

Get file's basename (locale independent)
  • Return: Basename
  • Access: protected

Parameters:

string   $filename   —  Filename

[ Top ]

checkParams   [line 1488]

void checkParams( )

Validate and set build parameters
  • Access: protected

[ Top ]

contentHeaders   [line 1374]

array contentHeaders( )

Get Content-Type and Content-Transfer-Encoding headers of the message
  • Return: Headers array
  • Access: protected

[ Top ]

encodeHeader   [line 1345]

string encodeHeader( string $name, string $value, string $charset, string $encoding)

Encodes a header as per RFC2047
  • Return: Encoded header data (without a name)
  • Since: 1.5.3
  • Access: public

Parameters:

string   $name   —  The header name
string   $value   —  The header data to encode
string   $charset   —  Character set name
string   $encoding   —  Encoding name (base64 or quoted-printable)

[ Top ]

encodeHeaders   [line 1305]

array encodeHeaders( array $input, [array $params = array()])

Encodes headers as per RFC2047
  • Return: Encoded data
  • Access: protected

Parameters:

array   $input   —  The header data to encode
array   $params   —  Extra build parameters

[ Top ]

encodeRecipients   [line 1289]

string encodeRecipients( string $recipients)

Since the PHP send function requires you to specify recipients (To: header) separately from the other headers, the To: header is not properly encoded.

To fix this, you can use this public method to encode your recipients before sending to the send function.

  • Return: Encoded data
  • Access: public

Parameters:

string   $recipients   —  A comma-delimited list of recipients

[ Top ]

file2str   [line 485]

string file2str( string $file_name)

Get the contents of the given file name as string
  • Return: Contents of $file_name
  • Access: protected

Parameters:

string   $file_name   —  Path of file to process

[ Top ]

get   [line 858]

mixed get( [array $params = null], [mixed $filename = null], [boolean $skip_head = false])

Builds the multipart message from the list ($this->parts) and returns the mime content.
  • Return: The MIME message content string, null or PEAR error object
  • Access: public

Parameters:

array   $params   —  Build parameters that change the way the email is built. Should be associative. See $_build_params.
mixed   $filename   —  Output filename or file pointer where to save the message instead of returning it
boolean   $skip_head   —  True if you want to return/save only the message without headers

[ Top ]

getCalendarBody   [line 307]

string getCalendarBody( )

Get body of calendar part
  • Return: Calendar part body
  • Since: 1.9.0
  • Access: public

[ Top ]

getHTMLBody   [line 268]

string getHTMLBody( )

Get message HTML body
  • Return: HTML body
  • Since: 1.6.0
  • Access: public

[ Top ]

getMessage   [line 721]

mixed getMessage( [string $separation = null], [array $params = null], [array $headers = null], [bool $overwrite = false])

Returns the complete e-mail, ready to send using an alternative

mail delivery method. Note that only the mailpart that is made with Mail_Mime is created. This means that, YOU WILL HAVE NO TO: HEADERS UNLESS YOU SET IT YOURSELF using the $headers parameter!

  • Return: The complete e-mail or PEAR error object
  • Access: public

Parameters:

string   $separation   —  The separation between these two parts.
array   $params   —  The Build parameters passed to the get() function. See get() for more info.
array   $headers   —  The extra headers that should be passed to the headers() method. See that function for more info.
bool   $overwrite   —  Overwrite the existing headers with new.

[ Top ]

getMessageBody   [line 747]

mixed getMessageBody( [array $params = null])

Returns the complete e-mail body, ready to send using an alternative mail delivery method.
  • Return: The e-mail body or PEAR error object
  • Since: 1.6.0
  • Access: public

Parameters:

array   $params   —  The Build parameters passed to the get() method. See get() for more info.

[ Top ]

getParam   [line 212]

mixed getParam( string $name)

Get build parameter value
  • Return: Parameter value
  • Since: 1.6.0
  • Access: public

Parameters:

string   $name   —  Parameter name

[ Top ]

getTXTBody   [line 243]

string getTXTBody( )

Get message text body
  • Return: Text body
  • Since: 1.6.0
  • Access: public

[ Top ]

headers   [line 1078]

array headers( [array $xtra_headers = null], [bool $overwrite = false], [bool $skip_content = false])

Returns an array with the headers needed to prepend to the email (MIME-Version and Content-Type). Format of argument is: $array['header-name'] = 'header-value';
  • Return: Assoc array with the mime headers
  • Access: public

Parameters:

array   $xtra_headers   —  Assoc array with any extra headers (optional) (Don't set Content-Type for multipart messages here!)
bool   $overwrite   —  Overwrite already existing headers.
bool   $skip_content   —  Don't return content headers: Content-Type, Content-Disposition and Content-Transfer-Encoding

[ Top ]

isError   [line 1604]

bool isError( mixed $data)

PEAR::isError implementation
  • Return: True if object is an instance of PEAR_Error
  • Access: public

Parameters:

mixed   $data   —  Object

[ Top ]

isMultipart   [line 472]

bool isMultipart( )

Checks if the current message has many parts
  • Return: True if the message has many parts, False otherwise.
  • Since: 1.9.0
  • Access: public

[ Top ]

raiseError   [line 1621]

PEAR_Error raiseError( string $message)

PEAR::raiseError implementation
  • Return: Instance of PEAR_Error
  • Access: public

Parameters:

string   $message   —  A text error message

[ Top ]

saveMessage   [line 766]

mixed saveMessage( string $filename, [array $params = null], [array $headers = null], [bool $overwrite = false])

Writes (appends) the complete e-mail into file.
  • Return: True or PEAR error object
  • Since: 1.6.0
  • Access: public

Parameters:

string   $filename   —  Output file location
array   $params   —  The Build parameters passed to the get() method. See get() for more info.
array   $headers   —  The extra headers that should be passed to the headers() function. See that function for more info.
bool   $overwrite   —  Overwrite the existing headers with new.

[ Top ]

saveMessageBody   [line 811]

mixed saveMessageBody( mixed $filename, [array $params = null])

Writes (appends) the complete e-mail body into file or stream.
  • Return: True or PEAR error object
  • Since: 1.6.0
  • Access: public

Parameters:

mixed   $filename   —  Output filename or file pointer where to save the message instead of returning it
array   $params   —  The Build parameters passed to the get() method. See get() for more info.

[ Top ]

setBody   [line 1545]

mixed setBody( string $type, string $data, [bool $isfile = false], [bool $append = false])

Set body of specified message part
  • Return: True on success or PEAR_Error object
  • Access: protected

Parameters:

string   $type   —  One of: txtbody, calbody, htmlbody
string   $data   —  Either a string or the file name with the contents
bool   $isfile   —  If true the first param should be treated as a file name, else as a string (default)
bool   $append   —  If true the text or file is appended to the existing body, else the old body is overwritten

[ Top ]

setCalendarBody   [line 289]

mixed setCalendarBody( string $data, [bool $isfile = false], [bool $append = false], [string $method = 'request'], [string $charset = 'UTF-8'], [string $encoding = 'quoted-printable'])

Function to set a body of text/calendar part (not attachment)
  • Return: True on success or PEAR_Error object
  • Since: 1.9.0
  • Access: public

Parameters:

string   $data   —  Either a string or the file name with the contents
bool   $isfile   —  If true the first param should be treated as a file name, else as a string (default)
bool   $append   —  If true the text or file is appended to the existing body, else the old body is overwritten
string   $method   —  iCalendar object method
string   $charset   —  iCalendar character set
string   $encoding   —  Transfer encoding

[ Top ]

setContentType   [line 1166]

void setContentType( string $type, [array $params = array()])

Sets message Content-Type header.

Use it to build messages with various content-types e.g. miltipart/raport not supported by contentHeaders() function.

  • Since: 1.7.0
  • Access: public

Parameters:

string   $type   —  Type name
array   $params   —  Hash array of header parameters

[ Top ]

setFrom   [line 1222]

void setFrom( string $email)

Set an email to the From (the sender) header
  • Access: public

Parameters:

string   $email   —  The email address to use

[ Top ]

setHTMLBody   [line 257]

bool setHTMLBody( string $data, [bool $isfile = false])

Adds a html part to the mail.
  • Return: True on success or PEAR_Error object
  • Access: public

Parameters:

string   $data   —  Either a string or the file name with the contents
bool   $isfile   —  A flag that determines whether $data is a filename, or a string(false, default)

[ Top ]

setParam   [line 199]

void setParam( string $name, string $value)

Set build parameter value
  • Since: 1.6.0
  • Access: public

Parameters:

string   $name   —  Parameter name
string   $value   —  Parameter value

[ Top ]

setSubject   [line 1210]

void setSubject( string $subject)

Sets the Subject header
  • Access: public

Parameters:

string   $subject   —  String to set the subject to.

[ Top ]

setTXTBody   [line 232]

mixed setTXTBody( string $data, [bool $isfile = false], [bool $append = false])

Accessor function to set the body text. Body text is used if it's not an html mail being sent or else is used to fill the text/plain part that emails clients who don't support html should show.
  • Return: True on success or PEAR_Error object
  • Access: public

Parameters:

string   $data   —  Either a string or the file name with the contents
bool   $isfile   —  If true the first param should be treated as a file name, else as a string (default)
bool   $append   —  If true the text or file is appended to the existing body, else the old body is overwritten

[ Top ]

txtHeaders   [line 1127]

string txtHeaders( [array $xtra_headers = null], [bool $overwrite = false], [bool $skip_content = false])

Get the text version of the headers (usefull if you want to use the PHP mail() function)
  • Return: Plain text headers
  • Access: public

Parameters:

array   $xtra_headers   —  Assoc array with any extra headers (optional) (Don't set Content-Type for multipart messages here!)
bool   $overwrite   —  Overwrite the existing headers with new.
bool   $skip_content   —  Don't return content headers: Content-Type, Content-Disposition and Content-Transfer-Encoding

[ Top ]


Documentation generated on Wed, 09 Dec 2015 23:15:30 +0000 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.