Copied!
Cloneable Instantiable
Constants
public PHPMailer\PHPMailer\PHPMailer ::CHARSET_ASCII = 'us-ascii'
public PHPMailer\PHPMailer\PHPMailer ::CHARSET_ISO88591 = 'iso-8859-1'
public PHPMailer\PHPMailer\PHPMailer ::CHARSET_UTF8 = 'utf-8'
public PHPMailer\PHPMailer\PHPMailer ::CONTENT_TYPE_MULTIPART_ALTERNATIVE = 'multipart/alternative'
public PHPMailer\PHPMailer\PHPMailer ::CONTENT_TYPE_MULTIPART_MIXED = 'multipart/mixed'
public PHPMailer\PHPMailer\PHPMailer ::CONTENT_TYPE_MULTIPART_RELATED = 'multipart/related'
public PHPMailer\PHPMailer\PHPMailer ::CONTENT_TYPE_PLAINTEXT = 'text/plain'
public PHPMailer\PHPMailer\PHPMailer ::CONTENT_TYPE_TEXT_CALENDAR = 'text/calendar'
public PHPMailer\PHPMailer\PHPMailer ::CONTENT_TYPE_TEXT_HTML = 'text/html'
public PHPMailer\PHPMailer\PHPMailer ::CRLF = ' '
 

The SMTP standard CRLF line break.

If you want to change line break format, change static::$LE, not this.

public PHPMailer\PHPMailer\PHPMailer ::ENCODING_7BIT = '7bit'
public PHPMailer\PHPMailer\PHPMailer ::ENCODING_8BIT = '8bit'
public PHPMailer\PHPMailer\PHPMailer ::ENCODING_BASE64 = 'base64'
public PHPMailer\PHPMailer\PHPMailer ::ENCODING_BINARY = 'binary'
public PHPMailer\PHPMailer\PHPMailer ::ENCODING_QUOTED_PRINTABLE = 'quoted-printable'
public PHPMailer\PHPMailer\PHPMailer ::ENCRYPTION_SMTPS = 'ssl'
public PHPMailer\PHPMailer\PHPMailer ::ENCRYPTION_STARTTLS = 'tls'
public PHPMailer\PHPMailer\PHPMailer ::FWS = ' '
 

"Folding White Space" a white space string used for line folding.

public PHPMailer\PHPMailer\PHPMailer ::ICAL_METHOD_ADD = 'ADD'
public PHPMailer\PHPMailer\PHPMailer ::ICAL_METHOD_CANCEL = 'CANCEL'
public PHPMailer\PHPMailer\PHPMailer ::ICAL_METHOD_COUNTER = 'COUNTER'
public PHPMailer\PHPMailer\PHPMailer ::ICAL_METHOD_DECLINECOUNTER = 'DECLINECOUNTER'
public PHPMailer\PHPMailer\PHPMailer ::ICAL_METHOD_PUBLISH = 'PUBLISH'
public PHPMailer\PHPMailer\PHPMailer ::ICAL_METHOD_REFRESH = 'REFRESH'
public PHPMailer\PHPMailer\PHPMailer ::ICAL_METHOD_REPLY = 'REPLY'
public PHPMailer\PHPMailer\PHPMailer ::ICAL_METHOD_REQUEST = 'REQUEST'
public PHPMailer\PHPMailer\PHPMailer ::MAIL_MAX_LINE_LENGTH = 63
 

The maximum line length supported by mail().

Background: mail() will sometimes corrupt messages
with headers headers longer than 65 chars, see #818.

  • var int
public PHPMailer\PHPMailer\PHPMailer ::MAX_LINE_LENGTH = 998
 

The maximum line length allowed by RFC 2822 section 2.1.1.

  • var int
public PHPMailer\PHPMailer\PHPMailer ::STD_LINE_LENGTH = 76
 

The lower maximum line length allowed by RFC 2822 section 2.1.1.

This length does NOT include the line break
76 means that lines will be 77 or 78 chars depending on whether
the line break format is LF or CRLF; both are valid.

  • var int
public PHPMailer\PHPMailer\PHPMailer ::STOP_CONTINUE = 1
 

Error severity: message, likely ok to continue processing.

  • var int
public PHPMailer\PHPMailer\PHPMailer ::STOP_CRITICAL = 2
 

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

  • var int
public PHPMailer\PHPMailer\PHPMailer ::STOP_MESSAGE = 0
 

Error severity: message only, continue processing.

  • var int
public PHPMailer\PHPMailer\PHPMailer ::VERSION = '6.6.3'
 

The PHPMailer Version number.

  • var string
Properties
public $action_function
 

Callback Action function name.

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:
bool $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
string $extra extra information of possible use

                     "smtp_transaction_id' => last smtp transaction id
  • var string
public $AllowEmpty
 

Whether to allow sending messages with an empty body.

  • var bool
public $AltBody
 

The plain-text message body.

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.

  • var string
