PHPMailer - PHP email creation and transport class.

package PHPMailer
author Marcus Bointon (Synchro/coolbru)
author Jim Jagielski (jimjag)
author Andy Prevost (codeworxtech)
author Brent R. Matzelle (original founder)

 Methods

Create the DKIM header and body in a new message 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 a DKIM canonicalization body.

DKIM_BodyC(string $body) : string
access public

Parameters

$body

string

Message Body

Returns

string

Generate a DKIM canonicalization header.

DKIM_HeaderC(string $signHeader) : string
access public

Parameters

$signHeader

string

Header

Returns

string

Quoted-Printable-encode a DKIM header.

DKIM_QP(string $txt) : string
access public

Parameters

$txt

string

Returns

string

Generate a DKIM signature.

DKIM_Sign(string $signHeader) : string
access public

Parameters

$signHeader

string

Exceptions

\phpmailerException

Returns

stringThe DKIM signature value

Constructor.

__construct(boolean $exceptions = null

Parameters

$exceptions

boolean

Should we throw external exceptions?

Destructor.

__destruct() 

Get the MIME type for a file extension.

_mime_types(string $ext = '') : string
Static
access public
static

Parameters

$ext

string

File extension

Returns

stringMIME type of file.

Add a "To" address.

addAddress(string $address, string $name = '') : boolean

Parameters

$address

string

The email address to send to

$name

string

Returns

booleantrue on success, false if address already used or invalid in some way

Add an attachment from a path on the filesystem.

addAttachment(string $path, string $name = '', string $encoding = 'base64', string $type = '', string $disposition = 'attachment') : boolean

Never use a user-supplied path to a file! Returns false if the file could not be found or read. Explicitly does not support passing URLs; PHPMailer is not an HTTP client. If you need to do that, fetch the resource yourself and pass it in via a local file or string.

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.

$disposition

string

Disposition to use

Exceptions

\phpmailerException

Returns

boolean

Add 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

The email address to send to

$name

string

Returns

booleantrue on success, false if address already used or invalid in some way

Add 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

The email address to send to

$name

string

Returns

booleantrue on success, false if address already used or invalid in some way

Add a custom header.

addCustomHeader(string $name, string $value = null) : 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

Add an embedded (inline) attachment from a file.

addEmbeddedImage(string $path, string $cid, string $name = '', string $encoding = 'base64', string $type = '', string $disposition = 'inline') : boolean

This can include images, sounds, and just about any other document type. These differ from 'regular' attachments in that they are intended to be displayed inline with the message, not just attached for download. This is used in HTML messages that embed the images the HTML refers to using the $cid value. Never use a user-supplied path to a file!

Parameters

$path

string

Path to the attachment.

$cid

string

Content ID of the attachment; Use this to reference the content when using an embedded image in HTML.

$name

string

Overrides the attachment name.

$encoding

string

File encoding (see $Encoding).

$type

string

File MIME type.

$disposition

string

Disposition to use

Returns

booleanTrue on successfully adding an attachment

Add a "Reply-To" address.

addReplyTo(string $address, string $name = '') : boolean

Parameters

$address

string

The email address to reply to

$name

string

Returns

booleantrue on success, false if address already used or invalid in some way

Add a string or binary attachment (non-filesystem).

addStringAttachment(string $string, string $filename, string $encoding = 'base64', string $type = '', string $disposition = 'attachment') : 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.

$disposition

string

Disposition to use

Add an embedded stringified attachment.

addStringEmbeddedImage(string $string, string $cid, string $name = '', string $encoding = 'base64', string $type = '', string $disposition = 'inline') : boolean

This can include images, sounds, and just about any other document type. Be sure to set the $type to an image type for images: JPEG images use 'image/jpeg', GIF uses 'image/gif', PNG uses 'image/png'.

Parameters

$string

string

The attachment binary data.

$cid

string

Content ID of the attachment; Use this to reference the content when using an embedded image in HTML.

$name

string

$encoding

string

File encoding (see $Encoding).

$type

string

MIME type.

$disposition

string

Disposition to use

Returns

booleanTrue on successfully adding an attachment

Create recipient headers.

addrAppend(string $type, array $addr) : string
access public

Parameters

$type

string

$addr

array

An array of recipient, where each recipient is a 2-element indexed array with element 0 containing an address and element 1 containing a name, like: array(array('joe@example.com', 'Joe User'), array('zoe@example.com', 'Zoe User'))

Returns

string

Format an address for use in a message header.

addrFormat(array $addr) : string
access public

Parameters

$addr

array

A 2-element indexed array, element 0 containing an address, element 1 containing a name like array('joe@example.com', 'Joe User')

Returns

string

Check if this message has an alternative body set.

alternativeExists() : boolean

Returns

boolean

Check if an attachment (non-inline) is present.

attachmentExists() : boolean

Returns

boolean

Encode and wrap long multibyte strings for mail headers without breaking lines within a character.

base64EncodeWrapMB(string $str, string $linebreak = null) : string

Adapted from a function by paravoid

link http://www.php.net/manual/en/function.mb-encode-mimeheader.php#60283
access public

Parameters

$str

string

multi-byte text to wrap encode

$linebreak

string

string to use as linefeed/end-of-line

Returns

string

Clear all To recipients.

clearAddresses() : void

Clear all recipient types.

clearAllRecipients() : void

Clear all filesystem, string, and binary attachments.

clearAttachments() : void

Clear all BCC recipients.

clearBCCs() : void

Clear all CC recipients.

clearCCs() : void

Clear all custom headers.

clearCustomHeaders() : void

Clear queued addresses of given kind.

clearQueuedAddresses(string $kind) : void
access protected

Parameters

$kind

string

'to', 'cc', or 'bcc'

Clear all ReplyTo recipients.

clearReplyTos() : void

Assemble the message body.

createBody() : string

Returns an empty string on failure.

access public

Exceptions

\phpmailerException

Returns

stringThe assembled message body

Assemble message headers.

createHeader() : string
access public

Returns

stringThe assembled headers

Encode a header string optimally.

encodeHeader(string $str, string $position = 'text') : string

Picks shortest of Q, B, quoted-printable or none.

access public

Parameters

$str

string

$position

string

Returns

string

Encode a string using Q encoding.

encodeQ(string $str, string $position = 'text') : 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 a string in quoted-printable format.

encodeQP(string $string, integer $line_max = 76) : string

According to RFC2045 section 6.7.

access public
link Adapted from this comment

Parameters

$string

string

The text to encode

$line_max

integer

Number of chars allowed on a line before wrapping

Returns

string

Backward compatibility wrapper for an old QP encoding function that was removed.

encodeQPphp(string $string, integer $line_max = 76, boolean $space_conv = false) : string
see
access public
deprecated Use encodeQP instead.

Parameters

$string

string

$line_max

integer

$space_conv

boolean

Returns

string

Encode a string in requested format.

encodeString(string $str, string $encoding = 'base64') : 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

Map a file name to a MIME type.

filenameToType(string $filename) : string
Static

Defaults to 'application/octet-stream', i.e.. arbitrary binary data.

static

Parameters

$filename

string

A file name or full path, does not need to exist as a file

Returns

string

Ensure consistent line endings in a string.

fixEOL(string $str) : string

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

access public

Parameters

$str

string

String to fixEOL

Returns

string

Allows for public read access to 'all_recipients' property.

getAllRecipientAddresses() : array
note : Before the send() call, queued addresses (i.e. with IDN) are not yet included.
access public

Returns

array

Return the array of attachments.

getAttachments() : array

Returns

array

Allows for public read access to 'bcc' property.

getBccAddresses() : array
note : Before the send() call, queued addresses (i.e. with IDN) are not yet included.
access public

Returns

array

Allows for public read access to 'cc' property.

getCcAddresses() : array
note : Before the send() call, queued addresses (i.e. with IDN) are not yet included.
access public

Returns

array

Returns all custom headers.

getCustomHeaders() : array

Returns

array

Return the Message-ID header of the last email.

getLastMessageID() : string

Technically this is the value from the last time the headers were created, but it's also the message ID of the last sent message except in pathological cases.

Returns

string

Get the message MIME type headers.

getMailMIME() : string
access public

Returns

string

Allows for public read access to 'ReplyTo' property.

getReplyToAddresses() : array
note : Before the send() call, queued addresses (i.e. with IDN) are not yet included.
access public

Returns

array

Get an instance to use for SMTP operations.

getSMTPInstance() : \SMTP

Override this function to load your own SMTP implementation

Returns

\SMTP

Returns the whole MIME message.

getSentMIMEMessage() : string

Includes complete headers and body. Only valid post preSend().

see
access public

Returns

string

Allows for public read access to 'to' property.

getToAddresses() : array
note : Before the send() call, queued addresses (i.e. with IDN) are not yet included.
access public

Returns

array

Get the array of strings for the current language.

getTranslations() : array

Returns

array

Does a string contain any 8-bit chars (in any charset)?

has8bitChars(string $text) : boolean

Parameters

$text

string

Returns

boolean

Detect if a string contains a line longer than the maximum line length allowed.

hasLineLongerThanMax(string $str) : boolean
Static
static

Parameters

$str

string

Returns

boolean

Check if a string contains multi-byte characters.

hasMultiBytes(string $str) : boolean
access public

Parameters

$str

string

multi-byte text to wrap encode

Returns

boolean

Format a header line.

headerLine(string $name, string $value) : string
access public

Parameters

$name

string

$value

string

Returns

string

Convert an HTML string into plain text.

html2text(string $html, boolean|callable $advanced = false) : string

This is used by msgHTML(). Note - older versions of this function used a bundled advanced converter which was been removed for license reasons in #232. Example usage: // Use default conversion $plain = $mail->html2text($html); // Use your own custom converter $plain = $mail->html2text($html, function($html) { $converter = new MyHtml2text($html); return $converter->get_text(); });

Parameters

$html

string

The HTML text to convert

$advanced

booleancallable

Any boolean value to use the internal converter, or provide your own callable for custom conversion.

Returns

string

Tells whether IDNs (Internationalized Domain Names) are supported or not. This requires the "intl" and "mbstring" PHP extensions.

idnSupported() : boolean

Returns

boolean"true" if required functions for IDN support are present

Check if an inline attachment is present.

inlineImageExists() : boolean
access public

Returns

boolean

Check if an error occurred.

isError() : boolean
access public

Returns

booleanTrue if an error did occur.

Sets message type to HTML or plain.

isHTML(boolean $isHtml = true) : void

Parameters

$isHtml

boolean

True for HTML mode.

Send messages using PHP's mail() function.

isMail() : void

Send messages using qmail.

isQmail() : void

Send messages using SMTP.

isSMTP() : void

Send messages using $Sendmail.

isSendmail() : void

Multi-byte-safe pathinfo replacement.

mb_pathinfo(string $path, integer|string $options = null) : string | array
Static

Drop-in replacement for pathinfo(), but multibyte-safe, cross-platform-safe, old-version-safe. Works similarly to the one in PHP >= 5.2.0

link http://www.php.net/manual/en/function.pathinfo.php#107461
static

Parameters

$path

string

A filename or path, does not need to exist as a file

$options

integerstring

Either a PATHINFO_* constant, or a string name to return only the specified piece, allows 'filename' to work on PHP < 5.2

Returns

stringarray

Create a message body from an HTML string.

msgHTML(string $message, string $basedir = '', boolean|callable $advanced = false) : string

Automatically inlines images and creates a plain-text version by converting the HTML, overwriting any existing values in Body and AltBody. Do not source $message content from user input! $basedir is prepended when handling relative URLs, e.g. and must not be empty will look for an image file in $basedir/images/a.png and convert it to inline. If you don't provide a $basedir, relative paths will be left untouched (and thus probably break in email) If you don't want to apply these transformations to your HTML, just set Body and AltBody directly.

access public

Parameters

$message

string

HTML message string

$basedir

string

Absolute path to a base directory to prepend to relative paths to images

$advanced

booleancallable

Whether to use the internal HTML to text converter or your own custom converter @see PHPMailer::html2text()

Returns

string$message The transformed message Body

Normalize line breaks in a string.

normalizeBreaks(string $text, string $breaktype = "\r\n") : string
Static

Converts UNIX LF, Mac CR and Windows CRLF line breaks into a single line break format. Defaults to CRLF (for message bodies) and preserves consecutive breaks.

access public
static

Parameters

$text

string

$breaktype

string

What kind of line break to use, defaults to CRLF

Returns

string

Parse and validate a string containing one or more RFC822-style comma-separated email addresses of the form "display name <address>" into an array of name/address pairs.

parseAddresses(string $addrstr, boolean $useimap = true) : array

Uses the imap_rfc822_parse_adrlist function if the IMAP extension is available. Note that quotes in the name part are removed.

link A more careful implementation

Parameters

$addrstr

string

The address list string

$useimap

boolean

Whether to use the IMAP extension to parse the list

Returns

array

Actually send a message.

postSend() : boolean

Send the email via the selected mechanism

Exceptions

\phpmailerException

Returns

boolean

Prepare a message for sending.

preSend() : boolean

Exceptions

\phpmailerException

Returns

boolean

Converts IDN in given email address to its ASCII form, also known as punycode, if possible.

punyencodeAddress(string $address) : string

Important: Address must be passed in same encoding as currently set in PHPMailer::$CharSet. This function silently returns unmodified address if:

  • No conversion is necessary (i.e. domain name is not an IDN, or is already in ASCII form)
  • Conversion to punycode is impossible (e.g. required PHP functions are not available) or fails for any reason (e.g. domain has characters not allowed in an IDN)
see

Parameters

$address

string

The email address to convert

Returns

stringThe encoded address in ASCII form

Return an RFC 822 formatted date.

rfcDate() : string
Static
access public
static

Returns

string

Strip newlines to prevent header injection.

secureHeader(string $str) : string
access public

Parameters

$str

string

Returns

string

Create a message and send it.

send() : boolean

Uses the sending method specified by $Mailer.

Exceptions

\phpmailerException

Returns

booleanfalse on error - See the ErrorInfo property for details of the error.

Set or reset instance properties.

set(string $name, mixed $value = '') : boolean

You should avoid this function - it's more verbose, less efficient, more error-prone and harder to debug than setting properties directly. Usage Example: $mail->set('SMTPSecure', 'tls'); is the same as: $mail->SMTPSecure = 'tls';

access public
TODO Should this not be using the __set() magic function?

Parameters

$name

string

The property name to set

$value

mixed

The value to set the property to

Returns

boolean

Set the From and FromName properties.

setFrom(string $address, string $name = '', boolean $auto = true) : boolean

Parameters

$address

string

$name

string

$auto

boolean

Whether to also set the Sender address, defaults to true

Exceptions

\phpmailerException

Returns

boolean

Set the language for error messages.

setLanguage(string $langcode = 'en', string $lang_path = '') : boolean

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. French is "fr")

