PHPMailer

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

CHARSET_ASCII  = 'us-ascii'
CHARSET_ISO88591  = 'iso-8859-1'
CHARSET_UTF8  = 'utf-8'
CONTENT_TYPE_MULTIPART_ALTERNATIVE  = 'multipart/alternative'
CONTENT_TYPE_MULTIPART_MIXED  = 'multipart/mixed'
CONTENT_TYPE_MULTIPART_RELATED  = 'multipart/related'
CONTENT_TYPE_PLAINTEXT  = 'text/plain'
CONTENT_TYPE_TEXT_CALENDAR  = 'text/calendar'
CONTENT_TYPE_TEXT_HTML  = 'text/html'
CRLF  = "\r\n"
The SMTP standard CRLF line break.
ENCODING_7BIT  = '7bit'
ENCODING_8BIT  = '8bit'
ENCODING_BASE64  = 'base64'
ENCODING_BINARY  = 'binary'
ENCODING_QUOTED_PRINTABLE  = 'quoted-printable'
ENCRYPTION_SMTPS  = 'ssl'
ENCRYPTION_STARTTLS  = 'tls'
FWS  = ' '
"Folding White Space" a white space string used for line folding.
ICAL_METHOD_ADD  = 'ADD'
ICAL_METHOD_CANCEL  = 'CANCEL'
ICAL_METHOD_COUNTER  = 'COUNTER'
ICAL_METHOD_DECLINECOUNTER  = 'DECLINECOUNTER'
ICAL_METHOD_PUBLISH  = 'PUBLISH'
ICAL_METHOD_REFRESH  = 'REFRESH'
ICAL_METHOD_REPLY  = 'REPLY'
ICAL_METHOD_REQUEST  = 'REQUEST'
MAIL_MAX_LINE_LENGTH  = 63
The maximum line length supported by mail().
MAX_LINE_LENGTH  = 998
The maximum line length allowed by RFC 2822 section 2.1.1.
STD_LINE_LENGTH  = 76
The lower 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.
VERSION  = '6.5.1'
The PHPMailer Version number.
$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|LoggerInterface
How to handle debug output.
$DKIM_copyHeaderFields  : bool
DKIM Copy header field values for diagnostic use.
$DKIM_domain  : string
DKIM signing domain name.
$DKIM_extraHeaders  : array<string|int, mixed>
DKIM Extra signing headers.
$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.
$dsn  : mixed
Comma separated list of DSN notifications 'NEVER' under no circumstances a DSN must be returned to the sender.
$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/EHLO name used for the SMTP connection.
$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.
$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.
$Port  : int
The default SMTP server port.
$Priority  : int|null
Email priority.
$Sender  : string
The envelope sender 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.
$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 the 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.
$WordWrap  : int
Word-wrap the message body to this number of chars.
$XMailer  : string|null
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.
$IcalMethods  : array<string|int, string>
Value-array of "method" in Contenttype header "text/calendar"
$language  : array<string|int, mixed>
The array of available text strings for the current language.
$lastMessageID  : string
The most recent Message-ID (including angular brackets).
$LE  : string
SMTP RFC standard line ending; Carriage Return, Line Feed.
$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.
$oauth  : OAuth
An instance of the PHPMailer OAuth class.
$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.
$SingleToArray  : array<string|int, mixed>
Storage for addresses when SingleTo is enabled.
$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()  : bool
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 value (not including its label) optimally.
encodeQ()  : string
Encode a string using Q encoding.
encodeQP()  : string
Encode a string in quoted-printable format.
encodeString()  : string
Encode a string in requested format.
filenameToType()  : string
Map a file name to a MIME type.
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.
getLE()  : string
Return the current line break format string.
getMailMIME()  : string
Get the message MIME type headers.
getOAuth()  : OAuth
Get the OAuth instance.
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 by RFC 2822 section 2.1.1.
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.
isValidHost()  : bool
Validate whether a string contains a valid value to use as a hostname or IP address.
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 via the selected mechanism.
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.
quotedString()  : string
If a string contains any "special" characters, double-quote the name, and escape any double quotes with a backslash.
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.
setOAuth()  : mixed
Set an OAuth instance.
setSMTPInstance()  : SMTP
Provide an instance to use for SMTP operations.
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.
stripTrailingWSP()  : string
Remove trailing breaks from a string.
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.
cidExists()  : bool
Check if an embedded attachment is present with this cid.
doCallback()  : mixed
Perform a callback.
edebug()  : mixed
Output debugging info via a user-defined method.
encodeFile()  : string
Encode a file attachment in requested format.
endBoundary()  : string
Return the end of a message boundary.
fileIsAccessible()  : bool
Check whether a file path is safe, accessible, and readable.
generateId()  : string
Create a unique ID to use for boundaries.
getBoundary()  : string
Return the start of a message boundary.
isPermittedPath()  : bool
Check whether a file path is of a permitted type.
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.
setLE()  : mixed
Set the line break format string, e.g. "\r\n".
setMessageType()  : mixed
Set the message type.
smtpSend()  : bool
Send mail via SMTP.
validateEncoding()  : bool
Validate encodings.
mailPassthru()  : bool
Call mail() in a safe_mode-aware fashion.

