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

Class: Mail_mime

Source Location: /Mail_Mime-1.10.7/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 582]

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 400]

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 658]

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 1245]

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 1542]

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 547]

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 1228]

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 329]

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 629]

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 533]

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 563]

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 606]

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 519]

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 1211]

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 1335]

string basename( string $filename)

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

Parameters:

string   $filename   —  Filename

[ Top ]

buildAlternativeParts   [line 982]

null|object The buildAlternativeParts( Mail_mimePart|null $parent_part, [array $mixed_params = null])

Builds a single text, html, or calendar part only if one of them is found.

If two or more parts are found, then an alternative part containing them is built.

  • Return: main part built inside the method. It will be an alternative part or text, html, or calendar part. Null if no body texts are found.
  • Access: protected

Parameters:

Mail_mimePart|null   $parent_part   —  The parent mime part to add the part or null
array   $mixed_params   —  The needed params to create the part when no parent_part is received.

[ Top ]

buildBodyPart   [line 949]

Mail_mimePart|null buildBodyPart( )

Builds the main body MIME part for the email body. It will add a mixed part if attachments are found. If no attachments are found it will return an alternative part if several body texts are found (text, html, calendar), or a single part if only one body text is found.

[ Top ]

buildHtmlParts   [line 1023]

Mail_mimePart|null buildHtmlParts( Mail_mimePart|null $parent_part)

Builds html part as a single part or inside a related part with the html images thar were found.
  • Return: The created part or null if no htmlbody found.
  • Access: protected

Parameters:

Mail_mimePart|null   $parent_part   —  The object to add the part to, or anything else if a new object is to be created.

[ Top ]

checkParams   [line 1455]

void checkParams( )

Validate and set build parameters
  • Access: protected

[ Top ]

contentHeaders   [line 1350]

array contentHeaders( )

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

[ Top ]

encodeHeader   [line 1321]

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 1281]

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 1265]

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 483]

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 856]

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 305]

string getCalendarBody( )

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

[ Top ]

getHTMLBody   [line 266]

string getHTMLBody( )

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

[ Top ]

getMessage   [line 719]

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 745]

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 210]

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 241]

string getTXTBody( )

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

[ Top ]

headers   [line 1058]

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 1565]

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 470]

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 1582]

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 764]

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 809]

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 1512]

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 287]

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 1145]

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 1198]

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 255]

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 197]

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 1186]

void setSubject( string $subject)

Sets the Subject header
  • Access: public

Parameters:

string   $subject   —  String to set the subject to.

[ Top ]

setTXTBody   [line 230]

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 1106]

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 Sun, 01 Mar 2020 02:56:06 -0500 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.