$lang_path

string

Path to the language file directory, with trailing separator (slash)

Returns

boolean

Apply word wrapping to the message body.

setWordWrap() : void

Wraps the message body to the number of chars set in the WordWrap property. You should only do this to plain-text bodies as wrapping HTML tags may break them. This is called automatically by createBody(), so you don't need to call it yourself.

access public

Set the public and private key files and password for S/MIME signing.

sign(string $cert_filename, string $key_filename, string $key_pass, string $extracerts_filename = ''
access public

Parameters

$cert_filename

string

$key_filename

string

$key_pass

string

Password for private key

$extracerts_filename

string

Optional path to chain certificate

Close the active SMTP session if one exists.

smtpClose() : void

Initiate a connection to an SMTP server.

smtpConnect(array $options = null) : boolean

Returns false if the operation failed.

uses
access public

Parameters

$options

array

An array of options compatible with stream_context_create()

Exceptions

\phpmailerException

Returns

boolean

Return a formatted mail line.

textLine(string $value) : string
access public

Parameters

$value

string

Returns

string

Find the 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 public

Parameters

$encodedText

string

utf-8 QP text

$maxLength

integer

Find the last character boundary prior to this length

Returns

integer

Check that a string looks like an email address.

validateAddress(string $address, string|callable $patternselect = null) : boolean
Static
static
access public

Parameters

$address

string

The email address to check

$patternselect

stringcallable

A selector for the validation pattern to use :

  • auto Pick best pattern automatically;
  • pcre8 Use the squiloople.com pattern, requires PCRE > 8.0, PHP >= 5.3.2, 5.2.14;
  • pcre Use old PCRE implementation;
  • php Use PHP built-in FILTER_VALIDATE_EMAIL;
  • html5 Use the pattern given by the HTML5 spec for 'email' type form input elements.
  • noregex Don't use a regex: super fast, really dumb. Alternatively you may pass in a callable to inject your own validator, for example: PHPMailer::validateAddress('user@example.com', function($address) { return (strpos($address, '@') !== false); }); You can also set the PHPMailer::$validator static to a callable, allowing built-in methods to use your validator.

Returns

boolean

Word-wrap message.

wrapText(string $message, integer $length, boolean $qp_mode = false) : string

For use with mailers that do not automatically perform wrapping and for quoted-printable encoded messages. 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

Add an address to one of the recipient arrays or to the ReplyTo array.

addAnAddress(string $kind, string $address, string $name = '') : boolean

Addresses that have been added already return false, but do not throw exceptions.

access protected

Parameters

$kind

string

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

$address

string

The email address to send, resp. to reply to

$name

string

Exceptions

\phpmailerException

Returns

booleantrue on success, false if address already used or invalid in some way

Add an address to one of the recipient arrays or to the ReplyTo array. Because PHPMailer can't validate addresses with an IDN without knowing the PHPMailer::$CharSet (that can still be modified after calling this function), addition of such addresses is delayed until send().

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

Addresses that have been added already return false, but do not throw exceptions.

access protected

Parameters

$kind

string

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

$address

string

The email address to send, resp. to reply to

$name

string

Exceptions

\phpmailerException

Returns

booleantrue on success, false if address already used or invalid in some way

Attach all file, 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

Perform a callback.

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

Parameters

$isSent

boolean

$to

array

$cc

array

$bcc

array

$subject

string

$body

string

$from

string

Output debugging info via user-defined method.

edebug(string $str) 

Only generates output if SMTP debug output is enabled (@see SMTP::$do_debug).

see
see

Parameters

$str

string

Encode a file attachment in requested format.

encodeFile(string $path, string $encoding = 'base64') : string

Returns an empty string on failure.

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

Return the end of a message boundary.

endBoundary(string $boundary) : string
access protected

Parameters

$boundary

string

Returns

string

Create unique ID

generateId() : string

Returns

string

Return 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

Check whether a file path is of a permitted type.

isPermittedPath(string $path) : boolean
Static

Used to reject URLs and phar files from functions that access local file paths, such as addAttachment.

Parameters

$path

string

A relative or absolute path to a file.

Returns

boolean

Fix CVE-2016-10033 and CVE-2016-10045 by disallowing potentially unsafe shell characters.

isShellSafe(string $string) : boolean
Static

Note that escapeshellarg and escapeshellcmd are inadequate for our purposes, especially on Windows.

see CVE-2016-10045 bug report
access protected

Parameters

$string

string

The string to be validated

Returns

boolean

Get an error message in the current language.

lang(string $key) : string
access protected

Parameters

$key

string

Returns

string

Send mail using the PHP mail() function.

mailSend(string $header, string $body) : boolean
link http://www.php.net/manual/en/book.mail.php
access protected

Parameters

$header

string

The message headers

$body

string

The message body

Exceptions

\phpmailerException

Returns

boolean

Send mail using the $Sendmail program.

sendmailSend(string $header, string $body) : boolean
see
access protected

Parameters

$header

string

The message headers

$body

string

The message body

Exceptions

\phpmailerException

Returns

boolean

Get the server hostname.

serverHostname() : string

Returns 'localhost.localdomain' if unknown.

access protected

Returns

string

Add an error message to the error container.

setError(string $msg) : void
access protected

Parameters

$msg

string

Set the message type.

setMessageType() : void

PHPMailer only supports some preset message types, not arbitrary MIME structures.

access protected

Send mail via SMTP.

smtpSend(string $header, string $body) : boolean

Returns false if there is a bad MAIL FROM, RCPT, or DATA input. Uses the PHPMailerSMTP class by default.

see to use a different class.
uses
access protected

Parameters

$header

string

The message headers

$body

string

The message body

Exceptions

\phpmailerException

Returns

boolean

Call mail() in a safe_mode-aware fashion.

mailPassthru(string $to, string $subject, string $body, string $header, string $params) : boolean

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)

