PHP Class PHPMailer\PHPMailer\PHPMailer

Author: Marcus Bointon (Synchro/coolbru) ([email protected])
Author: Jim Jagielski (jimjag) ([email protected])
Author: Andy Prevost (codeworxtech) ([email protected])
Author: Brent R. Matzelle (original founder)
Mostra file Open project: nukeviet/nukeviet Class Usage Examples

Public Properties

Property Type Description
$AllowEmpty boolean Whether to allow sending messages with an empty body.
$AltBody string 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 string Options are LOGIN (default), PLAIN, NTLM, CRAM-MD5, XOAUTH2
$Body string If HTML then call isHTML(true).
$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.
$DKIM_domain string DKIM signing domain name.
$DKIM_identity string Usually the email address used as the source of the email
$DKIM_passphrase string Used if your key is encrypted.
$DKIM_private string DKIM private key file path.
$DKIM_selector string DKIM selector.
$Debugoutput string | callable Options: * echo Output plain-text as-is, appropriate for CLI * html Output escaped, line breaks converted to
, 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";};
$Encoding string Options: "8bit", "7bit", "binary", "base64", and "quoted-printable".
$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 Default is $Hostname. If $Hostname is empty, PHPMailer attempts to find one with the same method described above for $Hostname.
$Host string 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 string If empty, PHPMailer attempts to find one with, in order, $_SERVER['SERVER_NAME'], gethostname(), php_uname('n'), or the value 'localhost.localdomain'.
$Ical string Only supported in simple alt or alt_inline message types To generate iCal events, use the bundled extras/EasyPeasyICS.php class or iCalcreator
$LE string The default line ending.
$Mailer string Options: "mail", "sendmail", or "smtp".
$MessageDate string If empty, the current date will be added.
$MessageID string If empty, a unique id will be generated.
$Password string SMTP password.
$Port integer The default SMTP server port.
$Priority integer Options: null (default), 1 = High, 3 = Normal, 5 = low. When null, the header is not set at all.
$SMTPAuth boolean Uses the Username and Password properties.
$SMTPAutoTLS boolean Be aware that in PHP >= 5.6 this requires that the server's certificates are valid.
$SMTPDebug integer Debug output level. Options: * 0 No output * 1 Commands * 2 Data and commands * 3 As 2 plus connection status * 4 Low-level data output
$SMTPKeepAlive boolean If this is set to true then to close the connection requires an explicit call to smtpClose().
$SMTPOptions array Options array passed to stream_context_create when connecting via SMTP.
$SMTPSecure string Options: '', 'ssl' or 'tls'
$Sender string If not empty, will be sent via -f to sendmail or as 'MAIL FROM' in smtp mode.
$Sendmail string The path to the sendmail program.
$SingleTo boolean Only supported in mail and sendmail transports, not in SMTP.
$Subject string The Subject of the message.
$Timeout integer Default of 5 minutes (300sec) is from RFC2821 section 4.5.3.2
$UseSendmailOptions boolean One which supports sendmail's "-oi -f" options.
$Username string SMTP username.
$WordWrap integer Set to 0 to not wrap. A useful value here is 78, for RFC2822 section 2.1.1 compliance.
$XMailer string Options: An empty string for PHPMailer default, whitespace for none, or a string to use
$action_function string The function that handles the result of the send email action. It is called out by send() for each email sent. Value can be 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
$do_verp boolean Only applicable when sending via SMTP.
$validator string | callable May be a callable to inject your own validator, but there are several built-in validators.

Protected Properties

Property Type Description
$CustomHeader array The array of custom headers.
$MIMEBody string The complete compiled MIME message body.
$MIMEHeader string The complete compiled MIME message headers.
$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.
$ReplyTo array The array of reply-to names and addresses.
$ReplyToQueue array In send(), valid and non duplicate entries are moved to $ReplyTo. This array is used only for addresses with IDN.
$SingleToArray array Storage for addresses when SingleTo is enabled.
$all_recipients array Includes all of $to, $cc, $bcc
$attachment array The array of attachments.
$bcc array The array of 'bcc' names and addresses.
$boundary array The array of MIME boundary strings.
$cc array The array of 'cc' names and addresses.
$error_count integer The number of errors encountered.
$exceptions boolean Whether to throw exceptions for errors.
$language array 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.
$oauth OAuth An instance of the PHPMailer OAuth class.
$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 Used only if the key is encrypted.
$smtp SMTP An instance of the SMTP sender class.
$to array The array of 'to' names and addresses.
$uniqueid string Unique ID used for message ID and boundaries.

Public Methods

