kotchasan

PHPMailer
in package

PHPMailer - PHP email creation and transport class.

Tags
author

Marcus Bointon (Synchro/coolbru) phpmailer@synchromedia.co.uk

author

Jim Jagielski (jimjag) jimjag@gmail.com

author

Andy Prevost (codeworxtech) codeworxtech@users.sourceforge.net

author

Brent R. Matzelle (original founder)

Table of Contents

CRLF  = " "
SMTP RFC standard line ending.
MAX_LINE_LENGTH  = 998
The maximum line length allowed by RFC 2822 section 2.1.1.
STOP_CONTINUE  = 1
Error severity: message, likely ok to continue processing.
STOP_CRITICAL  = 2
Error severity: message, plus full stop, critical error reached.
STOP_MESSAGE  = 0
Error severity: message only, continue processing.
$action_function  : string
Callback Action function name.
$AllowEmpty  : bool
Whether to allow sending messages with an empty body.
$AltBody  : string
The plain-text message body.
$AuthType  : string
SMTP auth type.
$Body  : string
An HTML or plain text message body.
$CharSet  : string
The character set of the message.
$ConfirmReadingTo  : string
The email address that a reading confirmation should be sent to, also known as read receipt.
$ContentType  : string
The MIME Content-type of the message.
$Debugoutput  : string|callable
How to handle debug output.
$DKIM_domain  : string
DKIM signing domain name.
$DKIM_identity  : string
DKIM Identity.
$DKIM_passphrase  : string
DKIM passphrase.
$DKIM_private  : string
DKIM private key file path.
$DKIM_private_string  : string
DKIM private key string.
$DKIM_selector  : string
DKIM selector.
$do_verp  : bool
Whether to generate VERP addresses on send.
$Encoding  : string
The message encoding.
$ErrorInfo  : string
Holds the most recent mailer error message.
$From  : string
The From email address for the message.
$FromName  : string
The From name of the message.
$Helo  : string
The SMTP HELO of the message.
$Host  : string
SMTP hosts.
$Hostname  : string
The hostname to use in the Message-ID header and as default HELO string.
$Ical  : string
An iCal message part body.
$LE  : string
The default line ending.
$Mailer  : string
Which method to use to send mail.
$MessageDate  : string
The message Date to be used in the Date header.
$MessageID  : string
An ID to be used in the Message-ID header.
$Password  : string
SMTP password.
$PluginDir  : string
Path to PHPMailer plugins.
$Port  : int
The default SMTP server port.
$Priority  : int
Email priority.
$Realm  : string
SMTP realm.
$ReturnPath  : string
The Return-Path of the message.
$Sender  : string
The Sender email (Return-Path) of the message.
$Sendmail  : string
The path to the sendmail program.
$SingleTo  : bool
Whether to split multiple to addresses into multiple messages or send them all in one message.
$SingleToArray  : array<string|int, mixed>
Storage for addresses when SingleTo is enabled.
$SMTPAuth  : bool
Whether to use SMTP authentication.
$SMTPAutoTLS  : bool
Whether to enable TLS encryption automatically if a server supports it, even if `SMTPSecure` is not set to 'tls'.
$SMTPDebug  : int
SMTP class debug output mode.
$SMTPKeepAlive  : bool
Whether to keep SMTP connection open after each message.
$SMTPOptions  : array<string|int, mixed>
Options array passed to stream_context_create when connecting via SMTP.
$SMTPSecure  : string
What kind of encryption to use on the SMTP connection.
$Subject  : string
The Subject of the message.
$Timeout  : int
The SMTP server timeout in seconds.
$Username  : string
SMTP username.
$UseSendmailOptions  : bool
Whether mail() uses a fully sendmail-compatible MTA.
$validator  : string|callable
Which validator to use by default when validating email addresses.
$Version  : string
The PHPMailer Version number.
$WordWrap  : int
Word-wrap the message body to this number of chars.
$Workstation  : string
SMTP workstation.
$XMailer  : string
What to put in the X-Mailer header.
$all_recipients  : array<string|int, mixed>
An array of all kinds of addresses.
$attachment  : array<string|int, mixed>
The array of attachments.
$bcc  : array<string|int, mixed>
The array of 'bcc' names and addresses.
$boundary  : array<string|int, mixed>
The array of MIME boundary strings.
$cc  : array<string|int, mixed>
The array of 'cc' names and addresses.
$CustomHeader  : array<string|int, mixed>
The array of custom headers.
$error_count  : int
The number of errors encountered.
$exceptions  : bool
Whether to throw exceptions for errors.
$language  : array<string|int, mixed>
The array of available languages.
$lastMessageID  : string
The most recent Message-ID (including angular brackets).
$mailHeader  : string
Extra headers that createHeader() doesn't fold in.
$message_type  : string
The message's MIME type.
$MIMEBody  : string
The complete compiled MIME message body.
$MIMEHeader  : string
The complete compiled MIME message headers.
$RecipientsQueue  : array<string|int, mixed>
An array of names and addresses queued for validation.
$ReplyTo  : array<string|int, mixed>
The array of reply-to names and addresses.
$ReplyToQueue  : array<string|int, mixed>
An array of reply-to names and addresses queued for validation.
$sign_cert_file  : string
The S/MIME certificate file path.
$sign_extracerts_file  : string
The optional S/MIME extra certificates ("CA Chain") file path.
$sign_key_file  : string
The S/MIME key file path.
$sign_key_pass  : string
The S/MIME password for the key.
$smtp  : SMTP
An instance of the SMTP sender class.
$to  : array<string|int, mixed>
The array of 'to' names and addresses.
$uniqueid  : string
Unique ID used for message ID and boundaries.
__construct()  : mixed
Constructor.
__destruct()  : mixed
Destructor.
_mime_types()  : string
Get the MIME type for a file extension.
addAddress()  : bool
Add a "To" address.
addAttachment()  : bool
Add an attachment from a path on the filesystem.
addBCC()  : bool
Add a "BCC" address.
addCC()  : bool
Add a "CC" address.
addCustomHeader()  : mixed
Add a custom header.
addEmbeddedImage()  : bool
Add an embedded (inline) attachment from a file.
addrAppend()  : string
Create recipient headers.
addReplyTo()  : bool
Add a "Reply-To" address.
addrFormat()  : string
Format an address for use in a message header.
addStringAttachment()  : mixed
Add a string or binary attachment (non-filesystem).
addStringEmbeddedImage()  : bool
Add an embedded stringified attachment.
alternativeExists()  : bool
Check if this message has an alternative body set.
attachmentExists()  : bool
Check if an attachment (non-inline) is present.
base64EncodeWrapMB()  : string
Encode and wrap long multibyte strings for mail headers without breaking lines within a character.
clearAddresses()  : mixed
Clear all To recipients.
clearAllRecipients()  : mixed
Clear all recipient types.
clearAttachments()  : mixed
Clear all filesystem, string, and binary attachments.
clearBCCs()  : mixed
Clear all BCC recipients.
clearCCs()  : mixed
Clear all CC recipients.
clearCustomHeaders()  : mixed
Clear all custom headers.
clearQueuedAddresses()  : mixed
Clear queued addresses of given kind.
clearReplyTos()  : mixed
Clear all ReplyTo recipients.
createBody()  : string
Assemble the message body.
createHeader()  : string
Assemble message headers.
DKIM_Add()  : string
Create the DKIM header and body in a new message header.
DKIM_BodyC()  : string
Generate a DKIM canonicalization body.
DKIM_HeaderC()  : string
Generate a DKIM canonicalization header.
DKIM_QP()  : string
Quoted-Printable-encode a DKIM header.
DKIM_Sign()  : string
Generate a DKIM signature.
encodeHeader()  : string
Encode a header string optimally.
encodeQ()  : string
Encode a string using Q encoding.
encodeQP()  : string
Encode a string in quoted-printable format.
encodeQPphp()  : string
Backward compatibility wrapper for an old QP encoding function that was removed.
encodeString()  : string
Encode a string in requested format.
filenameToType()  : string
Map a file name to a MIME type.
fixEOL()  : string
Ensure consistent line endings in a string.
getAllRecipientAddresses()  : array<string|int, mixed>
Allows for public read access to 'all_recipients' property.
getAttachments()  : array<string|int, mixed>
Return the array of attachments.
getBccAddresses()  : array<string|int, mixed>
Allows for public read access to 'bcc' property.
getCcAddresses()  : array<string|int, mixed>
Allows for public read access to 'cc' property.
getCustomHeaders()  : array<string|int, mixed>
Returns all custom headers.
getLastMessageID()  : string
Return the Message-ID header of the last email.
getMailMIME()  : string
Get the message MIME type headers.
getReplyToAddresses()  : array<string|int, mixed>
Allows for public read access to 'ReplyTo' property.
getSentMIMEMessage()  : string
Returns the whole MIME message.
getSMTPInstance()  : SMTP
Get an instance to use for SMTP operations.
getToAddresses()  : array<string|int, mixed>
Allows for public read access to 'to' property.
getTranslations()  : array<string|int, mixed>
Get the array of strings for the current language.
has8bitChars()  : bool
Does a string contain any 8-bit chars (in any charset)?
hasLineLongerThanMax()  : bool
Detect if a string contains a line longer than the maximum line length allowed.
hasMultiBytes()  : bool
Check if a string contains multi-byte characters.
headerLine()  : string
Format a header line.
html2text()  : string
Convert an HTML string into plain text.
idnSupported()  : bool
Tells whether IDNs (Internationalized Domain Names) are supported or not. This requires the "intl" and "mbstring" PHP extensions.
inlineImageExists()  : bool
Check if an inline attachment is present.
isError()  : bool
Check if an error occurred.
isHTML()  : mixed
Sets message type to HTML or plain.
isMail()  : mixed
Send messages using PHP's mail() function.
isQmail()  : mixed
Send messages using qmail.
isSendmail()  : mixed
Send messages using $Sendmail.
isSMTP()  : mixed
Send messages using SMTP.
mb_pathinfo()  : string|array<string|int, mixed>
Multi-byte-safe pathinfo replacement.
msgHTML()  : string
Create a message body from an HTML string.
normalizeBreaks()  : string
Normalize line breaks in a string.
parseAddresses()  : array<string|int, mixed>
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.
postSend()  : bool
Actually send a message.
preSend()  : bool
Prepare a message for sending.
punyencodeAddress()  : string
Converts IDN in given email address to its ASCII form, also known as punycode, if possible.
rfcDate()  : string
Return an RFC 822 formatted date.
secureHeader()  : string
Strip newlines to prevent header injection.
send()  : bool
Create a message and send it.
set()  : bool
Set or reset instance properties.
setFrom()  : bool
Set the From and FromName properties.
setLanguage()  : bool
Set the language for error messages.
setWordWrap()  : mixed
Apply word wrapping to the message body.
sign()  : mixed
Set the public and private key files and password for S/MIME signing.
smtpClose()  : mixed
Close the active SMTP session if one exists.
smtpConnect()  : bool
Initiate a connection to an SMTP server.
textLine()  : string
Return a formatted mail line.
utf8CharBoundary()  : int
Find the last character boundary prior to $maxLength in a utf-8 quoted-printable encoded string.
validateAddress()  : bool
Check that a string looks like an email address.
wrapText()  : string
Word-wrap message.
addAnAddress()  : bool
Add an address to one of the recipient arrays or to the ReplyTo array.
addOrEnqueueAnAddress()  : bool
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().
attachAll()  : string
Attach all file, string, and binary attachments to the message.
doCallback()  : mixed
Perform a callback.
edebug()  : mixed
Output debugging info via user-defined method.
encodeFile()  : string
Encode a file attachment in requested format.
endBoundary()  : string
Return the end of a message boundary.
generateId()  : string
Create unique ID.
getBoundary()  : string
Return the start of a message boundary.
isShellSafe()  : bool
Fix CVE-2016-10033 and CVE-2016-10045 by disallowing potentially unsafe shell characters.
lang()  : string
Get an error message in the current language.
mailSend()  : bool
Send mail using the PHP mail() function.
sendmailSend()  : bool
Send mail using the $Sendmail program.
serverHostname()  : string
Get the server hostname.
setError()  : mixed
Add an error message to the error container.
setMessageType()  : mixed
Set the message type.
smtpSend()  : bool
Send mail via SMTP.
mailPassthru()  : bool
Call mail() in a safe_mode-aware fashion.