access private

Parameters

$to

string

To

$subject

string

Subject

$body

string

Message Body

$header

string

Additional Header(s)

$params

string

Params

Returns

boolean

 Properties

 

Whether to allow sending messages with an empty body.

$AllowEmpty : boolean

Default

false
 

The plain-text message body.

$AltBody : string

Default

''

This body can be read by mail clients that do not have HTML email capability such as mutt & Eudora. Clients that can read HTML will view the normal Body.

 

SMTP auth type.

$AuthType : string

Default

''

Options are CRAM-MD5, LOGIN, PLAIN, attempted in that order if not specified

 

An HTML or plain text message body.

$Body : string

Default

''

If HTML then call isHTML(true).

 

The character set of the message.

$CharSet : string

Default

'iso-8859-1'
 

The email address that a reading confirmation should be sent to, also known as read receipt.

$ConfirmReadingTo : string

Default

''
 

The MIME Content-type of the message.

$ContentType : string

Default

'text/plain'
 

DKIM signing domain name.

$DKIM_domain : string

Default

''
example

Examples


 

DKIM Identity.

$DKIM_identity : string

Default

''

Usually the email address used as the source of the email.

 

DKIM passphrase.

$DKIM_passphrase : string

Default

''

Used if your key is encrypted.

 

DKIM private key file path.

