PHP email creation and transport class

package | PHPMailer

### Methods

## Adds a "To" address.

    AddAddress(string $address, string $name) : boolean

### Parameters

#### $address

`string`

#### $name

`string`

### Returns

`boolean`true on success, false if address already used

## Adds an attachment from a path on the filesystem.

    AddAttachment(string $path, string $name, string $encoding, string $type) : bool

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.

### Exceptions

`\phpmailerException` |

### Returns

`bool`

## Adds a "Bcc" address.

    AddBCC(string $address, string $name) : boolean

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

### Parameters

#### $address

`string`

#### $name

`string`

### Returns

`boolean`true on success, false if address already used

## Adds a "Cc" address.

    AddCC(string $address, string $name) : boolean

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

### Parameters

#### $address

`string`

#### $name

`string`

### Returns

`boolean`true on success, false if address already used

## Adds a custom header.

    AddCustomHeader(string $name, string $value) : void

$name value can be overloaded to contain both header name and value (name:value)

access | public

### Parameters

#### $name

`string`

custom header name

#### $value

`string`

header value

## Adds an embedded attachment.

    AddEmbeddedImage(string $path, string $cid, string $name, string $encoding, string $type) : bool

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".

### 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

`bool`

## Adds a "Reply-to" address.

    AddReplyTo(string $address, string $name) : boolean

### Parameters

#### $address

`string`

#### $name

`string`

### Returns

`boolean`

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

    AddStringAttachment(string $string, string $filename, string $encoding, string $type) : 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.

## Adds an embedded stringified attachment.

    AddStringEmbeddedImage(string $string, string $cid, string $name, string $encoding, string $type) : bool

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".

### Parameters

#### $string

`string`

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

`bool`

## Creates recipient headers.

    AddrAppend(string $type, array $addr) : string

access | public

### Parameters

#### $type

`string`

#### $addr

`array`

### Returns

`string`

## Formats an address correctly.

    AddrFormat(string $addr) : string

access | public

### Parameters

#### $addr

`string`

### Returns

`string`

## Does this message have an alternative body set?

    AlternativeExists() : bool

### Returns

`bool`

## Returns true if an attachment (non-inline) is present.

    AttachmentExists() : bool

### Returns

`bool`

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

    Base64EncodeWrapMB(string $str, string $lf) : string

Adapted from a function by paravoid at http://uk.php.net/manual/en/function.mb-encode-mimeheader.php

access | public

### Parameters

#### $str

`string`

multi-byte text to wrap encode

#### $lf

`string`

string to use as linefeed/end-of-line

### Returns

`string`

## Clears all recipients assigned in the TO array.

    ClearAddresses() : void

Returns void.

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

    ClearAllRecipients() : void

Returns void.

## Clears all previously set filesystem, string, and binary attachments.

    ClearAttachments() : void

Returns void.

## Clears all recipients assigned in the BCC array.

    ClearBCCs() : void

Returns void.

## Clears all recipients assigned in the CC array.

    ClearCCs() : void

Returns void.

## Clears all custom headers.

    ClearCustomHeaders() : void

Returns void.

## Clears all recipients assigned in the ReplyTo array.

    ClearReplyTos() : void

Returns void.

## Assembles the message body.

    CreateBody() : string

Returns an empty string on failure.

access | public

### Exceptions

`\phpmailerException` |

### Returns

`string`The assembled message body

## Assembles message header.

    CreateHeader() : string

access | public

### Returns

`string`The assembled header

## Create the DKIM header, body, as new header

    DKIM_Add(string $headers_line, string $subject, string $body) : string

access | public

### Parameters

#### $headers_line

`string`

Header lines

#### $subject

`string`

Subject

#### $body

`string`

Body

### Returns

`string`

## Generate DKIM Canonicalization Body

    DKIM_BodyC(string $body) : string

access | public

### Parameters

#### $body

`string`

Message Body

### Returns

`string`

## Generate DKIM Canonicalization Header

    DKIM_HeaderC(string $s) : string

access | public

### Parameters

#### $s

`string`

Header

### Returns

`string`

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

    DKIM_QP(string $txt) : string

access | public

### Parameters

#### $txt

`string`

### Returns

`string`

