PHPMailer - PHP email transport class

package PHPMailer
author Andy Prevost
copyright 2004 - 2009 Andy Prevost

 Methods

Adds a "To" address.

AddAddress(string $address, string $name = '') : void

Parameters

$address

string

$name

string

Adds an attachment from a path on the filesystem.

AddAttachment(string $path, string $name = '', string $encoding = 'base64', string $type = 'application/octet-stream') : boolean

Returns false if the file could not be found or accessed.

Parameters

$path

string

Path to the attachment.

$name

string

Overrides the attachment name.

$encoding

string

File encoding (see $Encoding).

$type

string

File extension (MIME) type.

Returns

boolean

Adds a "Bcc" address. Note: this function works with the SMTP mailer on win32, not with the "mail" mailer.

AddBCC(string $address, string $name = '') : void

Parameters

$address

string

$name

string

Adds a "Cc" address. Note: this function works with the SMTP mailer on win32, not with the "mail" mailer.

AddCC(string $address, string $name = '') : void

Parameters

$address

string

$name

string

Adds a custom header.

AddCustomHeader($custom_header) : void

Parameters

$custom_header

Adds an embedded attachment. This can include images, sounds, and just about any other document. Make sure to set the $type to an image type. For JPEG images use "image/jpeg" and for GIF images use "image/gif".

AddEmbeddedImage(string $path, string $cid, string $name = '', string $encoding = 'base64', string $type = 'application/octet-stream') : boolean

Parameters

$path

string

Path to the attachment.

$cid

string

Content ID of the attachment. Use this to identify the Id for accessing the image in an HTML form.

$name

string

Overrides the attachment name.

$encoding

string

File encoding (see $Encoding).

$type

string

File extension (MIME) type.

Returns

boolean

Adds a "Reply-To" address.

AddReplyTo(string $address, string $name = '') : void

Parameters

$address

string

$name

string

Adds a string or binary attachment (non-filesystem) to the list.

AddStringAttachment(string $string, string $filename, string $encoding = 'base64', string $type = 'application/octet-stream') : void

This method can be used to attach ascii or binary data, such as a BLOB record from a database.

Parameters

$string

string

String attachment data.

$filename

string

Name of the attachment.

$encoding

string

File encoding (see $Encoding).

$type

string

File extension (MIME) type.

Creates recipient headers.

AddrAppend($type, $addr) : string
access private

Parameters

$type

$addr

Returns

string

Formats an address correctly.

AddrFormat($addr) : string
access private

Parameters

$addr

Returns

string

Attaches all fs, string, and binary attachments to the message.

AttachAll() : string

Returns an empty string on failure.

access private

Returns

string

Correctly encodes and wraps long multibyte strings for mail headers without breaking lines within a character.

Base64EncodeWrapMB(string $str) : string
access private

Parameters

$str

string

multi-byte text to wrap encode

Returns

string

Clears all recipients assigned in the TO array. Returns void.

ClearAddresses() : void

Clears all recipients assigned in the TO, CC and BCC array. Returns void.

ClearAllRecipients() : void

Clears all previously set filesystem, string, and binary attachments. Returns void.

ClearAttachments() : void

Clears all recipients assigned in the BCC array. Returns void.

ClearBCCs() : void

Clears all recipients assigned in the CC array. Returns void.

ClearCCs() : void

Clears all custom headers. Returns void.

ClearCustomHeaders() : void

Clears all recipients assigned in the ReplyTo array. Returns void.

ClearReplyTos() : void

Assembles the message body. Returns an empty string on failure.

CreateBody() : string
access private

Returns

string

Assembles message header.

CreateHeader() : string
access private

Returns

string

Encodes attachment in requested format. Returns an empty string on failure.

EncodeFile($path, $encoding = 'base64') : string
access private

Parameters

$path

$encoding

Returns

string

Encode a header string to best of Q, B, quoted or none.

EncodeHeader($str, $position = 'text') : string
access private

Parameters

$str

$position

Returns

string

Encode string to q encoding.

EncodeQ($str, $position = 'text') : string
access private

Parameters

$str

$position

Returns

string

Encode string to quoted-printable.

EncodeQP($input = '', $line_max = 76, $space_conv = false) : string
access private

Parameters

$input

$line_max

$space_conv

Returns

string

Callback for converting to "=XX".

EncodeQ_callback($matches) : string
access private

Parameters

$matches

Returns

string

Encodes string to requested format. Returns an empty string on failure.

EncodeString($str, $encoding = 'base64') : string
access private

Parameters

$str

$encoding

Returns

string

Returns the end of a message boundary.