Constants

MAX_LINE_LENGTH

The maximum line length allowed by RFC 2822 section 2.1.1.

public int MAX_LINE_LENGTH = 998

STOP_CONTINUE

Error severity: message, likely ok to continue processing.

public mixed STOP_CONTINUE = 1

STOP_CRITICAL

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

public mixed STOP_CRITICAL = 2

STOP_MESSAGE

Error severity: message only, continue processing.

public mixed STOP_MESSAGE = 0

Properties

$action_function

Callback Action function name.

public string $action_function = ''

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

$AllowEmpty

Whether to allow sending messages with an empty body.

public bool $AllowEmpty = alse

$AltBody

The plain-text message body.

public string $AltBody = ''

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.

$AuthType

SMTP auth type.

public string $AuthType = ''

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

$Body

An HTML or plain text message body.

public string $Body = ''

If HTML then call isHTML(true).

$CharSet

The character set of the message.

public string $CharSet = 'iso-8859-1'

$ConfirmReadingTo

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

public string $ConfirmReadingTo = ''

$ContentType

The MIME Content-type of the message.

public string $ContentType = 'text/plain'

$Debugoutput

How to handle debug output.

public string|callable $Debugoutput = '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";};

Tags
see
SMTP::$Debugoutput

$DKIM_domain