public $AuthType
 

SMTP auth type.

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

  • var string
public $Body
 

An HTML or plain text message body.

If HTML then call isHTML(true).

  • var string
public $CharSet
 

The character set of the message.

  • var string
public $ConfirmReadingTo
 

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

  • var string
public $ContentType
 

The MIME Content-type of the message.

  • var string
public $Debugoutput
 

How to handle debug output.

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
    By default PHPMailer will use echo if run from a cli or cli-server SAPI, html otherwise.
    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";};

Alternatively, you can pass in an instance of a PSR-3 compatible logger, though only debug
level output is used:

$mail->Debugoutput = new myPsr3Logger;
  • see \SMTP::$Debugoutput
  • var string | callable | Psr\Log\LoggerInterface
public $DKIM_copyHeaderFields
 

DKIM Copy header field values for diagnostic use.

  • var bool
public $DKIM_domain
 

DKIM signing domain name.

  • example 'example.com'
  • var string
public $DKIM_extraHeaders
 

DKIM Extra signing headers.

  • example ['List-Unsubscribe', 'List-Help']
  • var array
public $DKIM_identity
 

DKIM Identity.

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

  • var string
public $DKIM_passphrase
 

DKIM passphrase.

Used if your key is encrypted.

  • var string
public $DKIM_private
 

DKIM private key file path.

  • var string
public $DKIM_private_string
 

DKIM private key string.

If set, takes precedence over $DKIM_private.

  • var string
public $DKIM_selector
 

DKIM selector.

  • var string
public $do_verp
 

Whether to generate VERP addresses on send.

Only applicable when sending via SMTP.

  • see https://en.wikipedia.org/wiki/Variable_envelope_return_path
  • see http://www.postfix.org/VERP_README.htmlPostfix VERP info
  • var bool
public $dsn
 

Comma separated list of DSN notifications
'NEVER' under no circumstances a DSN must be returned to the sender.

If you use NEVER all other notifications will be ignored.
'SUCCESS' will notify you when your mail has arrived at its destination.
'FAILURE' will arrive if an error occurred during delivery.
'DELAY' will notify you if there is an unusual delay in delivery, but the actual

      delivery's outcome (success or failure) is not yet decided.
  • see https://tools.ietf.org/html/rfc3461See section 4.1 for more information about NOTIFY
public $Encoding
 

The message encoding.

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

  • var string
public $ErrorInfo
 

Holds the most recent mailer error message.

  • var string
public $From
 

The From email address for the message.

  • var string
public $FromName
 

The From name of the message.

  • var string
public $Helo
 

The SMTP HELO/EHLO name used for the SMTP connection.

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

  • see \PHPMailer::$Hostname
  • var string
public $Host
 

SMTP hosts.

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.

  • var string
public $Hostname
 

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

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

  • see \PHPMailer::$Helo
  • var string
public $Ical
 

An iCal message part body.

Only supported in simple alt or alt_inline message types
To generate iCal event structures, use classes like EasyPeasyICS or iCalcreator.

  • see http://sprain.ch/blog/downloads/php-class-easypeasyics-create-ical-files-with-php/
  • see http://kigkonsult.se/iCalcreator/
  • var string
public $Mailer
 

Which method to use to send mail.

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

  • var string
public $MessageDate
 

The message Date to be used in the Date header.

If empty, the current date will be added.

  • var string
public $MessageID
 

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

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 https://tools.ietf.org/html/rfc5322#section-3.6.4
  • var string
public $Password
 

SMTP password.

  • var string
public $Port
 

The default SMTP server port.

  • var int
public $Priority
 

Email priority.

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

  • var int | null
public $Sender
 

The envelope sender of the message.

This will usually be turned into a Return-Path header by the receiver,
and is the address that bounces will be sent to.
If not empty, will be passed via -f to sendmail or as the 'MAIL FROM' value over SMTP.

  • var string
public $Sendmail
 

The path to the sendmail program.

  • var string
public $SingleTo
 

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

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

  • var bool
  • deprecated 6.0.0PHPMailer isn't a mailing list manager!
public $SMTPAuth
 

Whether to use SMTP authentication.

Uses the Username and Password properties.

  • see \PHPMailer::$Username
  • see \PHPMailer::$Password
  • var bool
public $SMTPAutoTLS
 

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

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

  • var bool
public $SMTPDebug
 

SMTP class debug output mode.

Debug output level.
Options:

  • see
  • see
  • see
  • see
  • see
  • see \SMTP::$do_debug
  • var int
public $SMTPKeepAlive
 

Whether to keep the SMTP connection open after each message.

If this is set to true then the connection will remain open after a send,
and closing the connection will require an explicit call to smtpClose().
It's a good idea to use this if you are sending multiple messages as it reduces overhead.
See the mailing list example for how to use it.

  • var bool
public $SMTPOptions
 

Options array passed to stream_context_create when connecting via SMTP.

  • var array