Method Description
DKIM_Add ( string $headers_line, string $subject, string $body ) : string Create the DKIM header and body in a new message header.
DKIM_BodyC ( string $body ) : string Generate a DKIM canonicalization body.
DKIM_HeaderC ( string $signHeader ) : string Generate a DKIM canonicalization header.
DKIM_QP ( string $txt ) : string Quoted-Printable-encode a DKIM header.
DKIM_Sign ( string $signHeader ) : string Generate a DKIM signature.
__construct ( boolean $exceptions = null ) Constructor.
__destruct ( ) Destructor.
_mime_types ( string $ext = '' ) : string Get the MIME type for a file extension.
addAddress ( string $address, string $name = '' ) : boolean Add a "To" address.
addAttachment ( string $path, string $name = '', string $encoding = 'base64', string $type = '', string $disposition = 'attachment' ) : boolean Add an attachment from a path on the filesystem.
addBCC ( string $address, string $name = '' ) : boolean Add a "BCC" address.
addCC ( string $address, string $name = '' ) : boolean Add a "CC" address.
addCustomHeader ( string $name, string $value = null ) : void Add a custom header.
addEmbeddedImage ( string $path, string $cid, string $name = '', string $encoding = 'base64', string $type = '', string $disposition = 'inline' ) : boolean Add an embedded (inline) attachment from a file.
addReplyTo ( string $address, string $name = '' ) : boolean Add a "Reply-To" address.
addStringAttachment ( string $string, string $filename, string $encoding = 'base64', string $type = '', string $disposition = 'attachment' ) : void Add a string or binary attachment (non-filesystem).
addStringEmbeddedImage ( string $string, string $cid, string $name = '', string $encoding = 'base64', string $type = '', string $disposition = 'inline' ) : boolean Add an embedded stringified attachment.
addrAppend ( string $type, array $addr ) : string Create recipient headers.
addrFormat ( array $addr ) : string Format an address for use in a message header.
alternativeExists ( ) : boolean Check if this message has an alternative body set.
attachmentExists ( ) : boolean Check if an attachment (non-inline) is present.
base64EncodeWrapMB ( string $str, string $linebreak = null ) : string Encode and wrap long multibyte strings for mail headers without breaking lines within a character.
clearAddresses ( ) : void Clear all To recipients.
clearAllRecipients ( ) : void Clear all recipient types.
clearAttachments ( ) : void Clear all filesystem, string, and binary attachments.
clearBCCs ( ) : void Clear all BCC recipients.
clearCCs ( ) : void Clear all CC recipients.
clearCustomHeaders ( ) : void Clear all custom headers.
clearQueuedAddresses ( string $kind ) : void Clear queued addresses of given kind.
clearReplyTos ( ) : void Clear all ReplyTo recipients.
createBody ( ) : string Assemble the message body.
createHeader ( ) : string Assemble message headers.
encodeHeader ( string $str, string $position = 'text' ) : string Encode a header string optimally.
encodeQ ( string $str, string $position = 'text' ) : string Encode a string using Q encoding.
encodeQP ( string $string ) : string Encode a string in quoted-printable format.
encodeString ( string $str, string $encoding = 'base64' ) : string Encode a string in requested format.
filenameToType ( string $filename ) : string Map a file name to a MIME type.
fixEOL ( string $str ) : string Ensure consistent line endings in a string.
getAllRecipientAddresses ( ) : array Allows for public read access to 'all_recipients' property.
getAttachments ( ) : array Return the array of attachments.
getBccAddresses ( ) : array Allows for public read access to 'bcc' property.
getCcAddresses ( ) : array Allows for public read access to 'cc' property.
getCustomHeaders ( ) : array Returns all custom headers.
getLastMessageID ( ) : string Return the Message-ID header of the last email.
getMailMIME ( ) : string Get the message MIME type headers.
getOAuth ( ) : OAuth Get the OAuth instance.
getReplyToAddresses ( ) : array Allows for public read access to 'ReplyTo' property.
getSMTPInstance ( ) : SMTP Get an instance to use for SMTP operations.
getSentMIMEMessage ( ) : string Returns the whole MIME message.
getToAddresses ( ) : array Allows for public read access to 'to' property.
getTranslations ( ) : array Get the array of strings for the current language.
has8bitChars ( string $text ) : boolean Does a string contain any 8-bit chars (in any charset)?
hasLineLongerThanMax ( string $str ) : boolean Detect if a string contains a line longer than the maximum line length allowed.
hasMultiBytes ( string $str ) : boolean Check if a string contains multi-byte characters.
headerLine ( string $name, string $value ) : string Format a header line.
html2text ( string $html, boolean | callable $advanced = false ) : string Convert an HTML string into plain text.
idnSupported ( ) : boolean Tells whether IDNs (Internationalized Domain Names) are supported or not. This requires the "intl" and "mbstring" PHP extensions.
inlineImageExists ( ) : boolean Check if an inline attachment is present.
isError ( ) : boolean Check if an error occurred.
isHTML ( boolean $isHtml = true ) : void Sets message type to HTML or plain.
isMail ( ) : void Send messages using PHP's mail() function.
isQmail ( ) : void Send messages using qmail.
isSMTP ( ) : void Send messages using SMTP.
isSendmail ( ) : void Send messages using $Sendmail.
mb_pathinfo ( string $path, integer | string $options = null ) : string | array Multi-byte-safe pathinfo replacement.
msgHTML ( string $message, string $basedir = '', boolean | callable $advanced = false ) : string Create a message from an HTML string.
normalizeBreaks ( string $text, string $breaktype = " " ) : string Normalize line breaks in a string.
parseAddresses ( string $addrstr, boolean $useimap = true ) : array Parse and validate a string containing one or more RFC822-style comma-separated email addresses of the form "display name
" into an array of name/address pairs.
postSend ( ) : boolean Actually send a message.
preSend ( ) : boolean Prepare a message for sending.
punyencodeAddress ( string $address ) : 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 $str ) : string Strip newlines to prevent header injection.
send ( ) : boolean Create a message and send it.
set ( string $name, mixed $value = '' ) : boolean Set or reset instance properties.
setFrom ( string $address, string $name = '', boolean $auto = true ) : boolean Set the From and FromName properties.
setLanguage ( string $langcode = 'en', string $lang_path = '' ) : boolean Set the language for error messages.
setOAuth ( OAuth $oauth ) Set an OAuth instance.
setWordWrap ( ) : void Apply word wrapping to the message body.
sign ( string $cert_filename, string $key_filename, string $key_pass, string $extracerts_filename = '' ) Set the public and private key files and password for S/MIME signing.
smtpClose ( ) : void Close the active SMTP session if one exists.
smtpConnect ( array $options = [] ) : boolean Initiate a connection to an SMTP server.
textLine ( string $value ) : string Return a formatted mail line.
utf8CharBoundary ( string $encodedText, integer $maxLength ) : integer Find the last character boundary prior to $maxLength in a utf-8 quoted-printable encoded string.
validateAddress ( string $address, string | callable $patternselect = null ) : boolean Check that a string looks like an email address.
wrapText ( string $message, integer $length, boolean $qp_mode = false ) : string Word-wrap message.