DKIM signing domain name.

public string $DKIM_domain = ''
Tags
example

'example.com'

$DKIM_identity

DKIM Identity.

public string $DKIM_identity = ''

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

$DKIM_passphrase

DKIM passphrase.

public string $DKIM_passphrase = ''

Used if your key is encrypted.

$DKIM_private

DKIM private key file path.

public string $DKIM_private = ''

$DKIM_private_string

DKIM private key string.

public string $DKIM_private_string = ''

If set, takes precedence over $DKIM_private.

$Encoding

The message encoding.

public string $Encoding = '8bit'

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

$ErrorInfo

Holds the most recent mailer error message.

public string $ErrorInfo = ''

$From

The From email address for the message.

public string $From = 'root@localhost'

$FromName

The From name of the message.

public string $FromName = 'Root User'

$Helo

The SMTP HELO of the message.

public string $Helo = ''

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

Tags
see
PHPMailer::$Hostname

$Host

SMTP hosts.

public string $Host = '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.

$Hostname

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

public string $Hostname = ''

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

$LE

The default line ending.

public string $LE = " "
Tags
note

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

$Mailer

Which method to use to send mail.

public string $Mailer = 'mail'

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

$MessageDate

The message Date to be used in the Date header.

public string $MessageDate = ''

If empty, the current date will be added.