public $SMTPSecure
 

What kind of encryption to use on the SMTP connection.

Options: '', static::ENCRYPTION_STARTTLS, or static::ENCRYPTION_SMTPS.

  • var string
public $Subject
 

The Subject of the message.

  • var string
public $Timeout
 

The SMTP server timeout in seconds.

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

  • var int
public $Username
 

SMTP username.

  • var string
public $UseSendmailOptions
 

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

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

  • var bool
public static $validator = 'php'
 

Which validator to use by default when validating email addresses.

May be a callable to inject your own validator, but there are several built-in validators.
The default validator uses PHP's FILTER_VALIDATE_EMAIL filter_var option.

  • see \PHPMailer::validateAddress()
  • var string | callable
public $WordWrap
 

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

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

  • see \static::STD_LINE_LENGTH
  • var int
public $XMailer
 

What to put in the X-Mailer header.

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

  • var string | null
Methods
public __construct ( $exceptions = NULL )
 

Constructor.

  • param bool $exceptions Should we throw external exceptions?
public __destruct ()
 

Destructor.

public static _mime_types ( $ext = '' )
 

Get the MIME type for a file extension.

  • param string $ext File extension
  • return string MIME type of file
public addAddress ( $address , $name = '' )
 

Add a "To" address.

  • param string $address The email address to send to
  • param string $name
  • throws PHPMailer\PHPMailer\Exception
  • return bool true on success, false if address already used or invalid in some way
public addAttachment ( $path , $name = '' , $encoding = 'base64' self::ENCODING_BASE64, $type = '' , $disposition = 'attachment' )
 

Add an attachment from a path on the filesystem.

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.

  • param string $path Path to the attachment
  • param string $name Overrides the attachment name
  • param string $encoding File encoding (see $Encoding)
  • param string $type MIME type, e.g. image/jpeg; determined automatically from $path if not specified
  • param string $disposition Disposition to use
  • throws PHPMailer\PHPMailer\Exception
  • return bool
public addBCC ( $address , $name = '' )
 

Add a "BCC" address.

  • param string $address The email address to send to
  • param string $name
  • throws PHPMailer\PHPMailer\Exception
  • return bool true on success, false if address already used or invalid in some way
public addCC ( $address , $name = '' )
 

Add a "CC" address.

  • param string $address The email address to send to
  • param string $name
  • throws PHPMailer\PHPMailer\Exception
  • return bool true on success, false if address already used or invalid in some way
public addCustomHeader ( $name , $value = NULL )
 

Add a custom header.

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

public addEmbeddedImage ( $path , $cid , $name = '' , $encoding = 'base64' self::ENCODING_BASE64, $type = '' , $disposition = 'inline' )
 

