Map a file name to a MIME type. Defaults to 'application/octet-stream', i.e..
arbitrary binary data.
static
string
filenameToType
(string $filename)
-
string
$filename: A file name or full path, does not need to exist as a file
Detect if a string contains a line longer than the maximum line length allowed.
static
boolean
hasLineLongerThanMax
(string $str)
Multi-byte-safe pathinfo replacement.
Drop-in replacement for pathinfo(), but multibyte-safe, cross-platform-safe, old-version-safe. Works similarly to the one in PHP >= 5.2.0
static
string|array
mb_pathinfo
(string $path, [integer|string $options = null])
-
string
$path: A filename or path, does not need to exist as a file
-
integer|string
$options: Either a PATHINFO_* constant, or a string name to return only the specified piece, allows 'filename' to work on PHP < 5.2
Normalize line breaks in a string.
Converts UNIX LF, Mac CR and Windows CRLF line breaks into a single line break format. Defaults to CRLF (for message bodies) and preserves consecutive breaks.
static
string
normalizeBreaks
(string $text, [string $breaktype = "\r\n"])
-
string
$text
-
string
$breaktype: What kind of line break to use, defaults to CRLF
Return an RFC 822 formatted date.
static
string
rfcDate
()
Check that a string looks like an email address.
static
boolean
validateAddress
(string $address, [string|callable $patternselect = null])
-
string
$address: The email address to check
-
string|callable
$patternselect: A selector for the validation pattern to use : * `auto` Pick best pattern automatically; * `pcre8` Use the squiloople.com pattern, requires PCRE > 8.0, PHP >= 5.3.2, 5.2.14; * `pcre` Use old PCRE implementation; * `php` Use PHP built-in FILTER_VALIDATE_EMAIL; * `html5` Use the pattern given by the HTML5 spec for 'email' type form input elements. * `noregex` Don't use a regex: super fast, really dumb. Alternatively you may pass in a callable to inject your own validator, for example: PHPMailer::validateAddress('user@example.com', function($address) { return (strpos($address, '@') !== false); }); You can also set the PHPMailer::$validator static to a callable, allowing built-in methods to use your validator.
Get the MIME type for a file extension.
static
string
_mime_types
([string $ext = ''])
-
string
$ext: File extension
Constructor.
PHPMailer
__construct
([boolean $exceptions = null])
-
boolean
$exceptions: Should we throw external exceptions?
Destructor.
void
__destruct
()
Add a "To" address.
boolean
addAddress
(string $address, [string $name = ''])
-
string
$address: The email address to send to
-
string
$name
Add an address to one of the recipient arrays or to the ReplyTo array.
Addresses that have been added already return false, but do not throw exceptions.
boolean
addAnAddress
(string $kind, string $address, [string $name = ''])
-
string
$kind: One of 'to', 'cc', 'bcc', or 'ReplyTo'
-
string
$address: The email address to send, resp. to reply to
-
string
$name
Add an attachment from a path on the filesystem.
Never use a user-supplied path to a file! Returns false if the file could not be found or read. Explicitly *does not* support passing URLs; PHPMailer is not an HTTP client. If you need to do that, fetch the resource yourself and pass it in via a local file or string.
boolean
addAttachment
(string $path, [string $name = ''], [string $encoding = 'base64'], [string $type = ''], [string $disposition = 'attachment'])
-
string
$path: Path to the attachment.
-
string
$name: Overrides the attachment name.
-
string
$encoding: File encoding (see $Encoding).
-
string
$type: File extension (MIME) type.
-
string
$disposition: Disposition to use
Add a "BCC" address.
boolean
addBCC
(string $address, [string $name = ''])
-
string
$address: The email address to send to
-
string
$name
Add a "CC" address.
boolean
addCC
(string $address, [string $name = ''])
-
string
$address: The email address to send to
-
string
$name
Add a custom header.
$name value can be overloaded to contain both header name and value (name:value)
void
addCustomHeader
(string $name, [string $value = null])
-
string
$name: Custom header name
-
string
$value: Header value
Add an embedded (inline) attachment from a file.
This can include images, sounds, and just about any other document type. These differ from 'regular' attachments in that they are intended to be displayed inline with the message, not just attached for download. This is used in HTML messages that embed the images the HTML refers to using the $cid value. Never use a user-supplied path to a file!
boolean
addEmbeddedImage
(string $path, string $cid, [string $name = ''], [string $encoding = 'base64'], [string $type = ''], [string $disposition = 'inline'])
-
string
$path: Path to the attachment.
-
string
$cid: Content ID of the attachment; Use this to reference the content when using an embedded image in HTML.
-
string
$name: Overrides the attachment name.
-
string
$encoding: File encoding (see $Encoding).
-
string
$type: File MIME type.
-
string
$disposition: Disposition to use
Add an address to one of the recipient arrays or to the ReplyTo array.
Because PHPMailer can't validate addresses with an IDN without knowing the PHPMailer::$CharSet (that can still be modified after calling this function), addition of such addresses is delayed until send(). Addresses that have been added already return false, but do not throw exceptions.
boolean
addOrEnqueueAnAddress
(string $kind, string $address, string $name)
-
string
$kind: One of 'to', 'cc', 'bcc', or 'ReplyTo'
-
string
$address: The email address to send, resp. to reply to
-
string
$name
Create recipient headers.
string
addrAppend
(string $type, array $addr)
-
string
$type
-
array
$addr: An array of recipient, where each recipient is a 2-element indexed array with element 0 containing an address and element 1 containing a name, like: array(array('joe@example.com', 'Joe User'), array('zoe@example.com', 'Zoe User'))
Add a "Reply-To" address.
boolean
addReplyTo
(string $address, [string $name = ''])
-
string
$address: The email address to reply to
-
string
$name
Format an address for use in a message header.
string
addrFormat
(array $addr)
-
array
$addr: A 2-element indexed array, element 0 containing an address, element 1 containing a name like array('joe@example.com', 'Joe User')
Add a string or binary attachment (non-filesystem).
This method can be used to attach ascii or binary data, such as a BLOB record from a database.
void
addStringAttachment
(string $string, string $filename, [string $encoding = 'base64'], [string $type = ''], [string $disposition = 'attachment'
])
-
string
$string: String attachment data.
-
string
$filename: Name of the attachment.
-
string
$encoding: File encoding (see $Encoding).
-
string
$type: File extension (MIME) type.
-
string
$disposition: Disposition to use
Add an embedded stringified attachment.
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'.
boolean
addStringEmbeddedImage
(string $string, string $cid, [string $name = ''], [string $encoding = 'base64'], [string $type = ''], [string $disposition = 'inline'
])
-
string
$string: The attachment binary data.
-
string
$cid: Content ID of the attachment; Use this to reference the content when using an embedded image in HTML.
-
string
$name
-
string
$encoding: File encoding (see $Encoding).
-
string
$type: MIME type.
-
string
$disposition: Disposition to use
Check if this message has an alternative body set.
boolean
alternativeExists
()
Attach all file, string, and binary attachments to the message.
Returns an empty string on failure.
string
attachAll
(string $disposition_type, string $boundary)
-
string
$disposition_type
-
string
$boundary
Check if an attachment (non-inline) is present.
boolean
attachmentExists
()
Encode and wrap long multibyte strings for mail headers without breaking lines within a character.
Adapted from a function by paravoid
string
base64EncodeWrapMB
(string $str, [string $linebreak = null])
-
string
$str: multi-byte text to wrap encode
-
string
$linebreak: string to use as linefeed/end-of-line
Clear all To recipients.
void
clearAddresses
()
Clear all recipient types.
void
clearAllRecipients
()
Clear all filesystem, string, and binary attachments.
void
clearAttachments
()
Clear all BCC recipients.
void
clearBCCs
()
Clear all CC recipients.
void
clearCCs
()
Clear all custom headers.
void
clearCustomHeaders
()
Clear queued addresses of given kind.
void
clearQueuedAddresses
(string $kind)
-
string
$kind: 'to', 'cc', or 'bcc'
Clear all ReplyTo recipients.
void
clearReplyTos
()
Assemble the message body.
Returns an empty string on failure.
string
createBody
()
Assemble message headers.
string
createHeader
()
Create the DKIM header and body in a new message header.
string
DKIM_Add
(string $headers_line, string $subject, string $body)
-
string
$headers_line: Header lines
-
string
$subject: Subject
-
string
$body: Body
Generate a DKIM canonicalization body.
string
DKIM_BodyC
(string $body)
-
string
$body: Message Body
Generate a DKIM canonicalization header.
string
DKIM_HeaderC
(string $signHeader)
-
string
$signHeader: Header
Quoted-Printable-encode a DKIM header.
string
DKIM_QP
(string $txt)
Generate a DKIM signature.
string
DKIM_Sign
(string $signHeader)
Perform a callback.
void
doCallback
(boolean $isSent, array $to, array $cc, array $bcc, string $subject, string $body, string $from)
-
boolean
$isSent
-
array
$to
-
array
$cc
-
array
$bcc
-
string
$subject
-
string
$body
-
string
$from
Output debugging info via user-defined method.
Only generates output if SMTP debug output is enabled (@see SMTP::$do_debug).
void
edebug
(string $str)
Encode a file attachment in requested format.
Returns an empty string on failure.
string
encodeFile
(string $path, [string $encoding = 'base64'])
-
string
$path: The full path to the file
-
string
$encoding: The encoding to use; one of 'base64', '7bit', '8bit', 'binary', 'quoted-printable'
Encode a header string optimally.
Picks shortest of Q, B, quoted-printable or none.
string
encodeHeader
(string $str, [string $position = 'text'])
-
string
$str
-
string
$position
Encode a string using Q encoding.
string
encodeQ
(string $str, [string $position = 'text'])
-
string
$str: the text to encode
-
string
$position: Where the text is going to be used, see the RFC for what that means
Encode a string in quoted-printable format.
According to RFC2045 section 6.7.
string
encodeQP
(string $string, [integer $line_max = 76])
-
string
$string: The text to encode
-
integer
$line_max: Number of chars allowed on a line before wrapping
Backward compatibility wrapper for an old QP encoding function that was removed.
string
encodeQPphp
(string $string, [integer $line_max = 76], [boolean $space_conv = false
])
-
string
$string
-
integer
$line_max
-
boolean
$space_conv
Encode a string in requested format.
Returns an empty string on failure.
string
encodeString
(string $str, [string $encoding = 'base64'])
-
string
$str: The text to encode
-
string
$encoding: The encoding to use; one of 'base64', '7bit', '8bit', 'binary', 'quoted-printable'
Return the end of a message boundary.
string
endBoundary
(string $boundary)
Ensure consistent line endings in a string.
Changes every end of line from CRLF, CR or LF to $this->LE.
string
fixEOL
(string $str)
-
string
$str: String to fixEOL
Create unique ID
string
generateId
()
Allows for public read access to 'all_recipients' property.
array
getAllRecipientAddresses
()
Return the array of attachments.
array
getAttachments
()
Allows for public read access to 'bcc' property.
array
getBccAddresses
()
Return the start of a message boundary.
string
getBoundary
(string $boundary, string $charSet, string $contentType, string $encoding)
-
string
$boundary
-
string
$charSet
-
string
$contentType
-
string
$encoding
Allows for public read access to 'cc' property.
array
getCcAddresses
()
Returns all custom headers.
array
getCustomHeaders
()
Return the Message-ID header of the last email.
Technically this is the value from the last time the headers were created, but it's also the message ID of the last sent message except in pathological cases.
string
getLastMessageID
()
Get the message MIME type headers.
string
getMailMIME
()
Allows for public read access to 'ReplyTo' property.
array
getReplyToAddresses
()
Returns the whole MIME message.
Includes complete headers and body. Only valid post preSend().
string
getSentMIMEMessage
()
Get an instance to use for SMTP operations.
Override this function to load your own SMTP implementation
Allows for public read access to 'to' property.
array
getToAddresses
()
Get the array of strings for the current language.
array
getTranslations
()
Does a string contain any 8-bit chars (in any charset)?
boolean
has8bitChars
(string $text)
Check if a string contains multi-byte characters.
boolean
hasMultiBytes
(string $str)
-
string
$str: multi-byte text to wrap encode
Format a header line.
string
headerLine
(string $name, string $value)
-
string
$name
-
string
$value
Convert an HTML string into plain text.
This is used by msgHTML(). Note - older versions of this function used a bundled advanced converter which was 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();
});
string
html2text
(string $html, [boolean|callable $advanced = false])
-
string
$html: The HTML text to convert
-
boolean|callable
$advanced: Any boolean value to use the internal converter, or provide your own callable for custom conversion.
Tells whether IDNs (Internationalized Domain Names) are supported or not.
This requires the "intl" and "mbstring" PHP extensions.
bool
idnSupported
()
Check if an inline attachment is present.
boolean
inlineImageExists
()
Check if an error occurred.
boolean
isError
()
Sets message type to HTML or plain.
void
isHTML
([boolean $isHtml = true])
-
boolean
$isHtml: True for HTML mode.
Send messages using PHP's mail() function.
void
isMail
()
Check whether a file path is of a permitted type.
Used to reject URLs and phar files from functions that access local file paths, such as addAttachment.
bool
isPermittedPath
(string $path)
-
string
$path: A relative or absolute path to a file.
Send messages using qmail.
void
isQmail
()
Send messages using $Sendmail.
void
isSendmail
()
Fix CVE-2016-10033 and CVE-2016-10045 by disallowing potentially unsafe shell characters.
Note that escapeshellarg and escapeshellcmd are inadequate for our purposes, especially on Windows.
boolean
isShellSafe
(string $string)
-
string
$string: The string to be validated
Send messages using SMTP.
void
isSMTP
()
Get an error message in the current language.
string
lang
(string $key)
Send mail using the PHP mail() function.
boolean
mailSend
(string $header, string $body)
-
string
$header: The message headers
-
string
$body: The message body
Create a message body from an HTML string.
Automatically inlines images and creates a plain-text version by converting the HTML, overwriting any existing values in Body and AltBody. Do not source $message content from user input! $basedir is prepended when handling relative URLs, e.g. <img src="/images/a.png"> and must not be empty will look for an image file in $basedir/images/a.png and convert it to inline. If you don't provide a $basedir, relative paths will be left untouched (and thus probably break in email) If you don't want to apply these transformations to your HTML, just set Body and AltBody directly.
string
msgHTML
(string $message, [string $basedir = ''], [boolean|callable $advanced = false])
-
string
$message: HTML message string
-
string
$basedir: Absolute path to a base directory to prepend to relative paths to images
-
boolean|callable
$advanced: Whether to use the internal HTML to text converter or your own custom converter @see PHPMailer::html2text()
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.
Uses the imap_rfc822_parse_adrlist function if the IMAP extension is available. Note that quotes in the name part are removed.
array
parseAddresses
(string $addrstr, [bool $useimap = true])
-
string
$addrstr: The address list string
-
bool
$useimap: Whether to use the IMAP extension to parse the list
Actually send a message.
Send the email via the selected mechanism
boolean
postSend
()
Prepare a message for sending.
boolean
preSend
()
Converts IDN in given email address to its ASCII form, also known as punycode, if possible.
Important: Address must be passed in same encoding as currently set in PHPMailer::$CharSet. This function silently returns unmodified address if: - No conversion is necessary (i.e. domain name is not an IDN, or is already in ASCII form) - Conversion to punycode is impossible (e.g. required PHP functions are not available) or fails for any reason (e.g. domain has characters not allowed in an IDN)
string
punyencodeAddress
(string $address)
-
string
$address: The email address to convert
Strip newlines to prevent header injection.
string
secureHeader
(string $str)
Create a message and send it.
Uses the sending method specified by $Mailer.
boolean
send
()
Send mail using the $Sendmail program.
boolean
sendmailSend
(string $header, string $body)
-
string
$header: The message headers
-
string
$body: The message body
Get the server hostname.
Returns 'localhost.localdomain' if unknown.
string
serverHostname
()
Set or reset instance properties.
You should avoid this function - it's more verbose, less efficient, more error-prone and harder to debug than setting properties directly. Usage Example: `$mail->set('SMTPSecure', 'tls');` is the same as: `$mail->SMTPSecure = 'tls';`
boolean
set
(string $name, [mixed $value = ''])
-
string
$name: The property name to set
-
mixed
$value: The value to set the property to
Add an error message to the error container.
void
setError
(string $msg)
Set the From and FromName properties.
boolean
setFrom
(string $address, [string $name = ''], [boolean $auto = true])
-
string
$address
-
string
$name
-
boolean
$auto: Whether to also set the Sender address, defaults to true
Set the language for error messages.
Returns false if it cannot load the language file. The default language is English.
boolean
setLanguage
([string $langcode = 'en'], [string $lang_path = ''])
-
string
$langcode: ISO 639-1 2-character language code (e.g. French is "fr")
-
string
$lang_path: Path to the language file directory, with trailing separator (slash)
Set the message type.
PHPMailer only supports some preset message types, not arbitrary MIME structures.
void
setMessageType
()
Apply word wrapping to the message body.
Wraps the message body to the number of chars set in the WordWrap property. You should only do this to plain-text bodies as wrapping HTML tags may break them. This is called automatically by createBody(), so you don't need to call it yourself.
void
setWordWrap
()
Set the public and private key files and password for S/MIME signing.
void
sign
(string $cert_filename, string $key_filename, string $key_pass, [string $extracerts_filename = ''])
-
string
$cert_filename
-
string
$key_filename
-
string
$key_pass: Password for private key
-
string
$extracerts_filename: Optional path to chain certificate
Close the active SMTP session if one exists.
void
smtpClose
()
Initiate a connection to an SMTP server.
Returns false if the operation failed.
boolean
smtpConnect
([array $options = null])
-
array
$options: An array of options compatible with stream_context_create()
Redefined in descendants as:
Send mail via SMTP.
Returns false if there is a bad MAIL FROM, RCPT, or DATA input. Uses the PHPMailerSMTP class by default.
boolean
smtpSend
(string $header, string $body)
-
string
$header: The message headers
-
string
$body: The message body
Return a formatted mail line.
string
textLine
(string $value)
Find the last character boundary prior to $maxLength in a utf-8 quoted-printable encoded string.
Original written by Colin Brown.
integer
utf8CharBoundary
(string $encodedText, integer $maxLength)
-
string
$encodedText: utf-8 QP text
-
integer
$maxLength: Find the last character boundary prior to this length
Word-wrap message.
For use with mailers that do not automatically perform wrapping and for quoted-printable encoded messages. Original written by philippe.
string
wrapText
(string $message, integer $length, [boolean $qp_mode = false])
-
string
$message: The message to wrap
-
integer
$length: The line length to wrap to
-
boolean
$qp_mode: Whether to run in Quoted-Printable mode