## Generate DKIM signature

    DKIM_Sign(string $s) : string

access | public

### Parameters

#### $s

`string`

Header

### Returns

`string`

## Encode a header string to best (shortest) of Q, B, quoted or none.

    EncodeHeader(string $str, string $position) : string

access | public

### Parameters

#### $str

`string`

#### $position

`string`

### Returns

`string`

## Encode string to q encoding.

    EncodeQ(string $str, string $position) : string

link | http://tools.ietf.org/html/rfc2047
access | public

### Parameters

#### $str

`string`

the text to encode

#### $position

`string`

Where the text is going to be used, see the RFC for what that means

### Returns

`string`

## Encode string to RFC2045 (6.7) quoted-printable format Uses a PHP5 stream filter to do the encoding about 64x faster than the old version Also results in same content as you started with after decoding

    EncodeQP(string $string, integer $line_max, boolean $space_conv) : string

see | \global\EncodeQPphp()
access | public
author | Marcus Bointon

### Parameters

#### $string

`string`

the text to encode

#### $line_max

`integer`

Number of chars allowed on a line before wrapping

#### $space_conv

`boolean`

Dummy param for compatibility with existing EncodeQP function

### Returns

`string`

## Encodes string to requested format.

    EncodeString(string $str, string $encoding) : string

Returns an empty string on failure.

access | public

### Parameters

#### $str

`string`

The text to encode

#### $encoding

`string`

The encoding to use; one of 'base64', '7bit', '8bit', 'binary', 'quoted-printable'

### Returns

`string`

## Changes every end of line from CRLF, CR or LF to $this->LE.

    FixEOL(string $str) : string

access | public

### Parameters

#### $str

`string`

String to FixEOL

### Returns

`string`

## Return the current array of attachments

    GetAttachments() : array

### Returns

`array`

## Returns the message MIME.

    GetMailMIME() : string

access | public

### Returns

`string`

## Returns the MIME message (headers and body).

    GetSentMIMEMessage() : string

Only really valid post PreSend().

access | public

### Returns

`string`

## Return the current array of language strings

    GetTranslations() : array

### Returns

`array`

## Checks if a string contains multibyte characters.

    HasMultiBytes(string $str) : bool

access | public

### Parameters

#### $str

`string`

multi-byte text to wrap encode

### Returns

`bool`

## Returns a formatted header line.

    HeaderLine(string $name, string $value) : string

access | public

### Parameters

#### $name

`string`

#### $value

`string`

### Returns

`string`

## Returns true if an inline attachment is present.

    InlineImageExists() : bool

access | public

### Returns

`bool`

## Returns true if an error occurred.

    IsError() : bool

access | public

### Returns

`bool`

## Sets message type to HTML.

    IsHTML(bool $ishtml) : void

### Parameters

#### $ishtml

`bool`

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

    IsMail() : void

deprecated |

## Sets Mailer to send message using the qmail MTA.

    IsQmail() : void

deprecated |

## Sets Mailer to send message using SMTP.

    IsSMTP() : void

deprecated |

## Sets Mailer to send message using the $Sendmail program.

    IsSendmail() : void

deprecated |

## Evaluates the message and returns modifications for inline images and backgrounds

    MsgHTML(string $message, string $basedir) : string

access | public

### Parameters

#### $message

`string`

Text to be HTML modified

#### $basedir

`string`

baseline directory for path

### Returns

`string`$message

## Actual Email transport function Send the email via the selected mechanism

    PostSend() : bool

### Exceptions

`\phpmailerException` |

### Returns

`bool`

## Prep mail by constructing all message entities

    PreSend() : bool

### Exceptions

`\phpmailerException` |

### Returns

`bool`

## Returns the proper RFC 822 formatted date.

    RFCDate() : string

access | public
static |

### Returns

`string`

## Strips newlines to prevent header injection.

    SecureHeader(string $str) : string

access | public

### Parameters

#### $str

`string`

String

### Returns

`string`

## Creates message and assigns Mailer.

    Send() : bool

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

### Exceptions

`\phpmailerException` |

### Returns

`bool`

## Set the From and FromName properties

    SetFrom(string $address, string $name, int $auto) : boolean

### Parameters