Protected Methods

Method Description
addAnAddress ( string $kind, string $address, string $name = '' ) : boolean Add an address to one of the recipient arrays or to the ReplyTo array.
addOrEnqueueAnAddress ( string $kind, string $address, string $name ) : boolean 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 $disposition_type, string $boundary ) : string Attach all file, string, and binary attachments to the message.
cidExists ( $cid ) : boolean Check if an embedded attachment is present with this cid.
doCallback ( boolean $isSent, array $to, array $cc, array $bcc, string $subject, string $body, string $from ) Perform a callback.
edebug ( string $str ) Output debugging info via user-defined method.
encodeFile ( string $path, string $encoding = 'base64' ) : string Encode a file attachment in requested format.
endBoundary ( string $boundary ) : string Return the end of a message boundary.
getBoundary ( string $boundary, string $charSet, string $contentType, string $encoding ) : string Return the start of a message boundary.
lang ( string $key ) : string Get an error message in the current language.
mailSend ( string $header, string $body ) : boolean Send mail using the PHP mail() function.
sendmailSend ( string $header, string $body ) : boolean Send mail using the $Sendmail program.
serverHostname ( ) : string Get the server hostname.
setError ( string $msg ) : void Add an error message to the error container.
setMessageType ( ) : void Set the message type.
smtpSend ( string $header, string $body ) : boolean Send mail via SMTP.

Private Methods

Method Description
mailPassthru ( string $to, string $subject, string $body, string $header, string $params ) : boolean Call mail() in a safe_mode-aware fashion.

Method Details

DKIM_Add() public method

Create the DKIM header and body in a new message header.
public DKIM_Add ( string $headers_line, string $subject, string $body ) : string
$headers_line string Header lines
$subject string Subject
$body string Body
return string

DKIM_BodyC() public method

Uses the 'simple' algorithm from RFC6376 section 3.4.3
public DKIM_BodyC ( string $body ) : string
$body string Message Body
return string

DKIM_HeaderC() public method

Uses the 'relaxed' algorithm from RFC6376 section 3.4.2
public DKIM_HeaderC ( string $signHeader ) : string
$signHeader string Header
return string

DKIM_QP() public method

Quoted-Printable-encode a DKIM header.
public DKIM_QP ( string $txt ) : string
$txt string
return string

DKIM_Sign() public method

Generate a DKIM signature.
public DKIM_Sign ( string $signHeader ) : string
$signHeader string
return string

__construct() public method

Constructor.
public __construct ( boolean $exceptions = null )
$exceptions boolean Should we throw external exceptions?

__destruct() public method

Destructor.
public __destruct ( )

_mime_types() public static method

Get the MIME type for a file extension.
public static _mime_types ( string $ext = '' ) : string
$ext string File extension
return string MIME type of file.

addAddress() public method

Add a "To" address.
public addAddress ( string $address, string $name = '' ) : boolean
$address string The email address to send to
$name string
return boolean true on success, false if address already used or invalid in some way

addAnAddress() protected method

Addresses that have been added already return false, but do not throw exceptions.
protected addAnAddress ( string $kind, string $address, string $name = '' ) : boolean
$kind string One of 'to', 'cc', 'bcc', or 'ReplyTo'
$address string The email address to send, resp. to reply to
$name string
return boolean true on success, false if address already used or invalid in some way