$PluginDir

Path to PHPMailer plugins.

public string $PluginDir = ''

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

Tags
deprecated

should not be needed now there is an autoloader

$Port

The default SMTP server port.

public int $Port = 25
Tags
TODO

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

$Priority

Email priority.

public int $Priority = ull

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

$ReturnPath

The Return-Path of the message.

public string $ReturnPath = ''

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

it's the receiver's job (RFC5321 section 4.4), so this no longer does anything.

Tags
deprecated

Email senders should never set a return-path header;

see
https://tools.ietf.org/html/rfc5321#section-4.4

RFC5321 reference

$Sender

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

public string $Sender = ''

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

$Sendmail

The path to the sendmail program.

public string $Sendmail = '/usr/sbin/sendmail'

$SingleTo

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

public bool $SingleTo = alse

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

$SingleToArray

Storage for addresses when SingleTo is enabled.

public array<string|int, mixed> $SingleToArray = array()
Tags
TODO

This should really not be public

$SMTPAutoTLS

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

public bool $SMTPAutoTLS = rue

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

$SMTPDebug

SMTP class debug output mode.

public int $SMTPDebug = 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.

Tags
see
SMTP::$do_debug

$SMTPKeepAlive

Whether to keep SMTP connection open after each message.

public bool $SMTPKeepAlive = alse

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

$SMTPOptions

Options array passed to stream_context_create when connecting via SMTP.

public array<string|int, mixed> $SMTPOptions = array()

$SMTPSecure

What kind of encryption to use on the SMTP connection.

public string $SMTPSecure = ''

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

$Timeout

The SMTP server timeout in seconds.

public int $Timeout = 300

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

$UseSendmailOptions

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

public bool $UseSendmailOptions = rue

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

$validator

Which validator to use by default when validating email addresses.

public static string|callable $validator = 'auto'

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

Tags
static
see
PHPMailer::validateAddress()

$Version

The PHPMailer Version number.

public string $Version = '5.2.21'

$WordWrap

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

public int $WordWrap = 0

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

$Workstation

SMTP workstation.

public string $Workstation = ''

Used for NTLM auth.

$XMailer

What to put in the X-Mailer header.

public string $XMailer = ''

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

$all_recipients

An array of all kinds of addresses.

protected array<string|int, mixed> $all_recipients = array()

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

Tags
see
PHPMailer::$to

@see PHPMailer::$cc @see PHPMailer::$bcc

$attachment

The array of attachments.

protected array<string|int, mixed> $attachment = array()

$bcc

The array of 'bcc' names and addresses.

protected array<string|int, mixed> $bcc = array()

$boundary

The array of MIME boundary strings.

protected array<string|int, mixed> $boundary = array()

$cc

The array of 'cc' names and addresses.

protected array<string|int, mixed> $cc = array()

$CustomHeader

The array of custom headers.

protected array<string|int, mixed> $CustomHeader = array()

$error_count

The number of errors encountered.

protected int $error_count = 0

$exceptions

Whether to throw exceptions for errors.

protected bool $exceptions = alse

$language

The array of available languages.

protected array<string|int, mixed> $language = array()

$lastMessageID

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

protected string $lastMessageID = ''

$mailHeader

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

protected string $mailHeader = ''

$message_type

The message's MIME type.

protected string $message_type = ''

$MIMEBody

The complete compiled MIME message body.

protected string $MIMEBody = ''

$MIMEHeader

The complete compiled MIME message headers.

protected string $MIMEHeader = ''

$RecipientsQueue

An array of names and addresses queued for validation.

protected array<string|int, mixed> $RecipientsQueue = 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.

Tags
see
PHPMailer::$to

@see PHPMailer::$cc @see PHPMailer::$bcc

see
PHPMailer::$all_recipients

$ReplyTo

The array of reply-to names and addresses.

protected array<string|int, mixed> $ReplyTo = array()

$ReplyToQueue

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

protected array<string|int, mixed> $ReplyToQueue = array()

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

Tags
see
PHPMailer::$ReplyTo

$sign_cert_file

The S/MIME certificate file path.

protected string $sign_cert_file = ''

$sign_extracerts_file

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

protected string $sign_extracerts_file = ''

$sign_key_file

The S/MIME key file path.

protected string $sign_key_file = ''

$sign_key_pass

The S/MIME password for the key.

protected string $sign_key_pass = ''

Used only if the key is encrypted.

$to

The array of 'to' names and addresses.

protected array<string|int, mixed> $to = array()

$uniqueid

Unique ID used for message ID and boundaries.

protected string $uniqueid = ''

Methods

__construct()

Constructor.

public __construct([bool $exceptions = null ]) : mixed
Parameters
$exceptions : bool = null