#### $address

`string`

#### $name

`string`

#### $auto

`int`

Also set Reply-To and Sender

### Exceptions

`\phpmailerException` |

### Returns

`boolean`

## Sets the language for all class error messages.

    SetLanguage(string $langcode, string $lang_path) : bool

Returns false if it cannot load the language file. The default language is English.

access | public

### Parameters

#### $langcode

`string`

ISO 639-1 2-character language code (e.g. Portuguese: "br")

#### $lang_path

`string`

Path to the language file directory

### Returns

`bool`

## Set the body wrapping.

    SetWordWrap() : void

access | public

## 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.

    SmtpConnect() : bool

Returns false if the operation failed.

uses | \global\SMTP
access | public

### Exceptions

`\phpmailerException` |

### Returns

`bool`

## Returns a formatted mail line.

    TextLine(string $value) : string

access | public

### Parameters

#### $value

`string`

### Returns

`string`

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

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

Original written by Colin Brown.

access | public

### Parameters

#### $encodedText

`string`

utf-8 QP text

#### $maxLength

`int`

find last character boundary prior to this length

### Returns

`int`

## Check that a string looks roughly like an email address should Static so it can be used without instantiation, public so people can overload Conforms to RFC5322: Uses *correct* regex on which FILTER_VALIDATE_EMAIL is based; So why not use FILTER_VALIDATE_EMAIL? Because it was broken to not allow a@b type valid addresses :(

    ValidateAddress(string $address) : boolean

link | http://squiloople.com/2009/12/20/email-address-validation/
copyright | regex Copyright Michael Rushton 2009-10 | http://squiloople.com/ | Feel free to use and redistribute this code. But please keep this copyright notice.
static |
access | public

### Parameters

#### $address

`string`

The email address to check

### Returns

`boolean`

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

    WrapText(string $message, integer $length, boolean $qp_mode) : string

Original written by philippe.

access | public

### Parameters

#### $message

`string`

The message to wrap

#### $length

`integer`

The line length to wrap to

#### $qp_mode

`boolean`

Whether to run in Quoted-Printable mode

### Returns

`string`

## Constructor

    __construct(boolean $exceptions)

### Parameters

#### $exceptions

`boolean`

Should we throw external exceptions?

## Gets the MIME type of the embedded or inline image

    _mime_types(string $ext) : string

access | public
static |

### Parameters

#### $ext

`string`

File extension

### Returns

`string`MIME type of ext

## Set (or reset) Class Objects (variables)

    set(string $name, mixed $value) : bool

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

access | public
todo | Should this not be using __set() magic function?

### Parameters

#### $name

`string`

Parameter Name

#### $value

`mixed`

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

### Exceptions

`\phpmailerException` |

### Returns

`bool`

## Adds an address to one of the recipient arrays Addresses that have been added already return false, but do not throw exceptions

    AddAnAddress(string $kind, string $address, string $name) : boolean

access | protected

### Parameters

#### $kind

`string`

One of 'to', 'cc', 'bcc', 'ReplyTo'

#### $address

`string`

The email address to send to

#### $name

`string`

### Exceptions

`\phpmailerException` |

### Returns

`boolean`true on success, false if address already used or invalid in some way

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

    AttachAll(string $disposition_type, string $boundary) : string

Returns an empty string on failure.

access | protected

### Parameters

#### $disposition_type

`string`

#### $boundary

`string`

### Returns

`string`

## Encodes attachment in requested format.

    EncodeFile(string $path, string $encoding) : string

Returns an empty string on failure.

see | \global\EncodeFile()
access | protected

### Parameters

#### $path

`string`

The full path to the file

#### $encoding

`string`

The encoding to use; one of 'base64', '7bit', '8bit', 'binary', 'quoted-printable'

### Exceptions

`\phpmailerException` |

### Returns

`string`

## Returns the end of a message boundary.

    EndBoundary(string $boundary) : string

access | protected

### Parameters

#### $boundary

`string`

### Returns

`string`

## Returns the start of a message boundary.

    GetBoundary(string $boundary, string $charSet, string $contentType, string $encoding) : string

access | protected

### Parameters

#### $boundary

`string`

#### $charSet

`string`

#### $contentType