$DKIM_private : string

Default

''
 

DKIM private key string.

$DKIM_private_string : string

Default

''

If set, takes precedence over $DKIM_private.

 

DKIM selector.

$DKIM_selector : string

Default

''
 

How to handle debug output.

$Debugoutput : string | callable

Default

'echo'

Options:

  • echo Output plain-text as-is, appropriate for CLI
  • html Output escaped, line breaks converted to <br>, appropriate for browser output
  • error_log Output to error log as configured in php.ini

Alternatively, you can provide a callable expecting two params: a message string and the debug level: $mail->Debugoutput = function($str, $level) {echo "debug level $level; message: $str";};

see
 

The message encoding.

$Encoding : string

Default

'8bit'

Options: "8bit", "7bit", "binary", "base64", and "quoted-printable".

 

Holds the most recent mailer error message.

$ErrorInfo : string

Default

''
 

The From email address for the message.

$From : string

Default

'root@localhost'
 

The From name of the message.

$FromName : string

Default

'Root User'
 

The SMTP HELO of the message.

$Helo : string

Default

''

Default is $Hostname. If $Hostname is empty, PHPMailer attempts to find one with the same method described above for $Hostname.

see
 

SMTP hosts.

$Host : string

Default

'localhost'

Either a single hostname or multiple semicolon-delimited hostnames. 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"). You can also specify encryption type, for example: (e.g. "tls://smtp1.example.com:587;ssl://smtp2.example.com:465"). Hosts will be tried in order.

 