EndBoundary($boundary) 
access private

Parameters

$boundary

Changes every end of line from CR or LF to CRLF.

FixEOL($str) : string
access private

Parameters

$str

Returns

string

Returns the start of a message boundary.

GetBoundary($boundary, $charSet, $contentType, $encoding) 
access private

Parameters

$boundary

$charSet

$contentType

$encoding

Returns the message MIME.

GetMailMIME() : string
access private

Returns

string

Checks if a string contains multibyte characters.

HasMultiBytes(string $str) : boolean
access private

Parameters

$str

string

multi-byte text to wrap encode

Returns

boolean

HeaderLine()

HeaderLine($name, $value) 

Parameters

$name

$value

Returns true if an inline attachment is present.

InlineImageExists() : boolean
access private

Returns

boolean

Returns true if an error occurred.

IsError() : boolean

Returns

boolean

Sets message type to HTML.

IsHTML(boolean $bool) : void

Parameters

$bool

boolean

Sets Mailer to send message using PHP mail() function.

IsMail() : void

Sets Mailer to send message using the qmail MTA.

IsQmail() : void

Sets Mailer to send message using SMTP.

IsSMTP() : void

Sets Mailer to send message using the $Sendmail program.

IsSendmail() : void

Returns a message in the appropriate language.

Lang($key) : string
access private

Parameters

$key

Returns

string

Sends mail using the PHP mail() function.

MailSend($header, $body) : boolean
access private

Parameters

$header

$body

Returns

boolean

Evaluates the message and returns modifications for inline images and backgrounds

MsgHTML($message, $basedir = '') : \$message
access public

Parameters

$message

$basedir

Returns

\$message

Returns the proper RFC 822 formatted date.

RFCDate() : string
access private

Returns

string

Strips newlines to prevent header injection.

SecureHeader(string $str) : string
access private

Parameters

$str

string

String

Returns

string

Creates message and assigns Mailer. If the message is not sent successfully then it returns false. Use the ErrorInfo variable to view description of the error.

Send() : boolean

Returns

boolean

Sends mail using the $Sendmail program.

SendmailSend($header, $body) : boolean
access private

Parameters

$header

$body

Returns

boolean

Returns the server hostname or 'localhost.localdomain' if unknown.

ServerHostname() : string
access private

Returns

string

Returns the appropriate server variable. Should work with both PHP 4.1.0+ as well as older versions. Returns an empty string if nothing is found.

ServerVar($varName) : mixed
access private

Parameters

$varName

Returns

mixed

Adds the error message to the error container.

SetError($msg) : void

Returns void.

access private

Parameters

$msg

Sets the language for all class error messages. Returns false if it cannot load the language file. The default language type is English.

SetLanguage(string $lang_type, string $lang_path = 'language/') : boolean
access public

Parameters

$lang_type

string

Type of language (e.g. Portuguese: "br")

$lang_path

string

Path to the language file directory

Returns

boolean

Sets the message type.

SetMessageType() : void
access private

Set the body wrapping.

SetWordWrap() : void
access private

Set the private key file and password to sign the message.

Sign($cert_filename, string $key_filename, string $key_pass) 
access public

Parameters

$cert_filename

$key_filename

string

Parameter File Name

$key_pass

string

Password for private key

Closes the active SMTP session if one exists.

SmtpClose() : void

Initiates a connection to an SMTP server. Returns false if the operation failed.

SmtpConnect() : boolean
access private

Returns

boolean

Sends mail via SMTP using PhpSMTP (Author: Chris Ryan). Returns bool. Returns false if there is a bad MAIL FROM, RCPT, or DATA input.

SmtpSend($header, $body) : boolean
access private

Parameters

$header

$body

Returns

boolean

Returns a formatted mail line.

TextLine($value) : string
access private

Parameters

$value

Returns

string

Finds last character boundary prior to maxLength in a utf-8 quoted (printable) encoded string.

UTF8CharBoundary(string $encodedText, integer $maxLength) : integer

Original written by Colin Brown.

access private

Parameters

$encodedText

string

utf-8 QP text

$maxLength

integer

find last character boundary prior to this length

Returns

integer

Wraps message for use with mailers that do not automatically perform wrapping and for quoted-printable.

WrapText($message, $length, $qp_mode = false) : string

Original written by philippe.

access private

Parameters

$message

$length

$qp_mode

Returns

string

Gets the mime type of the embedded or inline image

_mime_types($ext = '') : \mime
access private

Parameters

$ext

Returns

\mimetype of ext

Read a file from a supplied filename and return it.

getFile(string $filename) 
access public

Parameters