Add an embedded (inline) attachment from a file.

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 in img tags, for example <img src="cid:mylogo">.
Never use a user-supplied path to a file!

  • param string $path Path to the attachment
  • param string $cid Content ID of the attachment; Use this to reference
    the content when using an embedded image in HTML
  • param string $name Overrides the attachment filename
  • param string $encoding File encoding (see $Encoding) defaults to base64
  • param string $type File MIME type (by default mapped from the $path filename's extension)
  • param string $disposition Disposition to use: inline (default) or attachment
    (unlikely you want this – {@see addAttachment()} instead)
  • return bool True on successfully adding an attachment
  • throws PHPMailer\PHPMailer\Exception
public addrAppend ( $type , $addr )
 

Create recipient headers.

  • param string $type
  • param array $addr An array of recipients,
    where each recipient is a 2-element indexed array with element 0 containing an address
    and element 1 containing a name, like:
    [['joe@example.com', 'Joe User'], ['zoe@example.com', 'Zoe User']]
  • return string
public addReplyTo ( $address , $name = '' )
 

Add a "Reply-To" address.

  • param string $address The email address to reply to
  • param string $name
  • throws PHPMailer\PHPMailer\Exception
  • return bool true on success, false if address already used or invalid in some way
public addrFormat ( $addr )
 

Format an address for use in a message header.

  • param array $addr A 2-element indexed array, element 0 containing an address, element 1 containing a name like
    ['joe@example.com', 'Joe User']
  • return string
public addStringAttachment ( $string , $filename , $encoding = 'base64' self::ENCODING_BASE64, $type = '' , $disposition = 'attachment' )
 

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

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

  • param string $string String attachment data
  • param string $filename Name of the attachment
  • param string $encoding File encoding (see $Encoding)
  • param string $type File extension (MIME) type
  • param string $disposition Disposition to use
  • throws PHPMailer\PHPMailer\Exception
  • return bool True on successfully adding an attachment
public addStringEmbeddedImage ( $string , $cid , $name = '' , $encoding = 'base64' self::ENCODING_BASE64, $type = '' , $disposition = 'inline' )
 

Add an embedded stringified attachment.

This can include images, sounds, and just about any other document type.
If your filename doesn't contain an extension, be sure to set the $type to an appropriate MIME type.

  • param string $string The attachment binary data
  • param string $cid Content ID of the attachment; Use this to reference
    the content when using an embedded image in HTML
  • param string $name A filename for the attachment. If this contains an extension,
    PHPMailer will attempt to set a MIME type for the attachment.
    For example 'file.jpg' would get an 'image/jpeg' MIME type.
  • param string $encoding File encoding (see $Encoding), defaults to 'base64'
  • param string $type MIME type - will be used in preference to any automatically derived type
  • param string $disposition Disposition to use
  • throws PHPMailer\PHPMailer\Exception
  • return bool True on successfully adding an attachment
public alternativeExists ()
 

Check if this message has an alternative body set.

  • return bool
public attachmentExists ()
 

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

  • return bool
public base64EncodeWrapMB ( $str , $linebreak = NULL )
 

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

Adapted from a function by paravoid.

  • see http://www.php.net/manual/en/function.mb-encode-mimeheader.php#60283
  • param string $str multi-byte text to wrap encode
  • param string $linebreak string to use as linefeed/end-of-line
  • return string
public clearAddresses ()
 

Clear all To recipients.

public clearAllRecipients ()
 

Clear all recipient types.

public clearAttachments ()
 

Clear all filesystem, string, and binary attachments.

public clearBCCs ()
 

Clear all BCC recipients.

public clearCCs ()
 

Clear all CC recipients.

public clearCustomHeaders ()
 

Clear all custom headers.

public clearQueuedAddresses ( $kind )
 

Clear queued addresses of given kind.

  • param string $kind 'to', 'cc', or 'bcc'
public clearReplyTos ()
 

Clear all ReplyTo recipients.

public createBody ()
 

Assemble the message body.

Returns an empty string on failure.

public createHeader ()
 

Assemble message headers.

  • return string The assembled headers
public DKIM_Add ( $headers_line , $subject , $body )
 

Create the DKIM header and body in a new message header.

public DKIM_BodyC ( $body )
 

Generate a DKIM canonicalization body.

Uses the 'simple' algorithm from RFC6376 section 3.4.3.
Canonicalized bodies should always use CRLF, regardless of mailer setting.

  • see https://tools.ietf.org/html/rfc6376#section-3.4.3
  • param string $body Message Body
  • return string
public DKIM_HeaderC ( $signHeader )
 

Generate a DKIM canonicalization header.

Uses the 'relaxed' algorithm from RFC6376 section 3.4.2.
Canonicalized headers should always use CRLF, regardless of mailer setting.

  • see https://tools.ietf.org/html/rfc6376#section-3.4.2
  • param string $signHeader Header
  • return string
public DKIM_QP ( $txt )
 

Quoted-Printable-encode a DKIM header.

  • param string $txt
  • return string
public DKIM_Sign ( $signHeader )
 

Generate a DKIM signature.

public encodeHeader ( $str , $position = 'text' )
 

Encode a header value (not including its label) optimally.

Picks shortest of Q, B, or none. Result includes folding if needed.
See RFC822 definitions for phrase, comment and text positions.

  • param string $str The header value to encode
  • param string $position What context the string will be used in
  • return string
public encodeQ ( $str , $position = 'text' )
 

Encode a string using Q encoding.

  • see http://tools.ietf.org/html/rfc2047#section-4.2
  • param string $str the text to encode
  • param string $position Where the text is going to be used, see the RFC for what that means
  • return string
public encodeQP ( $string )
 

Encode a string in quoted-printable format.

According to RFC2045 section 6.7.

  • param string $string The text to encode
  • return string
public encodeString ( $str , $encoding = 'base64' self::ENCODING_BASE64)
 

Encode a string in requested format.

Returns an empty string on failure.

  • param string $str The text to encode
  • param string $encoding The encoding to use; one of 'base64', '7bit', '8bit', 'binary', 'quoted-printable'
  • throws PHPMailer\PHPMailer\Exception
  • return string
public static filenameToType ( $filename )
 

Map a file name to a MIME type.

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

  • param string $filename A file name or full path, does not need to exist as a file
  • return string
public getAllRecipientAddresses ()
 

Allows for public read access to 'all_recipients' property.

Before the send() call, queued addresses (i.e. with IDN) are not yet included.

  • return array
public getAttachments ()
 

Return the array of attachments.

  • return array
public getBccAddresses ()
 

Allows for public read access to 'bcc' property.

Before the send() call, queued addresses (i.e. with IDN) are not yet included.

  • return array
public getCcAddresses ()
 

Allows for public read access to 'cc' property.

Before the send() call, queued addresses (i.e. with IDN) are not yet included.

  • return array
public getCustomHeaders ()
 

Returns all custom headers.

  • return array
public getLastMessageID ()
 

Return the Message-ID header of the last email.

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.

  • return string
public static getLE ()
 

Return the current line break format string.

  • return string
public getMailMIME ()
 

Get the message MIME type headers.

  • return string
public getOAuth ()
 

Get the OAuthTokenProvider instance.

public getReplyToAddresses ()
 

Allows for public read access to 'ReplyTo' property.

Before the send() call, queued addresses (i.e. with IDN) are not yet included.

  • return array
public getSentMIMEMessage ()
 

Returns the whole MIME message.

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

  • see \PHPMailer::preSend()
  • return string
public getSMTPInstance ()
 

Get an instance to use for SMTP operations.

Override this function to load your own SMTP implementation,
or set one with setSMTPInstance.

public getToAddresses ()
 

Allows for public read access to 'to' property.

Before the send() call, queued addresses (i.e. with IDN) are not yet included.

  • return array
public getTranslations ()
 

Get the array of strings for the current language.

  • return array
public has8bitChars ( $text )
 

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

  • param string $text
  • return bool
public static hasLineLongerThanMax ( $str )
 

Detect if a string contains a line longer than the maximum line length
allowed by RFC 2822 section 2.1.1.

  • param string $str
  • return bool
public hasMultiBytes ( $str )
 

Check if a string contains multi-byte characters.

  • param string $str multi-byte text to wrap encode
  • return bool
public headerLine ( $name , $value )
 

Format a header line.

  • param string $name
  • param string | int $value
  • return string
public html2text ( $html , $advanced = false )
 

Convert an HTML string into plain text.

This is used by msgHTML().
Note - older versions of this function used a bundled advanced converter
which was 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();
});
  • param string $html The HTML text to convert
  • param bool | callable $advanced Any boolean value to use the internal converter,
    or provide your own callable for custom conversion.
    Never pass user-supplied data into this parameter
  • return string