The hostname to use in the Message-ID header and as default HELO string.

$Hostname : string

Default

''

If empty, PHPMailer attempts to find one with, in order, $_SERVER['SERVER_NAME'], gethostname(), php_uname('n'), or the value 'localhost.localdomain'.

 

An iCal message part body.

$Ical : string

Default

''

Only supported in simple alt or alt_inline message types To generate iCal events, use the bundled extras/EasyPeasyICS.php class or iCalcreator

link http://sprain.ch/blog/downloads/php-class-easypeasyics-create-ical-files-with-php/
link http://kigkonsult.se/iCalcreator/
 

The default line ending.

$LE : string

Default

"\n"
note The default remains "\n". We force CRLF where we know it must be used via self::CRLF.
 

Which method to use to send mail.

$Mailer : string

Default

'mail'

Options: "mail", "sendmail", or "smtp".

 

The message Date to be used in the Date header.

$MessageDate : string

Default

''

If empty, the current date will be added.

 

An ID to be used in the Message-ID header.

$MessageID : string

Default

''

If empty, a unique id will be generated. You can set your own, but it must be in the format "id@domain", as defined in RFC5322 section 3.6.4 or it will be ignored.

see
 

SMTP password.

$Password : string

Default

''
 

Path to PHPMailer plugins.