`string`

#### $encoding

`string`

### Returns

`string`

## Returns a message in the appropriate language.

    Lang(string $key) : string

access | protected

### Parameters

#### $key

`string`

### Returns

`string`

## Sends mail using the PHP mail() function.

    MailSend(string $header, string $body) : bool

access | protected

### Parameters

#### $header

`string`

The message headers

#### $body

`string`

The message body

### Exceptions

`\phpmailerException` |

### Returns

`bool`

## Sends mail using the $Sendmail program.

    SendmailSend(string $header, string $body) : bool

access | protected

### Parameters

#### $header

`string`

The message headers

#### $body

`string`

The message body

### Exceptions

`\phpmailerException` |

### Returns

`bool`

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

    ServerHostname() : string

access | protected

### Returns

`string`

## Adds the error message to the error container.

    SetError(string $msg) : void

access | protected

### Parameters

#### $msg

`string`

## Sets the message type.

    SetMessageType() : void

access | protected

## Sends mail via SMTP using PhpSMTP Returns false if there is a bad MAIL FROM, RCPT, or DATA input.

    SmtpSend(string $header, string $body) : bool

uses | \global\SMTP
access | protected

### Parameters

#### $header

`string`

The message headers

#### $body

`string`

The message body

### Exceptions

`\phpmailerException` |

### Returns

`bool`

## Perform callback

    doCallback(boolean $isSent, string $to, string $cc, string $bcc, string $subject, string $body, string $from)

### Parameters

#### $isSent

`boolean`

#### $to

`string`

#### $cc

`string`

#### $bcc

`string`

#### $subject

`string`

#### $body

`string`

#### $from

`string`

## Outputs debugging info via user-defined method

    edebug(string $str)

### Parameters

#### $str

`string`

## Calls actual mail() function, but in a safe_mode aware fashion Also, unless sendmail_path points to sendmail (or something that claims to be sendmail), don't pass params (not a perfect fix, but it will do)

    mail_passthru(string $to, string $subject, string $body, string $header, string $params) : bool

access | private

### Parameters

#### $to

`string`

To

#### $subject

`string`

Subject

#### $body

`string`

Message Body

#### $header

`string`

Additional Header(s)

#### $params

`string`

Params

### Returns

`bool`

### Properties

## Sets the text-only body of the message.

    $AltBody : string

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.

## Sets SMTP auth type.

    $AuthType : string

Options are LOGIN | PLAIN | NTLM (default LOGIN)

## Sets the Body of the message.

    $Body : string

This can be either an HTML or text body. If HTML then run IsHTML(true).

## Sets the CharSet of the message.

    $CharSet : string

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

    $ConfirmReadingTo : string

## Sets the Content-type of the message.

    $ContentType : string

## Used with DKIM Singing required if DKIM is enabled, in format of email address 'domain.com'

    $DKIM_domain : string

## Used with DKIM Signing required if DKIM is enabled, in format of email address 'you@yourdomain.com' typically used as the source of the email

    $DKIM_identity : string

## Used with DKIM Signing optional parameter if your private key requires a passphras

    $DKIM_passphrase : string

## Used with DKIM Signing required if DKIM is enabled, path to private key file

    $DKIM_private : string

## Used with DKIM Signing required parameter if DKIM is enabled

    $DKIM_selector : string

domain selector example domainkey

## Sets the function/method to use for debugging output.

    $Debugoutput : string

Right now we only honor "echo" or "error_log"

## Sets the Encoding of the message.

    $Encoding : string

Options for this are "8bit", "7bit", "binary", "base64", and "quoted-printable".

## Holds the most recent mailer error message.

    $ErrorInfo : string

## Sets the From email address for the message.

    $From : string

## Sets the From name of the message.

    $FromName : string

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

    $Helo : string

## Sets the SMTP hosts.

    $Host : string

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"). Hosts will be tried in order.

## Sets the hostname to use in Message-Id and Received headers and as default HELO string.

    $Hostname : string

If empty, the value returned by SERVER_NAME is used or 'localhost.localdomain'.

## Provides the ability to change the generic line ending NOTE: The default remains '\n'.

    $LE : string

We force CRLF where we KNOW it must be used via self::CRLF

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

    $Mailer : string