Constants

CHARSET_ASCII

public mixed CHARSET_ASCII = 'us-ascii'

CHARSET_ISO88591

public mixed CHARSET_ISO88591 = 'iso-8859-1'

CHARSET_UTF8

public mixed CHARSET_UTF8 = 'utf-8'

CONTENT_TYPE_MULTIPART_ALTERNATIVE

public mixed CONTENT_TYPE_MULTIPART_ALTERNATIVE = 'multipart/alternative'

CONTENT_TYPE_MULTIPART_MIXED

public mixed CONTENT_TYPE_MULTIPART_MIXED = 'multipart/mixed'
public mixed CONTENT_TYPE_MULTIPART_RELATED = 'multipart/related'

CONTENT_TYPE_PLAINTEXT

public mixed CONTENT_TYPE_PLAINTEXT = 'text/plain'

CONTENT_TYPE_TEXT_CALENDAR

public mixed CONTENT_TYPE_TEXT_CALENDAR = 'text/calendar'

CONTENT_TYPE_TEXT_HTML

public mixed CONTENT_TYPE_TEXT_HTML = 'text/html'

CRLF

The SMTP standard CRLF line break.

public mixed CRLF = "\r\n"

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

ENCODING_7BIT

public mixed ENCODING_7BIT = '7bit'

ENCODING_8BIT

public mixed ENCODING_8BIT = '8bit'

ENCODING_BASE64

public mixed ENCODING_BASE64 = 'base64'

ENCODING_BINARY

public mixed ENCODING_BINARY = 'binary'

ENCODING_QUOTED_PRINTABLE

public mixed ENCODING_QUOTED_PRINTABLE = 'quoted-printable'

ENCRYPTION_SMTPS

public mixed ENCRYPTION_SMTPS = 'ssl'

ENCRYPTION_STARTTLS

public mixed ENCRYPTION_STARTTLS = 'tls'

FWS

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

public mixed FWS = ' '

ICAL_METHOD_ADD

public mixed ICAL_METHOD_ADD = 'ADD'

ICAL_METHOD_CANCEL

public mixed ICAL_METHOD_CANCEL = 'CANCEL'

ICAL_METHOD_COUNTER

public mixed ICAL_METHOD_COUNTER = 'COUNTER'

ICAL_METHOD_DECLINECOUNTER

public mixed ICAL_METHOD_DECLINECOUNTER = 'DECLINECOUNTER'

ICAL_METHOD_PUBLISH

public mixed ICAL_METHOD_PUBLISH = 'PUBLISH'

ICAL_METHOD_REFRESH

public mixed ICAL_METHOD_REFRESH = 'REFRESH'

ICAL_METHOD_REPLY

public mixed ICAL_METHOD_REPLY = 'REPLY'

ICAL_METHOD_REQUEST

public mixed ICAL_METHOD_REQUEST = 'REQUEST'

MAIL_MAX_LINE_LENGTH

The maximum line length supported by mail().

public int MAIL_MAX_LINE_LENGTH = 63

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

MAX_LINE_LENGTH

The maximum line length allowed by RFC 2822 section 2.1.1.

public int MAX_LINE_LENGTH = 998

STD_LINE_LENGTH

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

public int STD_LINE_LENGTH = 76

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.

STOP_CONTINUE

Error severity: message, likely ok to continue processing.

public int STOP_CONTINUE = 1

STOP_CRITICAL

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

public int STOP_CRITICAL = 2

STOP_MESSAGE

Error severity: message only, continue processing.

public int STOP_MESSAGE = 0

VERSION

The PHPMailer Version number.

public string VERSION = '6.5.1'

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