addAttachment() public method

Returns false if the file could not be found or read.
public addAttachment ( string $path, string $name = '', string $encoding = 'base64', string $type = '', string $disposition = 'attachment' ) : boolean
$path string Path to the attachment.
$name string Overrides the attachment name.
$encoding string File encoding (see $Encoding).
$type string File extension (MIME) type.
$disposition string Disposition to use
return boolean

addBCC() public method

Add a "BCC" address.
public addBCC ( string $address, string $name = '' ) : boolean
$address string The email address to send to
$name string
return boolean true on success, false if address already used or invalid in some way

addCC() public method

Add a "CC" address.
public addCC ( string $address, string $name = '' ) : boolean
$address string The email address to send to
$name string
return boolean true on success, false if address already used or invalid in some way

addCustomHeader() public method

$name value can be overloaded to contain both header name and value (name:value)
public addCustomHeader ( string $name, string $value = null ) : void
$name string Custom header name
$value string Header value
return void

addEmbeddedImage() public method

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.
public addEmbeddedImage ( string $path, string $cid, string $name = '', string $encoding = 'base64', string $type = '', string $disposition = 'inline' ) : boolean
$path string Path to the attachment.
$cid string Content ID of the attachment; Use this to reference the content when using an embedded image in HTML.
$name string Overrides the attachment name.
$encoding string File encoding (see $Encoding).
$type string File MIME type.
$disposition string Disposition to use
return boolean True on successfully adding an attachment

addOrEnqueueAnAddress() protected method

Addresses that have been added already return false, but do not throw exceptions.
protected addOrEnqueueAnAddress ( string $kind, string $address, string $name ) : boolean
$kind string One of 'to', 'cc', 'bcc', or 'ReplyTo'
$address string The email address to send, resp. to reply to
$name string
return boolean true on success, false if address already used or invalid in some way

addReplyTo() public method

Add a "Reply-To" address.
public addReplyTo ( string $address, string $name = '' ) : boolean
$address string The email address to reply to
$name string
return boolean true on success, false if address already used or invalid in some way

addStringAttachment() public method

This method can be used to attach ascii or binary data, such as a BLOB record from a database.
public addStringAttachment ( string $string, string $filename, string $encoding = 'base64', string $type = '', string $disposition = 'attachment' ) : void
$string string String attachment data.
$filename string Name of the attachment.
$encoding string File encoding (see $Encoding).
$type string File extension (MIME) type.
$disposition string Disposition to use
return void

addStringEmbeddedImage() public method

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'.
public addStringEmbeddedImage ( string $string, string $cid, string $name = '', string $encoding = 'base64', string $type = '', string $disposition = 'inline' ) : boolean
$string string The attachment binary data.
$cid string Content ID of the attachment; Use this to reference the content when using an embedded image in HTML.
$name string
$encoding string File encoding (see $Encoding).
$type string MIME type.
$disposition string Disposition to use
return boolean True on successfully adding an attachment

addrAppend() public method

Create recipient headers.
public addrAppend ( string $type, array $addr ) : string
$type string
$addr array An array of recipient, where each recipient is a 2-element indexed array with element 0 containing an address and element 1 containing a name, like: [['[email protected]', 'Joe User'], ['[email protected]', 'Zoe User']]
return string

addrFormat() public method

Format an address for use in a message header.
public addrFormat ( array $addr ) : string
$addr array A 2-element indexed array, element 0 containing an address, element 1 containing a name like ['[email protected]', 'Joe User']
return string

alternativeExists() public method

Check if this message has an alternative body set.
public alternativeExists ( ) : boolean
return boolean

attachAll() protected method

Returns an empty string on failure.
protected attachAll ( string $disposition_type, string $boundary ) : string
$disposition_type string
$boundary string
return string

attachmentExists() public method

Check if an attachment (non-inline) is present.
public attachmentExists ( ) : boolean
return boolean

base64EncodeWrapMB() public method

Adapted from a function by paravoid
public base64EncodeWrapMB ( string $str, string $linebreak = null ) : string
$str string multi-byte text to wrap encode
$linebreak string string to use as linefeed/end-of-line
return string

cidExists() protected method

Check if an embedded attachment is present with this cid.
protected cidExists ( $cid ) : boolean
$cid
return boolean

clearAddresses() public method

Clear all To recipients.
public clearAddresses ( ) : void
return void

clearAllRecipients() public method

Clear all recipient types.
public clearAllRecipients ( ) : void
return void

clearAttachments() public method

Clear all filesystem, string, and binary attachments.
public clearAttachments ( ) : void
return void

clearBCCs() public method

Clear all BCC recipients.
public clearBCCs ( ) : void
return void

clearCCs() public method

Clear all CC recipients.
public clearCCs ( ) : void
return void

clearCustomHeaders() public method

Clear all custom headers.
public clearCustomHeaders ( ) : void
return void

clearQueuedAddresses() public method