$PluginDir : string

Default

''

Useful if the SMTP class is not in the PHP include path.

deprecated Should not be needed now there is an autoloader.
 

The default SMTP server port.

$Port : integer

Default

25
TODO Why is this needed when the SMTP class takes care of it?
 

Email priority.

$Priority : integer

Default

null

Options: null (default), 1 = High, 3 = Normal, 5 = low. When null, the header is not set at all.

 

SMTP realm.

$Realm : string

Default

''

Used for NTLM auth

 

The Return-Path of the message.

$ReturnPath : string

Default

''

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

deprecated Email senders should never set a return-path header; it's the receiver's job (RFC5321 section 4.4), so this no longer does anything.
link RFC5321 reference
 

Whether to use SMTP authentication.

$SMTPAuth : boolean

Default

false

Uses the Username and Password properties.

see
see
 

Whether to enable TLS encryption automatically if a server supports it, even if `SMTPSecure` is not set to 'tls'.

$SMTPAutoTLS : boolean

Default

true

Be aware that in PHP >= 5.6 this requires that the server's certificates are valid.

 

SMTP class debug output mode.

$SMTPDebug : integer

Default

0

Debug output level. Options:

  • 0 No output
  • 1 Commands
  • 2 Data and commands
  • 3 As 2 plus connection status
  • 4 Low-level data output