Should we throw external exceptions?

Return values
mixed

__destruct()

Destructor.

public __destruct() : mixed
Return values
mixed

_mime_types()

Get the MIME type for a file extension.

public static _mime_types([string $ext = '' ]) : string
Parameters
$ext : string = ''

File extension

Tags
static
Return values
string

MIME type of file

addAddress()

Add a "To" address.

public addAddress(string $address[, string $name = '' ]) : bool
Parameters
$address : string

The email address to send to

$name : string = ''
Return values
bool

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

addAttachment()

Add an attachment from a path on the filesystem.

public addAttachment(string $path[, string $name = '' ][, string $encoding = 'base64' ][, string $type = '' ][, string $disposition = 'attachment' ]) : bool

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

Parameters
$path : string

path to the attachment

$name : string = ''

overrides the attachment name

$encoding : string = 'base64'

file encoding (see $Encoding)

$type : string = ''

file extension (MIME) type

$disposition : string = 'attachment'

Disposition to use

Tags
throws
phpmailerException
Return values
bool

addBCC()

Add a "BCC" address.

public addBCC(string $address[, string $name = '' ]) : bool
Parameters
$address : string

The email address to send to

$name : string = ''
Tags
note:

This function works with the SMTP mailer on win32, not with the "mail" mailer.

Return values
bool

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

addCC()

Add a "CC" address.

public addCC(string $address[, string $name = '' ]) : bool
Parameters
$address : string

The email address to send to

$name : string = ''
Tags
note:

This function works with the SMTP mailer on win32, not with the "mail" mailer.

Return values
bool

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

addCustomHeader()

Add a custom header.

public addCustomHeader(string $name[, string $value = null ]) : mixed

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

Parameters
$name : string

Custom header name

$value : string = null

Header value

Return values
mixed

addEmbeddedImage()

Add an embedded (inline) attachment from a file.

public addEmbeddedImage(string $path, string $cid[, string $name = '' ][, string $encoding = 'base64' ][, string $type = '' ][, string $disposition = 'inline' ]) : bool

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. the content when using an embedded image in HTML.

Parameters
$path : string

path to the attachment

$cid : string

Content ID of the attachment; Use this to reference

$name : string = ''

overrides the attachment name

$encoding : string = 'base64'

file encoding (see $Encoding)

$type : string = ''

file MIME type

$disposition : string = 'inline'

Disposition to use

Return values
bool

True on successfully adding an attachment

addrAppend()

Create recipient headers.

public addrAppend(string $type, array<string|int, mixed> $addr) : string
Parameters
$type : string
$addr : array<string|int, mixed>

An array of recipient,

Return values
string

addReplyTo()

Add a "Reply-To" address.

public addReplyTo(string $address[, string $name = '' ]) : bool
Parameters
$address : string

The email address to reply to

$name : string = ''
Return values
bool

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

addrFormat()

Format an address for use in a message header.

public addrFormat(array<string|int, mixed> $addr) : string
Parameters
$addr : array<string|int, mixed>

A 2-element indexed array, element containing an address, element 1 containing a name

Return values
string

addStringAttachment()

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

public addStringAttachment(string $string, string $filename[, string $encoding = 'base64' ][, string $type = '' ][, string $disposition = 'attachment' ]) : mixed

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 = 'base64'

file encoding (see $Encoding)

$type : string = ''

file extension (MIME) type

$disposition : string = 'attachment'

Disposition to use

Return values
mixed

addStringEmbeddedImage()

Add an embedded stringified attachment.

public addStringEmbeddedImage(string $string, string $cid[, string $name = '' ][, string $encoding = 'base64' ][, string $type = '' ][, string $disposition = 'inline' ]) : bool

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'. the content when using an embedded image in HTML.

Parameters
$string : string

the attachment binary data

$cid : string

Content ID of the attachment; Use this to reference

$name : string = ''
$encoding : string = 'base64'

file encoding (see $Encoding)

$type : string = ''

MIME type

$disposition : string = 'inline'

Disposition to use

Return values
bool

True on successfully adding an attachment

alternativeExists()

Check if this message has an alternative body set.

public alternativeExists() : bool
Return values
bool

attachmentExists()

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

public attachmentExists() : bool
Return values
bool

base64EncodeWrapMB()

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

public base64EncodeWrapMB(string $str[, string $linebreak = null ]) : string

Adapted from a function by paravoid.

Parameters
$str : string

multi-byte text to wrap encode

$linebreak : string = null

string to use as linefeed/end-of-line

Tags
see
http://www.php.net/manual/en/function.mb-encode-mimeheader.php#60283
Return values
string

clearAddresses()

Clear all To recipients.

public clearAddresses() : mixed
Return values
mixed

clearAllRecipients()

Clear all recipient types.

public clearAllRecipients() : mixed
Return values
mixed

clearAttachments()

Clear all filesystem, string, and binary attachments.

public clearAttachments() : mixed
Return values
mixed