public static idnSupported ()
 

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

  • return bool true if required functions for IDN support are present
public inlineImageExists ()
 

Check if an inline attachment is present.

  • return bool
public isError ()
 

Check if an error occurred.

  • return bool True if an error did occur
public isHTML ( $isHtml = true )
 

Sets message type to HTML or plain.

  • param bool $isHtml True for HTML mode
public isMail ()
 

Send messages using PHP's mail() function.

public isQmail ()
 

Send messages using qmail.

public isSendmail ()
 

Send messages using $Sendmail.

public isSMTP ()
 

Send messages using SMTP.

public static isValidHost ( $host )
 

Validate whether a string contains a valid value to use as a hostname or IP address.

IPv6 addresses must include [], e.g. [::1], not just ::1.

  • param string $host The host name or IP address to check
  • return bool
public static mb_pathinfo ( $path , $options = NULL )
 

Multi-byte-safe pathinfo replacement.

Drop-in replacement for pathinfo(), but multibyte- and cross-platform-safe.

  • see http://www.php.net/manual/en/function.pathinfo.php#107461
  • param string $path A filename or path, does not need to exist as a file
  • param int | string $options Either a PATHINFO_* constant,
    or a string name to return only the specified piece
  • return string | array
public msgHTML ( $message , $basedir = '' , $advanced = false )
 

Create a message body from an HTML 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)
Converts data-uri images into embedded attachments.
If you don't want to apply these transformations to your HTML, just set Body and AltBody directly.

  • param string $message HTML message string
  • param string $basedir Absolute path to a base directory to prepend to relative paths to images
  • param bool | callable $advanced Whether to use the internal HTML to text converter
    or your own custom converter
  • return string The transformed message body
  • throws PHPMailer\PHPMailer\Exception
  • see \PHPMailer::html2text()
public static normalizeBreaks ( $text , $breaktype = NULL )
 

Normalize line breaks in a string.

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.

  • param string $text
  • param string $breaktype What kind of line break to use; defaults to static::$LE
  • return string
public static parseAddresses ( $addrstr , $useimap = true , $charset = 'iso-8859-1' self::CHARSET_ISO88591)
 

Parse and validate a string containing one or more RFC822-style comma-separated email addresses
of the form "display name

" into an array of name/address pairs.

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

  • see http://www.andrew.cmu.edu/user/agreen1/testing/mrbs/web/Mail/RFC822.phpA more careful implementation
  • param string $addrstr The address list string
  • param bool $useimap Whether to use the IMAP extension to parse the list
  • param string $charset The charset to use when decoding the address list string.
  • return array
public postSend ()
 

Actually send a message via the selected mechanism.

public preSend ()
 

Prepare a message for sending.

public punyencodeAddress ( $address )
 

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

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 contains characters not allowed in an IDN).
  • see \PHPMailer::$CharSet
  • param string $address The email address to convert
  • return string The encoded address in ASCII form
public static quotedString ( $str )
 

If a string contains any "special" characters, double-quote the name,
and escape any double quotes with a backslash.

  • param string $str
  • return string
  • see \RFC8223.4.1
public static rfcDate ()
 

Return an RFC 822 formatted date.

  • return string