see
 

Whether to keep SMTP connection open after each message.

$SMTPKeepAlive : boolean

Default

false

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

 

Options array passed to stream_context_create when connecting via SMTP.

$SMTPOptions : array

Default

array()
 

What kind of encryption to use on the SMTP connection.

$SMTPSecure : string

Default

''

Options: '', 'ssl' or 'tls'

 

The Sender email (Return-Path) of the message.

$Sender : string

Default

''

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

 

The path to the sendmail program.

$Sendmail : string

Default

'/usr/sbin/sendmail'
 

Whether to split multiple to addresses into multiple messages or send them all in one message.

$SingleTo : boolean

Default

false

Only supported in mail and sendmail transports, not in SMTP.

 

Storage for addresses when SingleTo is enabled.

$SingleToArray : array

Default

array()
TODO This should really not be public
 

The Subject of the message.

$Subject : string

Default

''
 

The SMTP server timeout in seconds.

$Timeout : integer

Default

300

Default of 5 minutes (300sec) is from RFC2821 section 4.5.3.2

 

Whether mail() uses a fully sendmail-compatible MTA.

$UseSendmailOptions : boolean

Default

true

One which supports sendmail's "-oi -f" options.

 

SMTP username.

$Username : string

Default

''
 

The PHPMailer Version number.

$Version : string

Default

'5.2.27'
 

Word-wrap the message body to this number of chars.

$WordWrap : integer

Default

0