Clear queued addresses of given kind.
public clearQueuedAddresses ( string $kind ) : void
$kind string 'to', 'cc', or 'bcc'
return void

clearReplyTos() public method

Clear all ReplyTo recipients.
public clearReplyTos ( ) : void
return void

createBody() public method

Returns an empty string on failure.
public createBody ( ) : string
return string The assembled message body

createHeader() public method

Assemble message headers.
public createHeader ( ) : string
return string The assembled headers

doCallback() protected method

Perform a callback.
protected doCallback ( boolean $isSent, array $to, array $cc, array $bcc, string $subject, string $body, string $from )
$isSent boolean
$to array
$cc array
$bcc array
$subject string
$body string
$from string

edebug() protected method

Only generates output if SMTP debug output is enabled (@see SMTP::$do_debug).
See also: PHPMailer::$Debugoutput
See also: PHPMailer::$SMTPDebug
protected edebug ( string $str )
$str string

encodeFile() protected method

Returns an empty string on failure.
protected encodeFile ( string $path, string $encoding = 'base64' ) : string
$path string The full path to the file
$encoding string The encoding to use; one of 'base64', '7bit', '8bit', 'binary', 'quoted-printable'
return string

encodeHeader() public method

Picks shortest of Q, B, quoted-printable or none.
public encodeHeader ( string $str, string $position = 'text' ) : string
$str string
$position string
return string

encodeQ() public method

Encode a string using Q encoding.
public encodeQ ( string $str, string $position = 'text' ) : string
$str string the text to encode
$position string Where the text is going to be used, see the RFC for what that means
return string

encodeQP() public method

According to RFC2045 section 6.7.
public encodeQP ( string $string ) : string
$string string The text to encode
return string

encodeString() public method

Returns an empty string on failure.
public encodeString ( string $str, string $encoding = 'base64' ) : string
$str string The text to encode
$encoding string The encoding to use; one of 'base64', '7bit', '8bit', 'binary', 'quoted-printable'
return string

endBoundary() protected method

Return the end of a message boundary.
protected endBoundary ( string $boundary ) : string
$boundary string
return string

filenameToType() public static method

Defaults to 'application/octet-stream', i.e.. arbitrary binary data.
public static filenameToType ( string $filename ) : string
$filename string A file name or full path, does not need to exist as a file
return string

fixEOL() public method

Changes every end of line from CRLF, CR or LF to $this->LE.
public fixEOL ( string $str ) : string
$str string String to fixEOL
return string

getAllRecipientAddresses() public method

Allows for public read access to 'all_recipients' property.
public getAllRecipientAddresses ( ) : array
return array

getAttachments() public method

Return the array of attachments.
public getAttachments ( ) : array
return array

getBccAddresses() public method

Allows for public read access to 'bcc' property.
public getBccAddresses ( ) : array
return array

getBoundary() protected method

Return the start of a message boundary.
protected getBoundary ( string $boundary, string $charSet, string $contentType, string $encoding ) : string
$boundary string
$charSet string
$contentType string
$encoding string
return string

getCcAddresses() public method

Allows for public read access to 'cc' property.
public getCcAddresses ( ) : array
return array

getCustomHeaders() public method

Returns all custom headers.
public getCustomHeaders ( ) : array
return array

getLastMessageID() public method

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.
public getLastMessageID ( ) : string
return string

getMailMIME() public method

Get the message MIME type headers.
public getMailMIME ( ) : string
return string

getOAuth() public method

Get the OAuth instance.
public getOAuth ( ) : OAuth
return OAuth

getReplyToAddresses() public method

Allows for public read access to 'ReplyTo' property.
public getReplyToAddresses ( ) : array
return array

getSMTPInstance() public method

Override this function to load your own SMTP implementation
public getSMTPInstance ( ) : SMTP
return SMTP

getSentMIMEMessage() public method

Includes complete headers and body. Only valid post preSend().
See also: PHPMailer::preSend()
public getSentMIMEMessage ( ) : string
return string

getToAddresses() public method

Allows for public read access to 'to' property.
public getToAddresses ( ) : array
return array

getTranslations() public method

Get the array of strings for the current language.
public getTranslations ( ) : array
return array

has8bitChars() public method

Does a string contain any 8-bit chars (in any charset)?
public has8bitChars ( string $text ) : boolean
$text string
return boolean

hasLineLongerThanMax() public static method

Detect if a string contains a line longer than the maximum line length allowed.
public static hasLineLongerThanMax ( string $str ) : boolean
$str string
return boolean

hasMultiBytes() public method

Check if a string contains multi-byte characters.
public hasMultiBytes ( string $str ) : boolean
$str string multi-byte text to wrap encode
return boolean

headerLine() public method

Format a header line.
public headerLine ( string $name, string $value ) : string
$name string
$value string
return string

html2text() public method

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(); });
public html2text ( string $html, boolean | callable $advanced = false ) : string
$html string The HTML text to convert
$advanced boolean | callable Any boolean value to use the internal converter, or provide your own callable for custom conversion.
return string