public secureHeader ( $str )
 

Strip newlines to prevent header injection.

  • param string $str
  • return string
public send ()
 

Create a message and send it.

Uses the sending method specified by $Mailer.

public set ( $name , $value = '' )
 

Set or reset instance properties.

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', static::ENCRYPTION_STARTTLS);
is the same as:
$mail->SMTPSecure = static::ENCRYPTION_STARTTLS;.

  • param string $name The property name to set
  • param mixed $value The value to set the property to
  • return bool
public setFrom ( $address , $name = '' , $auto = true )
 

Set the From and FromName properties.

  • param string $address
  • param string $name
  • param bool $auto Whether to also set the Sender address, defaults to true
  • throws PHPMailer\PHPMailer\Exception
  • return bool
public setLanguage ( $langcode = 'en' , $lang_path = '' )
 

Set the language for error messages.

The default language is English.

  • param string $langcode ISO 639-1 2-character language code (e.g. French is "fr")
    Optionally, the language code can be enhanced with a 4-character
    script annotation and/or a 2-character country annotation.
  • param string $lang_path Path to the language file directory, with trailing separator (slash)
    Do not set this from user input!
  • return bool Returns true if the requested language was loaded, false otherwise.
public setOAuth ( PHPMailer\PHPMailer\OAuthTokenProvider $oauth )
 

Set an OAuthTokenProvider instance.

public setSMTPInstance ( PHPMailer\PHPMailer\SMTP $smtp )
 

Provide an instance to use for SMTP operations.

public setWordWrap ()
 

Apply word wrapping to the message body.

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.

public sign ( $cert_filename , $key_filename , $key_pass , $extracerts_filename = '' )
 

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

  • param string $cert_filename
  • param string $key_filename
  • param string $key_pass Password for private key
  • param string $extracerts_filename Optional path to chain certificate
public smtpClose ()
 

Close the active SMTP session if one exists.

public smtpConnect ( $options = NULL )
 

Initiate a connection to an SMTP server.

Returns false if the operation failed.

  • param array $options An array of options compatible with stream_context_create()
  • throws PHPMailer\PHPMailer\Exception
  • uses \PHPMailer\PHPMailer\SMTP
  • return bool
public static stripTrailingWSP ( $text )
 

Remove trailing breaks from a string.

  • param string $text
  • return string The text to remove breaks from
public textLine ( $value )
 

Return a formatted mail line.

  • param string $value
  • return string
public utf8CharBoundary ( $encodedText , $maxLength )
 

Find the last character boundary prior to $maxLength in a utf-8
quoted-printable encoded string.

Original written by Colin Brown.

  • param string $encodedText utf-8 QP text
  • param int $maxLength Find the last character boundary prior to this length
  • return int
public static validateAddress ( $address , $patternselect = NULL )
 

Check that a string looks like an email address.

Validation patterns supported:

  • auto Pick best pattern automatically;
  • pcre8 Use the squiloople.com pattern, requires PCRE > 8.0;
  • 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.

  • param string $address The email address to check
  • param string | callable $patternselect Which pattern to use
  • return bool
public wrapText ( $message , $length , $qp_mode = false )
 

Word-wrap message.

For use with mailers that do not automatically perform wrapping
and for quoted-printable encoded messages.
Original written by philippe.

  • param string $message The message to wrap
  • param int $length The line length to wrap to
  • param bool $qp_mode Whether to run in Quoted-Printable mode
  • return string
Properties
protected $all_recipients
 

An array of all kinds of addresses.

Includes all of $to, $cc, $bcc.

  • see \PHPMailer::$to
  • see \PHPMailer::$cc
  • see \PHPMailer::$bcc
  • var array
protected $attachment
 

The array of attachments.

  • var array
protected $bcc
 

The array of 'bcc' names and addresses.

  • var array
protected $boundary
 

The array of MIME boundary strings.

  • var array
protected $cc
 

The array of 'cc' names and addresses.

  • var array
protected $CustomHeader
 

The array of custom headers.

  • var array
protected $error_count
 

The number of errors encountered.

  • var int
protected $exceptions
 

Whether to throw exceptions for errors.

  • var bool
protected static $IcalMethods = [ 'REQUEST' , 'PUBLISH' , 'REPLY' , 'ADD' , 'CANCEL' , 'REFRESH' , 'COUNTER' , 'DECLINECOUNTER' ]
 

Value-array of "method" in Contenttype header "text/calendar"

  • var string []
protected $language
 

The array of available text strings for the current language.

  • var array
protected $lastMessageID
 

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

  • var string
protected static $LE = ' '
 

SMTP RFC standard line ending; Carriage Return, Line Feed.

  • var string
protected $mailHeader
 

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

  • var string
protected $message_type
 

The message's MIME type.

  • var string
protected $MIMEBody
 

The complete compiled MIME message body.

  • var string
protected $MIMEHeader
 