## Sets the message Date to be used in the Date header.

    $MessageDate : string

If empty, the current date will be added.

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

    $MessageID : string

If empty, a unique id will be generated.

## Sets SMTP password.

    $Password : string

## Path to PHPMailer plugins.

    $PluginDir : string

Useful if the SMTP class is in a different directory than the PHP include path.

## Sets the default SMTP server port.

    $Port : int

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

    $Priority : int

## Sets SMTP realm.

    $Realm

@var string

## Sets the Return-Path of the message.

    $ReturnPath : string

If empty, it will be set to either From or Sender.

## Sets SMTP authentication.

    $SMTPAuth : bool

Utilizes the Username and Password variables.

## Sets SMTP class debugging on or off.

    $SMTPDebug : bool

## Prevents the SMTP connection from being closed after each mail sending.

    $SMTPKeepAlive : bool

If this is set to true then to close the connection requires an explicit call to SmtpClose().

## Sets connection prefix.

    $SMTPSecure : string

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

## Sets the Sender email (Return-Path) of the message.

    $Sender : string

If not empty, will be sent via -f to sendmail or as 'MAIL FROM' in smtp mode.

## Sets the path of the sendmail program.

    $Sendmail : string

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

    $SingleTo : bool

## If SingleTo is true, this provides the array to hold the email addresses

    $SingleToArray : bool

## Sets the Subject of the message.

    $Subject : string

## Sets the SMTP server timeout in seconds.

    $Timeout : int

This function will not work with the win32 version.

## Determine if mail() uses a fully sendmail compatible MTA that supports sendmail's "-oi -f" options

    $UseSendmailOptions : boolean

## Sets SMTP username.

    $Username : string

## Sets the PHPMailer Version number

    $Version : string

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

    $WordWrap : int

## Sets SMTP workstation.

    $Workstation

@var string

## What to use in the X-Mailer header

    $XMailer : string

## Callback Action function name.

    $action_function : string

The function that handles the result of the send email action. It is called out by Send() for each email sent.

Value can be: - 'function_name' for function names - 'Class::Method' for static method calls - array($object, 'Method') for calling methods on $object See http://php.net/is_callable manual page for more details.

Parameters: bool $result result of the send action string $to email address of the recipient string $cc cc email addresses string $bcc bcc email addresses string $subject the subject string $body the email body string $from email address of sender

## <p>An array of custom headers</p>

    $CustomHeader : array

access | protected

## Stores the complete compiled MIME message body.

    $MIMEBody : string

access | protected

## Stores the complete compiled MIME message headers.

    $MIMEHeader : string

access | protected

## <p>An array of reply-to name and address</p>

    $ReplyTo : array

access | protected

## <p>An array of all kinds of addresses: to, cc, bcc, replyto</p>

    $all_recipients : array

access | protected

## <p>An array of attachments</p>

    $attachment : array

access | protected

## <p>An array of 'bcc' addresses</p>

    $bcc : array

access | protected

## <p>An array of MIME boundary strings</p>

    $boundary : array

access | protected

## <p>An array of 'cc' addresses</p>

    $cc : array

access | protected

## <p>The number of errors encountered</p>

    $error_count : integer

access | protected

## <p>Whether to throw exceptions for errors</p>

    $exceptions : boolean

access | protected

## <p>An array of available languages</p>

    $language : array

access | protected

## Stores the extra header list which CreateHeader() doesn't fold in

    $mailHeader : string

access | protected

## <p>The message's MIME type</p>

    $message_type : string

access | protected

## <p>The filename of a DKIM certificate file</p>

    $sign_cert_file : string

access | protected

## <p>The filename of a DKIM key file</p>

    $sign_key_file : string

access | protected

## <p>The password of a DKIM key</p>

    $sign_key_pass : string

access | protected

## <p>An instance of the SMTP sender class</p>

    $smtp : \SMTP

access | protected

## <p>An array of 'to' addresses</p>

    $to : array

access | protected

### Constants

## CRLF

    CRLF

## STOP_CONTINUE

    STOP_CONTINUE

## STOP_CRITICAL

    STOP_CRITICAL

## STOP_MESSAGE

    STOP_MESSAGE