clearBCCs()

Clear all BCC recipients.

public clearBCCs() : mixed
Return values
mixed

clearCCs()

Clear all CC recipients.

public clearCCs() : mixed
Return values
mixed

clearCustomHeaders()

Clear all custom headers.

public clearCustomHeaders() : mixed
Return values
mixed

clearQueuedAddresses()

Clear queued addresses of given kind.

public clearQueuedAddresses(string $kind) : mixed
Parameters
$kind : string

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

Return values
mixed

clearReplyTos()

Clear all ReplyTo recipients.

public clearReplyTos() : mixed
Return values
mixed

createBody()

Assemble the message body.

public createBody() : string

Returns an empty string on failure.

Tags
throws
phpmailerException
Return values
string

The assembled message body

createHeader()

Assemble message headers.

public createHeader() : string
Return values
string

The assembled headers

DKIM_Add()

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

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

Header lines

$subject : string

Subject

$body : string

Body

Return values
string

DKIM_BodyC()

Generate a DKIM canonicalization body.

public DKIM_BodyC(string $body) : string
Parameters
$body : string

Message Body

Return values
string

DKIM_HeaderC()

Generate a DKIM canonicalization header.

public DKIM_HeaderC(string $signHeader) : string
Parameters
$signHeader : string

Header

Return values
string

DKIM_QP()

Quoted-Printable-encode a DKIM header.

public DKIM_QP(string $txt) : string
Parameters
$txt : string
Return values
string

DKIM_Sign()

Generate a DKIM signature.

public DKIM_Sign(string $signHeader) : string
Parameters
$signHeader : string
Tags
throws
phpmailerException
Return values
string

The DKIM signature value

encodeHeader()

Encode a header string optimally.

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

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

Parameters
$str : string
$position : string = 'text'
Return values
string

encodeQ()

Encode a string using Q encoding.

public encodeQ(string $str[, string $position = 'text' ]) : string
Parameters
$str : string

the text to encode

$position : string = 'text'

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

Tags
see
http://tools.ietf.org/html/rfc2047
Return values
string

encodeQPphp()

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

public encodeQPphp(string $string[, int $line_max = 76 ][, bool $space_conv = false ]) : string
Parameters
$string : string
$line_max : int = 76
$space_conv : bool = false
Tags
deprecated

use encodeQP instead

see
PHPMailer::encodeQP()
Return values
string

encodeString()

Encode a string in requested format.

public encodeString(string $str[, string $encoding = 'base64' ]) : string

Returns an empty string on failure.

Parameters
$str : string

The text to encode

$encoding : string = 'base64'

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

Return values
string

filenameToType()

Map a file name to a MIME type.

public static filenameToType(string $filename) : string

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

Parameters
$filename : string

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

Tags
static
Return values
string

fixEOL()

Ensure consistent line endings in a string.

public fixEOL(string $str) : string

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

Parameters
$str : string

String to fixEOL

Return values
string

getAllRecipientAddresses()

Allows for public read access to 'all_recipients' property.

public getAllRecipientAddresses() : array<string|int, mixed>
Tags
note:

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

Return values
array<string|int, mixed>

getAttachments()

Return the array of attachments.

public getAttachments() : array<string|int, mixed>
Return values
array<string|int, mixed>

getBccAddresses()

Allows for public read access to 'bcc' property.

public getBccAddresses() : array<string|int, mixed>
Tags
note:

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

Return values
array<string|int, mixed>

getCcAddresses()

Allows for public read access to 'cc' property.

public getCcAddresses() : array<string|int, mixed>
Tags
note:

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

Return values
array<string|int, mixed>

getCustomHeaders()

Returns all custom headers.

public getCustomHeaders() : array<string|int, mixed>
Return values
array<string|int, mixed>

getLastMessageID()

Return the Message-ID header of the last email.

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

Return values
string

getMailMIME()

Get the message MIME type headers.

public getMailMIME() : string
Return values
string

getReplyToAddresses()

Allows for public read access to 'ReplyTo' property.

public getReplyToAddresses() : array<string|int, mixed>
Tags
note:

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

Return values
array<string|int, mixed>

getSentMIMEMessage()

Returns the whole MIME message.

public getSentMIMEMessage() : string

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

Tags
see
PHPMailer::preSend()
Return values
string

getSMTPInstance()

Get an instance to use for SMTP operations.

public getSMTPInstance() : SMTP

Override this function to load your own SMTP implementation.

Return values
SMTP

getToAddresses()

Allows for public read access to 'to' property.

public getToAddresses() : array<string|int, mixed>
Tags
note:

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

Return values
array<string|int, mixed>

getTranslations()

Get the array of strings for the current language.

public getTranslations() : array<string|int, mixed>
Return values
array<string|int, mixed>

has8bitChars()

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

public has8bitChars(string $text) : bool
Parameters
$text : string
Return values
bool

hasLineLongerThanMax()

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

public static hasLineLongerThanMax(string $str) : bool
Parameters
$str : string
Tags
static
Return values
bool