The complete compiled MIME message headers.

  • var string
protected $oauth
 

An implementation of the PHPMailer OAuthTokenProvider interface.

protected $RecipientsQueue
 

An array of names and addresses queued for validation.

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.

  • see \PHPMailer::$to
  • see \PHPMailer::$cc
  • see \PHPMailer::$bcc
  • see \PHPMailer::$all_recipients
  • var array
protected $ReplyTo
 

The array of reply-to names and addresses.

  • var array
protected $ReplyToQueue
 

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

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

  • see \PHPMailer::$ReplyTo
  • var array
protected $sign_cert_file
 

The S/MIME certificate file path.

  • var string
protected $sign_extracerts_file
 

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

  • var string
protected $sign_key_file
 

The S/MIME key file path.

  • var string
protected $sign_key_pass
 

The S/MIME password for the key.

Used only if the key is encrypted.

  • var string
protected $SingleToArray
 

Storage for addresses when SingleTo is enabled.

  • var array
protected $smtp
 

An instance of the SMTP sender class.

protected $to
 

The array of 'to' names and addresses.

  • var array
protected $uniqueid
 

Unique ID used for message ID and boundaries.

  • var string
Methods
protected addAnAddress ( $kind , $address , $name = '' )
 

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

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

  • param string $kind One of 'to', 'cc', 'bcc', or 'ReplyTo'
  • param string $address The email address to send, resp. to reply to
  • param string $name
  • throws PHPMailer\PHPMailer\Exception
  • return bool true on success, false if address already used or invalid in some way
protected addOrEnqueueAnAddress ( $kind , $address , $name )
 

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().

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

  • param string $kind One of 'to', 'cc', 'bcc', or 'ReplyTo'
  • param string $address The email address
  • param string $name An optional username associated with the address
  • throws PHPMailer\PHPMailer\Exception
  • return bool true on success, false if address already used or invalid in some way
protected attachAll ( $disposition_type , $boundary )
 

Attach all file, string, and binary attachments to the message.

Returns an empty string on failure.

protected cidExists ( $cid )
 

Check if an embedded attachment is present with this cid.

  • param string $cid
  • return bool
protected doCallback ( $isSent , $to , $cc , $bcc , $subject , $body , $from , $extra )
 

Perform a callback.

  • param bool $isSent
  • param array $to
  • param array $cc
  • param array $bcc
  • param string $subject
  • param string $body
  • param string $from
  • param array $extra
protected edebug ( $str )
 

Output debugging info via a user-defined method.

Only generates output if debug output is enabled.

  • see \PHPMailer::$Debugoutput
  • see \PHPMailer::$SMTPDebug
  • param string $str
protected encodeFile ( $path , $encoding = 'base64' self::ENCODING_BASE64)
 

Encode a file attachment in requested format.

Returns an empty string on failure.

  • param string $path The full path to the file
  • param string $encoding The encoding to use; one of 'base64', '7bit', '8bit', 'binary', 'quoted-printable'
  • return string
protected endBoundary ( $boundary )
 

Return the end of a message boundary.

  • param string $boundary
  • return string
protected static fileIsAccessible ( $path )
 

Check whether a file path is safe, accessible, and readable.

  • param string $path A relative or absolute path to a file
  • return bool
protected generateId ()
 

Create a unique ID to use for boundaries.

  • return string
protected getBoundary ( $boundary , $charSet , $contentType , $encoding )
 

Return the start of a message boundary.

  • param string $boundary
  • param string $charSet
  • param string $contentType
  • param string $encoding
  • return string
protected static isPermittedPath ( $path )
 

Check whether a file path is of a permitted type.

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

  • param string $path A relative or absolute path to a file
  • return bool
protected static isShellSafe ( $string )
 

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

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

  • see https://github.com/PHPMailer/PHPMailer/issues/924CVE-2016-10045 bug report
  • param string $string The string to be validated
  • return bool
protected lang ( $key )
 

Get an error message in the current language.

  • param string $key
  • return string
protected mailSend ( $header , $body )
 

Send mail using the PHP mail() function.

  • see http://www.php.net/manual/en/book.mail.php
  • param string $header The message headers
  • param string $body The message body
  • throws PHPMailer\PHPMailer\Exception
  • return bool
protected sendmailSend ( $header , $body )
 

Send mail using the $Sendmail program.

protected serverHostname ()
 

Get the server hostname.

Returns 'localhost.localdomain' if unknown.

  • return string
protected setError ( $msg )
 

Add an error message to the error container.

  • param string $msg
protected static setLE ( $le )
 

Set the line break format string, e.g. "\r\n".

  • param string $le
protected setMessageType ()
 

Set the message type.

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

protected smtpSend ( $header , $body )
 

Send mail via SMTP.

Returns false if there is a bad MAIL FROM, RCPT, or DATA input.

  • see \PHPMailer::setSMTPInstance()to use a different class.
  • uses \PHPMailer\PHPMailer\SMTP
  • param string $header The message headers
  • param string $body The message body
  • throws PHPMailer\PHPMailer\Exception
  • return bool
