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

Class: Mail_mime

Source Location: /Mail_Mime-1.9.0RC1/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 95]
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',
        // 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 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
    )

[line 137]

Build parameters
  • Access: protected

Type:   array


[ Top ]

$headers = array()

[line 130]

Headers for the mail
  • Access: protected

Type:   array


[ Top ]

$htmlbody =

[line 109]

Contains the html part of the email
  • Access: protected

Type:   string


[ Top ]

$html_images = array()

[line 116]

list of the attached images
  • Access: protected

Type:   array


[ Top ]

$parts = array()

[line 123]

list of the attachements
  • Access: protected

Type:   array


[ Top ]

$txtbody =

[line 102]

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

Type:   string


[ Top ]



Method Detail

__construct (Constructor)   [line 169]

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

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

mixed addAttachment( string $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:

string   $file   —  The file name of the file to attach or the file contents itself
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 647]

object The addAttachmentPart( object $obj, array $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
array   $value   —  The attachment information

[ Top ]

addBcc   [line 1235]

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 ]

addCc   [line 1218]

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

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

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

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

object The addMixedPart( )

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

[ Top ]

addRelatedPart   [line 595]

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

object The addTextPart( [mixed $obj = null], [string $text = ''])

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.
string   $text   —  The text to add.

[ Top ]

addTo   [line 1201]

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

string basename( string $filename)

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

Parameters:

string   $filename   —  Filename

[ Top ]

checkParams   [line 1427]

void checkParams( )

Validate and set build parameters
  • Access: protected

[ Top ]

contentHeaders   [line 1338]

array contentHeaders( )

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

[ Top ]

encodeHeader   [line 1309]

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

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

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

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

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 ]

getHTMLBody   [line 295]

string getHTMLBody( )

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

[ Top ]

getMessage   [line 704]

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

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

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

string getTXTBody( )

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

[ Top ]

headers   [line 1044]

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

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

bool isMultipart( )

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

[ Top ]

raiseError   [line 1483]

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

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

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 ]

setContentType   [line 1132]

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

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

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

Adds a html part to the mail.
  • Return: True on success
  • 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 195]

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

void setSubject( string $subject)

Sets the Subject header
  • Access: public

Parameters:

string   $subject   —  String to set the subject to.

[ Top ]

setTXTBody   [line 229]

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

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, 05 Jul 2015 12:30:03 +0000 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.