hasMultiBytes()

Check if a string contains multi-byte characters.

public hasMultiBytes(string $str) : bool
Parameters
$str : string

multi-byte text to wrap encode

Return values
bool

headerLine()

Format a header line.

public headerLine(string $name, string $value) : string
Parameters
$name : string
$value : string
Return values
string

html2text()

Convert an HTML string into plain text.

public html2text(string $html[, bool|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(); }); or provide your own callable for custom conversion.

Parameters
$html : string

The HTML text to convert

$advanced : bool|callable = false

Any boolean value to use the internal converter,

Return values
string

idnSupported()

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

public idnSupported() : bool
Return values
bool

"true" if required functions for IDN support are present

inlineImageExists()

Check if an inline attachment is present.

public inlineImageExists() : bool
Return values
bool

isError()

Check if an error occurred.

public isError() : bool
Return values
bool

true if an error did occur

isHTML()

Sets message type to HTML or plain.

public isHTML([bool $isHtml = true ]) : mixed
Parameters
$isHtml : bool = true

true for HTML mode

Return values
mixed

isMail()

Send messages using PHP's mail() function.

public isMail() : mixed
Return values
mixed

isQmail()

Send messages using qmail.

public isQmail() : mixed
Return values
mixed

isSendmail()

Send messages using $Sendmail.

public isSendmail() : mixed
Return values
mixed

isSMTP()

Send messages using SMTP.

public isSMTP() : mixed
Return values
mixed

mb_pathinfo()

Multi-byte-safe pathinfo replacement.

public static mb_pathinfo(string $path[, int|string $options = null ]) : string|array<string|int, mixed>

Drop-in replacement for pathinfo(), but multibyte-safe, cross-platform-safe, old-version-safe. Works similarly to the one in PHP >= 5.2.0 or a string name to return only the specified piece, allows 'filename' to work on PHP < 5.2.

Parameters
$path : string

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

$options : int|string = null

Either a PATHINFO_* constant,

Tags
static
see
http://www.php.net/manual/en/function.pathinfo.php#107461
Return values
string|array<string|int, mixed>

msgHTML()

Create a message body from an HTML string.

public msgHTML(string $message[, string $basedir = '' ][, bool|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. $basedir is used when handling relative image paths, e.g. will look for an image file in $basedir/images/a.png and convert it to inline. If you don't want to apply these transformations to your HTML, just set Body and AltBody yourself.

Parameters
$message : string

HTML message string

$basedir : string = ''

base directory for relative paths to images

$advanced : bool|callable = false

Whether to use the internal HTML to text converter

Return values
string

$message The transformed message Body

normalizeBreaks()

Normalize line breaks in a string.

public static normalizeBreaks(string $text[, string $breaktype = " " ]) : 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.

Parameters
$text : string
$breaktype : string = " "

What kind of line break to use, defaults to CRLF

Tags
static
Return values
string

parseAddresses()

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.

public parseAddresses(string $addrstr[, bool $useimap = true ]) : array<string|int, mixed>

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

Parameters
$addrstr : string

The address list string

$useimap : bool = true

Whether to use the IMAP extension to parse the list

Tags
see
http://www.andrew.cmu.edu/user/agreen1/testing/mrbs/web/Mail/RFC822.php

A more careful implementation

Return values
array<string|int, mixed>

postSend()

Actually send a message.

public postSend() : bool

Send the email via the selected mechanism.

Tags
throws
phpmailerException
Return values
bool

punyencodeAddress()

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

public 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).
Parameters
$address : string

The email address to convert

Tags
see
PHPMailer::$CharSet
Return values
string

The encoded address in ASCII form

rfcDate()

Return an RFC 822 formatted date.

public static rfcDate() : string
Tags
static
Return values
string

secureHeader()

Strip newlines to prevent header injection.

public secureHeader(string $str) : string
Parameters
$str : string
Return values
string

send()

Create a message and send it.

public send() : bool

Uses the sending method specified by $Mailer.

Tags
throws
phpmailerException
Return values
bool

false on error - See the ErrorInfo property for details of the error

set()

Set or reset instance properties.

public set(string $name[, mixed $value = '' ]) : bool

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';.

Parameters
$name : string

The property name to set

$value : mixed = ''

The value to set the property to

Tags
TODO

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

Return values
bool

setFrom()

Set the From and FromName properties.

public setFrom(string $address[, string $name = '' ][, bool $auto = true ]) : bool
Parameters
$address : string
$name : string = ''
$auto : bool = true

Whether to also set the Sender address, defaults to true

Tags
throws
phpmailerException
Return values
bool

setLanguage()

Set the language for error messages.

public setLanguage([string $langcode = 'en' ][, string $lang_path = '' ]) : bool

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

Parameters
$langcode : string = 'en'

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)

Return values
bool

setWordWrap()

Apply word wrapping to the message body.

public setWordWrap() : mixed

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.

Return values
mixed

sign()

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