$filename

string

Parameter File Name

Set (or reset) Class Objects (variables)

set(string $name, mixed $value = ''

Usage Example: $page->set('X-Priority', '3');

access public

Parameters

$name

string

Parameter Name

$value

mixed

Parameter Value NOTE: will not work with arrays, there are no arrays to set/reset

 Properties

 

Sets the text-only body of the message. This automatically sets the email to multipart/alternative. This body can be read by mail clients that do not have HTML email capability such as mutt. Clients that can read HTML will view the normal Body.

$AltBody : string

Default

''
 

Sets the Body of the message. This can be either an HTML or text body.

$Body : string

Default

''

If HTML then run IsHTML(true).

 

Sets the CharSet of the message.

$CharSet : string

Default

'iso-8859-1'
 

Sets the email address that a reading confirmation will be sent.

$ConfirmReadingTo : string

Default

''
 

Sets the Content-type of the message.

$ContentType : string

Default

'text/plain'
 

$CustomHeader

$CustomHeader 

Default

array()
 

Sets the Encoding of the message. Options for this are "8bit", "7bit", "binary", "base64", and "quoted-printable".

$Encoding : string

Default

'8bit'
 

Holds the most recent mailer error message.

$ErrorInfo : string

Default

''
 

Sets the From email address for the message.

$From : string

Default

'root@localhost'
 

Sets the From name of the message.

$FromName : string

Default

'Root User'
 

Sets the SMTP HELO of the message (Default is $Hostname).

$Helo : string

Default

''
 

Sets the SMTP hosts. All hosts must be separated by a semicolon. You can also specify a different port for each host by using this format: [hostname:port] (e.g. "smtp1.example.com:25;smtp2.example.com").

$Host : string

Default

'localhost'

Hosts will be tried in order.

 

Sets the hostname to use in Message-Id and Received headers and as default HELO string. If empty, the value returned by SERVER_NAME is used or 'localhost.localdomain'.

$Hostname : string

Default

''
 

$LE

$LE 

Default

"\n"
 

Method to send mail: ("mail", "sendmail", or "smtp").

$Mailer : string

Default

'mail'
 

Sets the message ID to be used in the Message-Id header.

$MessageID : string

Default

''

If empty, a unique id will be generated.

 

Sets SMTP password.

$Password : string

Default

''
 

Path to PHPMailer plugins. This is now only useful if the SMTP class is in a different directory than the PHP include path.

$PluginDir : string

Default

''
 

Sets the default SMTP server port.

$Port : integer

Default

25
 

Email priority (1 = High, 3 = Normal, 5 = low).

$Priority : integer

Default

3
 

$ReplyTo

$ReplyTo 

Default

array()
 

Sets SMTP authentication. Utilizes the Username and Password variables.

$SMTPAuth : boolean

Default

false
 

Sets SMTP class debugging on or off.

$SMTPDebug : boolean

Default

false
 

Prevents the SMTP connection from being closed after each mail sending. If this is set to true then to close the connection requires an explicit call to SmtpClose().

$SMTPKeepAlive : boolean

Default

false
 

Sets connection prefix.

$SMTPSecure : string

Default

""

Options are "", "ssl" or "tls"

 

Sets the Sender email (Return-Path) of the message. If not empty, will be sent via -f to sendmail or as 'MAIL FROM' in smtp mode.

$Sender : string

Default

''
 

Sets the path of the sendmail program.

$Sendmail : string

Default

'/usr/sbin/sendmail'
 

Provides the ability to have the TO field process individual emails, instead of sending to entire TO addresses

$SingleTo : boolean

Default

false
 

Sets the Subject of the message.

$Subject : string

Default

''
 

Sets the SMTP server timeout in seconds. This function will not work with the win32 version.

$Timeout : integer

Default

10
 

Sets SMTP username.

$Username : string

Default

''
 

Holds PHPMailer version.

$Version : string

Default

"2.0.4"
 

Sets word wrapping on the body of the message to a given number of characters.

$WordWrap : integer

Default

0
 

$attachment

$attachment 

Default

array()
 

$bcc

$bcc 

Default

array()
 

$boundary

$boundary 

Default

array()
 

$cc

$cc 

Default

array()
 

$error_count

$error_count 

Default

0
 

$language

$language 

Default

array()
 

$message_type

$message_type 

Default

''
 

$sign_cert_file

$sign_cert_file 

Default

""
 

$sign_key_file

$sign_key_file 

Default

""
 

$sign_key_pass

$sign_key_pass 

Default

""
 

$smtp

$smtp 

Default

NULL
 

$to

$to 

Default

array()