$AllowEmpty

Whether to allow sending messages with an empty body.

public bool $AllowEmpty = false

$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, 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 = self::CHARSET_ISO88591

$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 = self::CONTENT_TYPE_PLAINTEXT

$Debugoutput

How to handle debug output.

public string|callable|LoggerInterface $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 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;
Tags
see
SMTP::$Debugoutput

$DKIM_copyHeaderFields

DKIM Copy header field values for diagnostic use.

public bool $DKIM_copyHeaderFields = true

$DKIM_domain

DKIM signing domain name.

public string $DKIM_domain = ''
Tags
example

'example.com'

$DKIM_extraHeaders

DKIM Extra signing headers.

public array<string|int, mixed> $DKIM_extraHeaders = []
Tags
example

['List-Unsubscribe', 'List-Help']

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

$DKIM_selector

DKIM selector.

public string $DKIM_selector = ''

$dsn

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

public mixed $dsn = ''

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.

Tags
see
https://tools.ietf.org/html/rfc3461

See section 4.1 for more information about NOTIFY

$Encoding

The message encoding.

public string $Encoding = self::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 = ''

$FromName

The From name of the message.

public string $FromName = ''

$Helo

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

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

Tags
see
PHPMailer::$Helo

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

$Password

SMTP password.

public string $Password = ''

$Port

The default SMTP server port.

public int $Port = 25

$Priority

Email priority.

public int|null $Priority

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

$Sender

The envelope sender of the message.

public string $Sender = ''

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.

$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 = false

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

Tags
deprecated
6.0.0

PHPMailer isn't a mailing list manager!

$SMTPAutoTLS

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

public bool $SMTPAutoTLS = true

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:

Tags
see

SMTP::DEBUG_OFF: No output

see

SMTP::DEBUG_CLIENT: Client messages

see

SMTP::DEBUG_SERVER: Client and server messages

see

SMTP::DEBUG_CONNECTION: As SERVER plus connection status

see

SMTP::DEBUG_LOWLEVEL: Noisy, low-level data output, rarely needed

see
SMTP::$do_debug

$SMTPKeepAlive

Whether to keep the SMTP connection open after each message.

public bool $SMTPKeepAlive = false

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.

$SMTPOptions

Options array passed to stream_context_create when connecting via SMTP.

public array<string|int, mixed> $SMTPOptions = []

$SMTPSecure

What kind of encryption to use on the SMTP connection.

public string $SMTPSecure = ''

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

$Subject

The Subject of the message.

public string $Subject = ''

$Timeout

The SMTP server timeout in seconds.

public int $Timeout = 300

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

$Username

SMTP username.

public string $Username = ''

$UseSendmailOptions

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

public bool $UseSendmailOptions = true

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

$validator

Which validator to use by default when validating email addresses.

public static string|callable $validator = 'php'

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.

Tags
see
PHPMailer::validateAddress()

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

Tags
see
static::STD_LINE_LENGTH

$XMailer

What to put in the X-Mailer header.

public string|null $XMailer = ''

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

$attachment

The array of attachments.

protected array<string|int, mixed> $attachment = []

$bcc

The array of 'bcc' names and addresses.

protected array<string|int, mixed> $bcc = []

$boundary

The array of MIME boundary strings.

protected array<string|int, mixed> $boundary = []

$cc

The array of 'cc' names and addresses.

protected array<string|int, mixed> $cc = []

$CustomHeader

The array of custom headers.

protected array<string|int, mixed> $CustomHeader = []

$error_count

The number of errors encountered.

protected int $error_count = 0

$exceptions

Whether to throw exceptions for errors.

protected bool $exceptions = false

$IcalMethods

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

protected static array<string|int, string> $IcalMethods = [self::ICAL_METHOD_REQUEST, self::ICAL_METHOD_PUBLISH, self::ICAL_METHOD_REPLY, self::ICAL_METHOD_ADD, self::ICAL_METHOD_CANCEL, self::ICAL_METHOD_REFRESH, self::ICAL_METHOD_COUNTER, self::ICAL_METHOD_DECLINECOUNTER]

$language

The array of available text strings for the current language.

protected array<string|int, mixed> $language = []

$lastMessageID

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

protected string $lastMessageID = ''

$LE

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

protected static string $LE = self::CRLF

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

$oauth

An instance of the PHPMailer OAuth class.

protected OAuth $oauth

$ReplyTo

The array of reply-to names and addresses.