public sign(string $cert_filename, string $key_filename, string $key_pass[, string $extracerts_filename = '' ]) : mixed
Parameters
$cert_filename : string
$key_filename : string
$key_pass : string

Password for private key

$extracerts_filename : string = ''

Optional path to chain certificate

Return values
mixed

smtpClose()

Close the active SMTP session if one exists.

public smtpClose() : mixed
Return values
mixed

smtpConnect()

Initiate a connection to an SMTP server.

public smtpConnect([array<string|int, mixed> $options = null ]) : bool

Returns false if the operation failed.

Parameters
$options : array<string|int, mixed> = null

An array of options compatible with stream_context_create()

Tags
uses
SMTP
throws
phpmailerException
Return values
bool

textLine()

Return a formatted mail line.

public textLine(string $value) : string
Parameters
$value : string
Return values
string

utf8CharBoundary()

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

public utf8CharBoundary(string $encodedText, int $maxLength) : int

Original written by Colin Brown.

Parameters
$encodedText : string

utf-8 QP text

$maxLength : int

Find the last character boundary prior to this length

Return values
int

validateAddress()

Check that a string looks like an email address.

public static validateAddress(string $address[, string|callable $patternselect = null ]) : bool

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.

Parameters
$address : string

The email address to check

$patternselect : string|callable = null

A selector for the validation pattern to use :

Tags
static
Return values
bool

wrapText()

Word-wrap message.

public wrapText(string $message, int $length[, bool $qp_mode = false ]) : string

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

Parameters
$message : string

The message to wrap

$length : int

The line length to wrap to

$qp_mode : bool = false

Whether to run in Quoted-Printable mode

Return values
string

addAnAddress()

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

protected addAnAddress(string $kind, string $address[, string $name = '' ]) : bool

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

Parameters
$kind : string

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

$address : string

The email address to send, resp. to reply to

$name : string = ''
Tags
throws
phpmailerException
Return values
bool

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

addOrEnqueueAnAddress()

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

protected addOrEnqueueAnAddress(string $kind, string $address, string $name) : bool

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

Parameters
$kind : string

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

$address : string

The email address to send, resp. to reply to

$name : string
Tags
throws
phpmailerException
Return values
bool

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

attachAll()

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

protected attachAll(string $disposition_type, string $boundary) : string

Returns an empty string on failure.

Parameters
$disposition_type : string
$boundary : string
Return values
string

doCallback()

Perform a callback.

protected doCallback(bool $isSent, array<string|int, mixed> $to, array<string|int, mixed> $cc, array<string|int, mixed> $bcc, string $subject, string $body, string $from) : mixed
Parameters
$isSent : bool
$to : array<string|int, mixed>
$cc : array<string|int, mixed>
$bcc : array<string|int, mixed>
$subject : string
$body : string
$from : string
Return values
mixed

encodeFile()

Encode a file attachment in requested format.

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

Returns an empty string on failure.

Parameters
$path : string

The full path to the file

$encoding : string = 'base64'

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

Tags
throws
phpmailerException
Return values
string

endBoundary()

Return the end of a message boundary.

protected endBoundary(string $boundary) : string
Parameters
$boundary : string
Return values
string

generateId()

Create unique ID.

protected generateId() : string
Return values
string

getBoundary()

Return the start of a message boundary.

protected getBoundary(string $boundary, string $charSet, string $contentType, string $encoding) : string
Parameters
$boundary : string
$charSet : string
$contentType : string
$encoding : string
Return values
string

isShellSafe()

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

protected static isShellSafe(string $string) : bool

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

Parameters
$string : string

The string to be validated

Tags
see
https://github.com/PHPMailer/PHPMailer/issues/924

CVE-2016-10045 bug report

Return values
bool

lang()

Get an error message in the current language.

protected lang(string $key) : string
Parameters
$key : string
Return values
string

sendmailSend()

Send mail using the $Sendmail program.

protected sendmailSend(string $header, string $body) : bool
Parameters
$header : string

The message headers

$body : string

The message body

Tags
see
PHPMailer::$Sendmail
throws
phpmailerException
Return values
bool

serverHostname()

Get the server hostname.

protected serverHostname() : string

Returns 'localhost.localdomain' if unknown.

Return values
string

setError()

Add an error message to the error container.

protected setError(string $msg) : mixed
Parameters
$msg : string
Return values
mixed

setMessageType()

Set the message type.

protected setMessageType() : mixed

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

Return values
mixed

smtpSend()

Send mail via SMTP.

protected smtpSend(string $header, string $body) : bool

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

Parameters
$header : string

The message headers

$body : string

The message body

Tags
uses
SMTP
see
PHPMailer::getSMTPInstance()

to use a different class.

throws
phpmailerException
Return values
bool

mailPassthru()

Call mail() in a safe_mode-aware fashion.

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

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

Parameters
$to : string

To

$subject : string

Subject

$body : string

Message Body

$header : string

Additional Header(s)

$params : string

Params

Return values
bool

Search results