idnSupported() public method

Tells whether IDNs (Internationalized Domain Names) are supported or not. This requires the "intl" and "mbstring" PHP extensions.
public idnSupported ( ) : boolean
return boolean "true" if required functions for IDN support are present

inlineImageExists() public method

Check if an inline attachment is present.
public inlineImageExists ( ) : boolean
return boolean

isError() public method

Check if an error occurred.
public isError ( ) : boolean
return boolean True if an error did occur.

isHTML() public method

Sets message type to HTML or plain.
public isHTML ( boolean $isHtml = true ) : void
$isHtml boolean True for HTML mode.
return void

isMail() public method

Send messages using PHP's mail() function.
public isMail ( ) : void
return void

isQmail() public method

Send messages using qmail.
public isQmail ( ) : void
return void

isSMTP() public method

Send messages using SMTP.
public isSMTP ( ) : void
return void

isSendmail() public method

Send messages using $Sendmail.
public isSendmail ( ) : void
return void

lang() protected method

Get an error message in the current language.
protected lang ( string $key ) : string
$key string
return string

mailSend() protected method

Send mail using the PHP mail() function.
protected mailSend ( string $header, string $body ) : boolean
$header string The message headers
$body string The message body
return boolean

mb_pathinfo() public static method

Drop-in replacement for pathinfo(), but multibyte- and cross-platform-safe
public static mb_pathinfo ( string $path, integer | string $options = null ) : string | array
$path string A filename or path, does not need to exist as a file
$options integer | string Either a PATHINFO_* constant, or a string name to return only the specified piece
return string | array

msgHTML() public method

Automatically makes modifications for inline images and backgrounds and creates a plain-text version by converting the HTML. Overwrites any existing values in $this->Body and $this->AltBody
public msgHTML ( string $message, string $basedir = '', boolean | callable $advanced = false ) : string
$message string HTML message string
$basedir string baseline directory for path, with or without a trailing slash
$advanced boolean | callable Whether to use the internal HTML to text converter or your own custom converter @see PHPMailer::html2text()
return string $message

normalizeBreaks() public static method

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.
public static normalizeBreaks ( string $text, string $breaktype = " " ) : string
$text string
$breaktype string What kind of line break to use, defaults to CRLF
return string

parseAddresses() public static method

Uses the imap_rfc822_parse_adrlist function if the IMAP extension is available. Note that quotes in the name part are removed.
public static parseAddresses ( string $addrstr, boolean $useimap = true ) : array
$addrstr string The address list string
$useimap boolean Whether to use the IMAP extension to parse the list
return array

postSend() public method

Send the email via the selected mechanism
public postSend ( ) : boolean
return boolean

preSend() public method

Prepare a message for sending.
public preSend ( ) : boolean
return boolean

punyencodeAddress() public method

Important: Address must be passed in same encoding as currently set in PHPMailer::$CharSet. This function silently returns unmodified address if: - No conversion is necessary (i.e. domain name is not an IDN, or is already in ASCII form) - Conversion to punycode is impossible (e.g. required PHP functions are not available) or fails for any reason (e.g. domain has characters not allowed in an IDN)
See also: PHPMailer::$CharSet
public punyencodeAddress ( string $address ) : string
$address string The email address to convert
return string The encoded address in ASCII form

rfcDate() public static method

Return an RFC 822 formatted date.
public static rfcDate ( ) : string
return string

secureHeader() public method

Strip newlines to prevent header injection.
public secureHeader ( string $str ) : string
$str string
return string

send() public method

Uses the sending method specified by $Mailer.
public send ( ) : boolean
return boolean false on error - See the ErrorInfo property for details of the error.

sendmailSend() protected method

Send mail using the $Sendmail program.
See also: PHPMailer::$Sendmail
protected sendmailSend ( string $header, string $body ) : boolean
$header string The message headers
$body string The message body
return boolean

serverHostname() protected method

Returns 'localhost.localdomain' if unknown.
protected serverHostname ( ) : string
return string

set() public method

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';
public set ( string $name, mixed $value = '' ) : boolean
$name string The property name to set
$value mixed The value to set the property to
return boolean

setError() protected method

Add an error message to the error container.
protected setError ( string $msg ) : void
$msg string
return void

setFrom() public method

Set the From and FromName properties.
public setFrom ( string $address, string $name = '', boolean $auto = true ) : boolean
$address string
$name string
$auto boolean Whether to also set the Sender address, defaults to true
return boolean

setLanguage() public method

Returns false if it cannot load the language file. The default language is English.
public setLanguage ( string $langcode = 'en', string $lang_path = '' ) : boolean
$langcode string ISO 639-1 2-character language code (e.g. French is "fr")
$lang_path string Path to the language file directory, with trailing separator (slash)
return boolean

setMessageType() protected method

PHPMailer only supports some preset message types, not arbitrary MIME structures.
protected setMessageType ( ) : void
return void

setOAuth() public method