protected array<string|int, mixed> $ReplyTo = []

$ReplyToQueue

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

protected array<string|int, mixed> $ReplyToQueue = []

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.

$SingleToArray

Storage for addresses when SingleTo is enabled.

protected array<string|int, mixed> $SingleToArray = []

$smtp

An instance of the SMTP sender class.

protected SMTP $smtp

$to

The array of 'to' names and addresses.

protected array<string|int, mixed> $to = []

$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

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 = ''
Tags
throws
Exception
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 = self::ENCODING_BASE64 ][, string $type = '' ][, string $disposition = 'attachment' ]) : bool

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

Parameters
$path : string

Path to the attachment

$name : string = ''

Overrides the attachment name

$encoding : string = self::ENCODING_BASE64

File encoding (see $Encoding)

$type : string = ''

MIME type, e.g. image/jpeg; determined automatically from $path if not specified

$disposition : string = 'attachment'

Disposition to use

Tags
throws
Exception
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
throws
Exception
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
throws
Exception
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|null $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 = null

Header value

Tags
throws
Exception
Return values
mixed

addEmbeddedImage()

Add an embedded (inline) attachment from a file.

public addEmbeddedImage(string $path, string $cid[, string $name = '' ][, string $encoding = self::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. Never use a user-supplied path to a file!

Parameters
$path : string

Path to the attachment

$cid : string

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

$name : string = ''

Overrides the attachment name

$encoding : string = self::ENCODING_BASE64

File encoding (see $Encoding)

$type : string = ''

File MIME type

$disposition : string = 'inline'

Disposition to use

Tags
throws
Exception
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 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 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 = ''
Tags
throws
Exception
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 0 containing an address, element 1 containing a name like ['joe@example.com', 'Joe User']

Return values
string

addStringAttachment()

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

public addStringAttachment(string $string, string $filename[, string $encoding = self::ENCODING_BASE64 ][, string $type = '' ][, string $disposition = 'attachment' ]) : bool

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 = self::ENCODING_BASE64

File encoding (see $Encoding)

$type : string = ''

File extension (MIME) type

$disposition : string = 'attachment'

Disposition to use

Tags
throws
Exception
Return values
bool

True on successfully adding an attachment

addStringEmbeddedImage()

Add an embedded stringified attachment.

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

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.

Parameters
$string : string

The attachment binary data

$cid : string

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

$name : string = ''

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.

$encoding : string = self::ENCODING_BASE64

File encoding (see $Encoding), defaults to 'base64'

$type : string = ''

MIME type - will be used in preference to any automatically derived type

$disposition : string = 'inline'

Disposition to use

Tags
throws
Exception
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
Exception
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

Tags
throws
Exception
Return values
string

DKIM_BodyC()

Generate a DKIM canonicalization body.

public DKIM_BodyC(string $body) : string

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

Parameters
$body : string

Message Body

Tags
see
https://tools.ietf.org/html/rfc6376#section-3.4.3
Return values
string

DKIM_HeaderC()

Generate a DKIM canonicalization header.

public DKIM_HeaderC(string $signHeader) : string

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

Parameters
$signHeader : string

Header

Tags
see
https://tools.ietf.org/html/rfc6376#section-3.4.2
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
Exception
Return values
string

The DKIM signature value

encodeHeader()

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

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

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

Parameters
$str : string

The header value to encode

$position : string = 'text'

What context the string will be used in

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#section-4.2
Return values
string

encodeQP()

Encode a string in quoted-printable format.

public encodeQP(string $string) : string

According to RFC2045 section 6.7.

Parameters
$string : string

The text to encode

Return values
string

encodeString()

Encode a string in requested format.

public encodeString(string $str[, string $encoding = self::ENCODING_BASE64 ]) : string

Returns an empty string on failure.

Parameters
$str : string

The text to encode

$encoding : string = self::ENCODING_BASE64

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

Tags
throws
Exception
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

Return values
string

getAllRecipientAddresses()

Allows for public read access to 'all_recipients' property.

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

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>

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>

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

getLE()

Return the current line break format string.

public static getLE() : string
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>

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, or set one with setSMTPInstance.

Return values
SMTP

getToAddresses()

Allows for public read access to 'to' property.

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

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 by RFC 2822 section 2.1.1.

public static hasLineLongerThanMax(string $str) : bool
Parameters
$str : string
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|int $value) : string
Parameters
$name : string
$value : string|int
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 removed for license reasons in #232. Example usage:

//Use default conversion
$plain = $mail->html2text($html);
//Use your own custom converter
$plain = $mail->html2text($html, function($html) {
    $converter = new MyHtml2text($html);
    return $converter->get_text();
});
Parameters
$html : string

The HTML text to convert

$advanced : bool|callable = false

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

idnSupported()

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

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

isValidHost()

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

public static isValidHost(string $host) : bool

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

Parameters
$host : string

The host name or IP address to check

Return values
bool

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- and cross-platform-safe.

Parameters
$path : string

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

$options : int|string = null

Either a PATHINFO_* constant, or a string name to return only the specified piece

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

Parameters
$message : string

HTML message string

$basedir : string = ''

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

$advanced : bool|callable = false

Whether to use the internal HTML to text converter or your own custom converter

Tags
throws
Exception
see
PHPMailer::html2text()
Return values
string

The transformed message body

normalizeBreaks()

Normalize line breaks in a string.

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

What kind of line break to use; defaults to static::$LE

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 static parseAddresses(string $addrstr[, bool $useimap = true ][, mixed $charset = self::CHARSET_ISO88591 ]) : 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

$charset : mixed = self::CHARSET_ISO88591
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 via the selected mechanism.

public postSend() : bool
Tags
throws
Exception
Return values
bool

preSend()

Prepare a message for sending.

public preSend() : bool
Tags
throws
Exception
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 contains 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

quotedString()

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

public static quotedString(string $str) : string
Parameters
$str : string
Tags
see
RFC822

3.4.1

Return values
string

rfcDate()

Return an RFC 822 formatted date.

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

Parameters
$name : string

The property name to set

$value : mixed = ''

The value to set the property to

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
Exception
Return values
bool

setLanguage()

Set the language for error messages.

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

The default language is English.

Parameters
$langcode : string = 'en'

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.

$lang_path : string = ''

Path to the language file directory, with trailing separator (slash) Do not set this from user input!

Return values
bool

Returns true if the requested language was loaded, false otherwise.

setOAuth()

Set an OAuth instance.

public setOAuth(OAuth $oauth) : mixed
Parameters
$oauth : OAuth
Return values
mixed

setSMTPInstance()

Provide an instance to use for SMTP operations.

public setSMTPInstance(SMTP $smtp) : SMTP
Parameters
$smtp : SMTP
Return values
SMTP

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
throws
Exception
uses
SMTP
Return values
bool

stripTrailingWSP()

Remove trailing breaks from a string.

public static stripTrailingWSP(string $text) : string
Parameters
$text : string
Return values
string

The text to remove breaks from

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

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.

Parameters
$address : string

The email address to check

$patternselect : string|callable = null

Which pattern to use

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
Exception
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
Exception
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
Tags
throws
Exception
Return values
string

cidExists()

Check if an embedded attachment is present with this cid.

protected cidExists(string $cid) : bool
Parameters
$cid : string
Return values
bool

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, array<string|int, mixed> $extra) : 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
$extra : array<string|int, mixed>
Return values
mixed