protected validateEncoding ( $encoding )
 

Validate encodings.

  • param string $encoding
  • return bool
Methods
private getSmtpErrorMessage ( $base_key )
 

Build an error message starting with a generic one and adding details if possible.

  • param string $base_key
  • return string
private mailPassthru ( $to , $subject , $body , $header , $params )
 

Call mail() 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).

  • param string $to To
  • param string $subject Subject
  • param string $body Message Body
  • param string $header Additional Header(s)
  • param string | null $params Params
  • return bool
Properties
protected static $IcalMethods = [ 'REQUEST' , 'PUBLISH' , 'REPLY' , 'ADD' , 'CANCEL' , 'REFRESH' , 'COUNTER' , 'DECLINECOUNTER' ]
 

Value-array of "method" in Contenttype header "text/calendar"

  • var string []
protected static $LE = ' '
 

SMTP RFC standard line ending; Carriage Return, Line Feed.

  • var string
public static $validator = 'php'
 

Which validator to use by default when validating email addresses.

May be a callable to inject your own validator, but there are several built-in validators.
The default validator uses PHP's FILTER_VALIDATE_EMAIL filter_var option.

  • see \PHPMailer::validateAddress()
  • var string | callable
Methods
public static _mime_types ( $ext = '' )
 

Get the MIME type for a file extension.

  • param string $ext File extension
  • return string MIME type of file
protected static fileIsAccessible ( $path )
 

Check whether a file path is safe, accessible, and readable.

  • param string $path A relative or absolute path to a file
  • return bool
public static filenameToType ( $filename )
 

Map a file name to a MIME type.

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

  • param string $filename A file name or full path, does not need to exist as a file
  • return string
public static getLE ()
 

Return the current line break format string.

  • return string
public static hasLineLongerThanMax ( $str )
 

Detect if a string contains a line longer than the maximum line length
allowed by RFC 2822 section 2.1.1.

  • param string $str
  • return bool
public static idnSupported ()
 

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

  • return bool true if required functions for IDN support are present
protected static isPermittedPath ( $path )
 

Check whether a file path is of a permitted type.

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

  • param string $path A relative or absolute path to a file
  • return bool
protected static isShellSafe ( $string )
 

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

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

  • see https://github.com/PHPMailer/PHPMailer/issues/924CVE-2016-10045 bug report
  • param string $string The string to be validated
  • return bool
public static isValidHost ( $host )
 

Validate whether a string contains a valid value to use as a hostname or IP address.

IPv6 addresses must include [], e.g. [::1], not just ::1.

  • param string $host The host name or IP address to check
  • return bool
public static mb_pathinfo ( $path , $options = NULL )
 

Multi-byte-safe pathinfo replacement.

Drop-in replacement for pathinfo(), but multibyte- and cross-platform-safe.

  • see http://www.php.net/manual/en/function.pathinfo.php#107461
  • param string $path A filename or path, does not need to exist as a file
  • param int | string $options Either a PATHINFO_* constant,
    or a string name to return only the specified piece
  • return string | array
public static normalizeBreaks ( $text , $breaktype = NULL )
 

Normalize line breaks in a string.

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.

  • param string $text
  • param string $breaktype What kind of line break to use; defaults to static::$LE
  • return string
public static parseAddresses ( $addrstr , $useimap = true , $charset = 'iso-8859-1' self::CHARSET_ISO88591)
 

Parse and validate a string containing one or more RFC822-style comma-separated email addresses
of the form "display name

" into an array of name/address pairs.

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

  • see http://www.andrew.cmu.edu/user/agreen1/testing/mrbs/web/Mail/RFC822.phpA more careful implementation
  • param string $addrstr The address list string
  • param bool $useimap Whether to use the IMAP extension to parse the list
  • param string $charset The charset to use when decoding the address list string.
  • return array
public static quotedString ( $str )
 

If a string contains any "special" characters, double-quote the name,
and escape any double quotes with a backslash.

  • param string $str
  • return string
  • see \RFC8223.4.1
public static rfcDate ()
 

Return an RFC 822 formatted date.

  • return string
protected static setLE ( $le )
 

Set the line break format string, e.g. "\r\n".

  • param string $le
public static stripTrailingWSP ( $text )
 

Remove trailing breaks from a string.

  • param string $text
  • return string The text to remove breaks from
public static validateAddress ( $address , $patternselect = NULL )
 

Check that a string looks like an email address.

Validation patterns supported:

  • auto Pick best pattern automatically;
  • pcre8 Use the squiloople.com pattern, requires PCRE > 8.0;
  • 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.

  • param string $address The email address to check
  • param string | callable $patternselect Which pattern to use
  • return bool
© 2022 Bruce Wells
Search Namespaces \ Classes
Configuration