Set to 0 to not wrap. A useful value here is 78, for RFC2822 section 2.1.1 compliance.

 

SMTP workstation.

$Workstation : string

Default

''

Used for NTLM auth

 

What to put in the X-Mailer header.

$XMailer : string

Default

''

Options: An empty string for PHPMailer default, whitespace for none, or a string to use

 

Callback Action function name.

$action_function : string

Default

''

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

Value can be any php callable: http://www.php.net/is_callable

Parameters: boolean $result result of the send action array $to email addresses of the recipients array $cc cc email addresses array $bcc bcc email addresses string $subject the subject string $body the email body string $from email address of sender

 

Whether to generate VERP addresses on send.

$do_verp : boolean

Default

false

Only applicable when sending via SMTP.

link https://en.wikipedia.org/wiki/Variable_envelope_return_path
link Postfix VERP info
 

Which validator to use by default when validating email addresses.

$validator : string | callable

Default

'auto'
Static

May be a callable to inject your own validator, but there are several built-in validators.

see
static
 

The array of custom headers.

$CustomHeader : array

Default

array()
access protected
 

The complete compiled MIME message body.

$MIMEBody : string

Default

''
access protected
 

The complete compiled MIME message headers.

$MIMEHeader : string

Default

''
access protected
 

An array of names and addresses queued for validation.

$RecipientsQueue : array

Default

array()

In send(), valid and non duplicate entries are moved to $all_recipients and one of $to, $cc, or $bcc. This array is used only for addresses with IDN.

access protected
see @see PHPMailer::$cc @see PHPMailer::$bcc
see
 

The array of reply-to names and addresses.

$ReplyTo : array

Default

array()
access protected
 

An array of reply-to names and addresses queued for validation.

$ReplyToQueue : array

Default

array()

In send(), valid and non duplicate entries are moved to $ReplyTo. This array is used only for addresses with IDN.

access protected
see
 

An array of all kinds of addresses.

$all_recipients : array

Default

array()

Includes all of $to, $cc, $bcc

access protected
see @see PHPMailer::$cc @see PHPMailer::$bcc
 

The array of attachments.

$attachment : array

Default

array()
access protected
 

The array of 'bcc' names and addresses.

$bcc : array

Default

array()
access protected
 

The array of MIME boundary strings.

$boundary : array

Default

array()
access protected
 

The array of 'cc' names and addresses.

$cc : array

Default

array()
access protected
 

The number of errors encountered.

$error_count : integer

Default

0
access protected
 

Whether to throw exceptions for errors.

$exceptions : boolean

Default

false
access protected
 

The array of available languages.

$language : array

Default

array()
access protected
 

The most recent Message-ID (including angular brackets).

$lastMessageID : string

Default

''
access protected
 

Extra headers that createHeader() doesn't fold in.

$mailHeader : string

Default

''
access protected
 

The message's MIME type.

$message_type : string

Default

''
access protected
 

The S/MIME certificate file path.

$sign_cert_file : string

Default

''
access protected
 

The optional S/MIME extra certificates ("CA Chain") file path.

$sign_extracerts_file : string

Default

''
access protected
 

The S/MIME key file path.

$sign_key_file : string

Default

''
access protected
 

The S/MIME password for the key.

$sign_key_pass : string

Default

''

Used only if the key is encrypted.

access protected
 

An instance of the SMTP sender class.

$smtp : \SMTP

Default

null
access protected
 

The array of 'to' names and addresses.

$to : array

Default

array()
access protected
 

Unique ID used for message ID and boundaries.

$uniqueid : string

Default

''
access protected

 Constants

 

SMTP RFC standard line ending.

CRLF = "\r\n" 
 

The maximum line length allowed by RFC 2822 section 2.1.1

MAX_LINE_LENGTH = 998 : integer
 

Error severity: message, likely ok to continue processing.

STOP_CONTINUE = 1 
 

Error severity: message, plus full stop, critical error reached.

STOP_CRITICAL = 2 
 

Error severity: message only, continue processing.

STOP_MESSAGE = 0