encodeFile()

Encode a file attachment in requested format.

protected encodeFile(string $path[, string $encoding = self::ENCODING_BASE64 ]) : string

Returns an empty string on failure.

Parameters
$path : string

The full path to the file

$encoding : string = self::ENCODING_BASE64

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

Return values
string

endBoundary()

Return the end of a message boundary.

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

fileIsAccessible()

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

protected static fileIsAccessible(string $path) : bool
Parameters
$path : string

A relative or absolute path to a file

Return values
bool

generateId()

Create a unique ID to use for boundaries.

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

isPermittedPath()

Check whether a file path is of a permitted type.

protected static isPermittedPath(string $path) : bool

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

Parameters
$path : string

A relative or absolute path to a file

Return values
bool

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

setLE()

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

protected static setLE(string $le) : mixed
Parameters
$le : 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.

Parameters
$header : string

The message headers

$body : string

The message body

Tags
see
PHPMailer::setSMTPInstance()

to use a different class.

uses
SMTP
throws
Exception
Return values
bool

validateEncoding()

Validate encodings.

protected validateEncoding(string $encoding) : bool
Parameters
$encoding : string
Return values
bool

mailPassthru()

Call mail() in a safe_mode-aware fashion.

private mailPassthru(string $to, string $subject, string $body, string $header, string|null $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|null

Params

Return values
bool

Search results