Set an OAuth instance.
public setOAuth ( OAuth $oauth )
$oauth OAuth

setWordWrap() public method

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

sign() public method

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 = '' )
$cert_filename string
$key_filename string
$key_pass string Password for private key
$extracerts_filename string Optional path to chain certificate

smtpClose() public method

Close the active SMTP session if one exists.
public smtpClose ( ) : void
return void

smtpConnect() public method

Returns false if the operation failed.
public smtpConnect ( array $options = [] ) : boolean
$options array An array of options compatible with stream_context_create()
return boolean

smtpSend() protected method

Returns false if there is a bad MAIL FROM, RCPT, or DATA input. Uses the PHPMailerSMTP class by default.
See also: PHPMailer::getSMTPInstance() to use a different class.
protected smtpSend ( string $header, string $body ) : boolean
$header string The message headers
$body string The message body
return boolean

textLine() public method

Return a formatted mail line.
public textLine ( string $value ) : string
$value string
return string

utf8CharBoundary() public method

Original written by Colin Brown.
public utf8CharBoundary ( string $encodedText, integer $maxLength ) : integer
$encodedText string utf-8 QP text
$maxLength integer Find the last character boundary prior to this length
return integer

validateAddress() public static method

Check that a string looks like an email address.
public static validateAddress ( string $address, string | callable $patternselect = null ) : boolean
$address string The email address to check
$patternselect string | callable A selector for the validation pattern to use : * `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('[email protected]', 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.
return boolean

wrapText() public method

For use with mailers that do not automatically perform wrapping and for quoted-printable encoded messages. Original written by philippe.
public wrapText ( string $message, integer $length, boolean $qp_mode = false ) : string
$message string The message to wrap
$length integer The line length to wrap to
$qp_mode boolean Whether to run in Quoted-Printable mode
return string

Property Details

$AllowEmpty public_oe property

Whether to allow sending messages with an empty body.
public bool $AllowEmpty
return boolean

$AltBody public_oe property

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.
public string $AltBody
return string

$AuthType public_oe property

Options are LOGIN (default), PLAIN, NTLM, CRAM-MD5, XOAUTH2
public string $AuthType
return string

$Body public_oe property

If HTML then call isHTML(true).
public string $Body
return string

$CharSet public_oe property

The character set of the message.
public string $CharSet
return string

$ConfirmReadingTo public_oe property

The email address that a reading confirmation should be sent to, also known as read receipt.
public string $ConfirmReadingTo
return string

$ContentType public_oe property

The MIME Content-type of the message.
public string $ContentType
return string

$CustomHeader protected_oe property

The array of custom headers.
protected array $CustomHeader
return array

$DKIM_domain public_oe property

DKIM signing domain name.
public string $DKIM_domain
return string

$DKIM_identity public_oe property

Usually the email address used as the source of the email
public string $DKIM_identity
return string

$DKIM_passphrase public_oe property

Used if your key is encrypted.
public string $DKIM_passphrase
return string

$DKIM_private public_oe property

DKIM private key file path.
public string $DKIM_private
return string

$DKIM_selector public_oe property

DKIM selector.
public string $DKIM_selector
return string

$Debugoutput public_oe property

Options: * echo Output plain-text as-is, appropriate for CLI * html Output escaped, line breaks converted to
, 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";};
See also: SMTP::$Debugoutput
public string|callable $Debugoutput
return string | callable

$Encoding public_oe property

Options: "8bit", "7bit", "binary", "base64", and "quoted-printable".
public string $Encoding
return string

$ErrorInfo public_oe property

Holds the most recent mailer error message.
public string $ErrorInfo
return string

$From public_oe property

The From email address for the message.
public string $From
return string

$FromName public_oe property

The From name of the message.
public string $FromName
return string

$Helo public_oe property

Default is $Hostname. If $Hostname is empty, PHPMailer attempts to find one with the same method described above for $Hostname.
See also: PHPMailer::$Hostname
public string $Helo
return string

$Host public_oe property

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

$Hostname public_oe property

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

$Ical public_oe property

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

$LE public_oe property

The default line ending.
public string $LE
return string

$MIMEBody protected_oe property

The complete compiled MIME message body.
protected string $MIMEBody
return string

$MIMEHeader protected_oe property

The complete compiled MIME message headers.
protected string $MIMEHeader
return string

$Mailer public_oe property

Options: "mail", "sendmail", or "smtp".
public string $Mailer
return string

$MessageDate public_oe property

If empty, the current date will be added.
public string $MessageDate
return string

$MessageID public_oe property

If empty, a unique id will be generated.
public string $MessageID
return string

$Password public_oe property

SMTP password.
public string $Password
return string

$Port public_oe property

The default SMTP server port.
public int $Port
return integer

$Priority public_oe property

Options: null (default), 1 = High, 3 = Normal, 5 = low. When null, the header is not set at all.
public int $Priority
return integer

$RecipientsQueue protected_oe property

In send(), valid and non duplicate entries are moved to $all_recipients and one of $to, $cc, or $bcc. This array is used only for addresses with IDN.
See also: PHPMailer::$to @see PHPMailer::$cc @see PHPMailer::$bcc
See also: PHPMailer::$all_recipients
protected array $RecipientsQueue
return array

$ReplyTo protected_oe property

The array of reply-to names and addresses.
protected array $ReplyTo
return array

$ReplyToQueue protected_oe property

In send(), valid and non duplicate entries are moved to $ReplyTo. This array is used only for addresses with IDN.
See also: PHPMailer::$ReplyTo
protected array $ReplyToQueue
return array

$SMTPAuth public_oe property

Uses the Username and Password properties.
See also: PHPMailer::$Username
See also: PHPMailer::$Password
public bool $SMTPAuth
return boolean

$SMTPAutoTLS public_oe property

Be aware that in PHP >= 5.6 this requires that the server's certificates are valid.
public bool $SMTPAutoTLS
return boolean

$SMTPDebug public_oe property

Debug output level. Options: * 0 No output * 1 Commands * 2 Data and commands * 3 As 2 plus connection status * 4 Low-level data output
See also: SMTP::$do_debug
public int $SMTPDebug
return integer

$SMTPKeepAlive public_oe property

If this is set to true then to close the connection requires an explicit call to smtpClose().
public bool $SMTPKeepAlive
return boolean

$SMTPOptions public_oe property

Options array passed to stream_context_create when connecting via SMTP.
public array $SMTPOptions
return array

$SMTPSecure public_oe property

Options: '', 'ssl' or 'tls'
public string $SMTPSecure
return string

$Sender public_oe property

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

$Sendmail public_oe property

The path to the sendmail program.
public string $Sendmail
return string

$SingleTo public_oe property

Only supported in mail and sendmail transports, not in SMTP.
public bool $SingleTo
return boolean

$SingleToArray protected_oe property

Storage for addresses when SingleTo is enabled.
protected array $SingleToArray
return array

$Subject public_oe property

The Subject of the message.
public string $Subject
return string

$Timeout public_oe property

Default of 5 minutes (300sec) is from RFC2821 section 4.5.3.2
public int $Timeout
return integer

$UseSendmailOptions public_oe property

One which supports sendmail's "-oi -f" options.
public bool $UseSendmailOptions
return boolean

$Username public_oe property

SMTP username.
public string $Username
return string

$WordWrap public_oe property

Set to 0 to not wrap. A useful value here is 78, for RFC2822 section 2.1.1 compliance.
public int $WordWrap
return integer

$XMailer public_oe property

Options: An empty string for PHPMailer default, whitespace for none, or a string to use
public string $XMailer
return string

$action_function public_oe property

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
public string $action_function
return string

$all_recipients protected_oe property

Includes all of $to, $cc, $bcc
See also: PHPMailer::$to @see PHPMailer::$cc @see PHPMailer::$bcc
protected array $all_recipients
return array

$attachment protected_oe property

The array of attachments.
protected array $attachment
return array

$bcc protected_oe property

The array of 'bcc' names and addresses.
protected array $bcc
return array

$boundary protected_oe property

The array of MIME boundary strings.
protected array $boundary
return array

$cc protected_oe property

The array of 'cc' names and addresses.
protected array $cc
return array

$do_verp public_oe property

Only applicable when sending via SMTP.
public bool $do_verp
return boolean

$error_count protected_oe property

The number of errors encountered.
protected int $error_count
return integer

$exceptions protected_oe property

Whether to throw exceptions for errors.
protected bool $exceptions
return boolean

$language protected_oe property

The array of available languages.
protected array $language
return array

$lastMessageID protected_oe property

The most recent Message-ID (including angular brackets).
protected string $lastMessageID
return string

$mailHeader protected_oe property

Extra headers that createHeader() doesn't fold in.
protected string $mailHeader
return string

$message_type protected_oe property

The message's MIME type.
protected string $message_type
return string

$oauth protected_oe property

An instance of the PHPMailer OAuth class.
protected OAuth,PHPMailer\PHPMailer $oauth
return OAuth

$sign_cert_file protected_oe property

The S/MIME certificate file path.
protected string $sign_cert_file
return string

$sign_extracerts_file protected_oe property

The optional S/MIME extra certificates ("CA Chain") file path.
protected string $sign_extracerts_file
return string

$sign_key_file protected_oe property

The S/MIME key file path.
protected string $sign_key_file
return string

$sign_key_pass protected_oe property

Used only if the key is encrypted.
protected string $sign_key_pass
return string

$smtp protected_oe property

An instance of the SMTP sender class.
protected SMTP,PHPMailer\PHPMailer $smtp
return SMTP

$to protected_oe property

The array of 'to' names and addresses.
protected array $to
return array

$uniqueid protected_oe property

Unique ID used for message ID and boundaries.
protected string $uniqueid
return string

$validator public_oe static_oe property

May be a callable to inject your own validator, but there are several built-in validators.
See also: PHPMailer::validateAddress()
public static string|callable $validator
return string | callable