Class PHPMailer

Description

PHPMailer - PHP email creation and transport class.

Located in /class.phpmailer.php (line 28)


	
			
Direct descendents
Class Description
PHPMailerOAuth PHPMailerOAuth - PHPMailer subclass adding OAuth support.
Class Constant Summary
Variable Summary
static string|callable $validator
boolean $AllowEmpty
string $AltBody
array $attachment
string $AuthType
array $bcc
string $Body
array $boundary
array $cc
string $CharSet
string $ContentType
string|callable $Debugoutput
string $DKIM_domain
string $DKIM_private
boolean $do_verp
string $Encoding
string $ErrorInfo
integer $error_count
boolean $exceptions
string $From
string $FromName
string $Helo
string $Host
string $Hostname
string $Ical
array $language
string $LE
string $Mailer
string $mailHeader
string $MessageDate
string $MessageID
string $message_type
string $MIMEBody
string $MIMEHeader
string $Password
string $PluginDir
integer $Port
integer $Priority
string $Realm
array $ReplyTo
string $ReturnPath
string $Sender
string $Sendmail
boolean $SingleTo
boolean $SMTPAuth
boolean $SMTPAutoTLS
integer $SMTPDebug
boolean $SMTPKeepAlive
array $SMTPOptions
string $SMTPSecure
string $Subject
integer $Timeout
array $to
string $uniqueid
string $Username
string $Version
integer $WordWrap
string $Workstation
string $XMailer
Method Summary
static string filenameToType (string $filename)
static boolean hasLineLongerThanMax (string $str)
static boolean isShellSafe (string $string)
static string|array mb_pathinfo (string $path, [integer|string $options = null])
static string normalizeBreaks (string $text, [string $breaktype = "\r\n"])
static string rfcDate ()
static boolean validateAddress (string $address, [string|callable $patternselect = null])
static string _mime_types ([string $ext = ''])
PHPMailer __construct ([boolean $exceptions = null])
void __destruct ()
boolean addAddress (string $address, [string $name = ''])
boolean addAnAddress (string $kind, string $address, [string $name = ''])
boolean addAttachment (string $path, [string $name = ''], [string $encoding = 'base64'], [string $type = ''], [string $disposition = 'attachment'])
boolean addBCC (string $address, [string $name = ''])
boolean addCC (string $address, [string $name = ''])
void addCustomHeader (string $name, [string $value = null])
boolean addEmbeddedImage (string $path, string $cid, [string $name = ''], [string $encoding = 'base64'], [string $type = ''], [string $disposition = 'inline'])
boolean addOrEnqueueAnAddress (string $kind, string $address, string $name)
string addrAppend (string $type, array $addr)
boolean addReplyTo (string $address, [string $name = ''])
string addrFormat (array $addr)
void addStringAttachment (string $string, string $filename, [string $encoding = 'base64'], [string $type = ''], [string $disposition = 'attachment'])
boolean addStringEmbeddedImage (string $string, string $cid, [string $name = ''], [string $encoding = 'base64'], [string $type = ''], [string $disposition = 'inline'])
boolean alternativeExists ()
string attachAll (string $disposition_type, string $boundary)
boolean attachmentExists ()
string base64EncodeWrapMB (string $str, [string $linebreak = null])
void clearAddresses ()
void clearBCCs ()
void clearCCs ()
void clearQueuedAddresses (string $kind)
void clearReplyTos ()
string createBody ()
string createHeader ()
string DKIM_Add (string $headers_line, string $subject, string $body)
string DKIM_BodyC (string $body)
string DKIM_HeaderC (string $signHeader)
string DKIM_QP (string $txt)
string DKIM_Sign (string $signHeader)
void doCallback (boolean $isSent, array $to, array $cc, array $bcc, string $subject, string $body, string $from)
void edebug (string $str)
string encodeFile (string $path, [string $encoding = 'base64'])
string encodeHeader (string $str, [string $position = 'text'])
string encodeQ (string $str, [string $position = 'text'])
string encodeQP (string $string, [integer $line_max = 76])
string encodeQPphp (string $string, [integer $line_max = 76], [boolean $space_conv = false])
string encodeString (string $str, [string $encoding = 'base64'])
string endBoundary (string $boundary)
string fixEOL (string $str)
string generateId ()
array getAttachments ()
array getBccAddresses ()
string getBoundary (string $boundary, string $charSet, string $contentType, string $encoding)
array getCcAddresses ()
array getCustomHeaders ()
string getLastMessageID ()
string getMailMIME ()
string getSentMIMEMessage ()
array getToAddresses ()
array getTranslations ()
boolean has8bitChars (string $text)
boolean hasMultiBytes (string $str)
string headerLine (string $name, string $value)
string html2text (string $html, [boolean|callable $advanced = false])
bool idnSupported ()
boolean inlineImageExists ()
boolean isError ()
void isHTML ([boolean $isHtml = true])
void isMail ()
void isQmail ()
void isSendmail ()
void isSMTP ()
string lang (string $key)
boolean mailSend (string $header, string $body)
string msgHTML (string $message, [string $basedir = ''], [boolean|callable $advanced = false])
array parseAddresses (string $addrstr, [bool $useimap = true])
boolean postSend ()
boolean preSend ()
string punyencodeAddress (string $address)
string secureHeader (string $str)
boolean send ()
boolean sendmailSend (string $header, string $body)
string serverHostname ()
boolean set (string $name, [mixed $value = ''])
void setError (string $msg)
boolean setFrom (string $address, [string $name = ''], [boolean $auto = true])
boolean setLanguage ([string $langcode = 'en'], [string $lang_path = ''])
void setMessageType ()
void setWordWrap ()
void sign (string $cert_filename, string $key_filename, string $key_pass, [string $extracerts_filename = ''])
void smtpClose ()
boolean smtpConnect ([array $options = null])
boolean smtpSend (string $header, string $body)
string textLine (string $value)
integer utf8CharBoundary (string $encodedText, integer $maxLength)
string wrapText (string $message, integer $length, [boolean $qp_mode = false])
Variables
static string|callable $validator = 'auto' (line 467)

Which validator to use by default when validating email addresses.

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

string $action_function = '' (line 451)

Callback Action function name.

The function that handles the result of the send email action. It is called out by send() for each email sent.

Value can be any php callable: http://www.php.net/is_callable

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

  • access: public
boolean $AllowEmpty = false (line 383)

Whether to allow sending messages with an empty body.

  • access: public
array $all_recipients = array() (line 511)

An array of all kinds of addresses.

Includes all of $to, $cc, $bcc

  • see: PHPMailer::$to @see PHPMailer::$cc @see PHPMailer::$bcc
  • access: protected
string $AltBody = '' (line 118)

The plain-text message body.

This body can be read by mail clients that do not have HTML email capability such as mutt & Eudora. Clients that can read HTML will view the normal Body.

  • access: public
array $attachment = array() (line 540)

The array of attachments.

  • access: protected
string $AuthType = '' (line 294)

SMTP auth type.

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

  • access: public
array $bcc = array() (line 495)

The array of 'bcc' names and addresses.

  • access: protected
string $Body = '' (line 109)

An HTML or plain text message body.

If HTML then call isHTML(true).

  • access: public
array $boundary = array() (line 568)

The array of MIME boundary strings.

  • access: protected
array $cc = array() (line 488)

The array of 'cc' names and addresses.

  • access: protected
string $CharSet = 'iso-8859-1' (line 48)

The character set of the message.

  • access: public
string $ConfirmReadingTo = '' (line 190)

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

  • access: public
string $ContentType = 'text/plain' (line 54)

The MIME Content-type of the message.

  • access: public
array $CustomHeader = array() (line 547)

The array of custom headers.

  • access: protected
string|callable $Debugoutput = 'echo' (line 345)

How to handle debug output.

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

Alternatively, you can provide a callable expecting two params: a message string and the debug level:

  1.  $mail->Debugoutput function($str$level{echo "debug level $level; message: $str";};

string $DKIM_domain = '' (line 418)

DKIM signing domain name.

  • access: public
  • example: example not found
string $DKIM_identity = '' (line 404)

DKIM Identity.

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

  • access: public
string $DKIM_passphrase = '' (line 411)

DKIM passphrase.

Used if your key is encrypted.

  • access: public
string $DKIM_private = '' (line 424)

DKIM private key file path.

  • access: public
string $DKIM_private_string = '' (line 431)

DKIM private key string.

If set, takes precedence over `$DKIM_private`.

  • access: public
string $DKIM_selector = '' (line 397)

DKIM selector.

  • access: public
boolean $do_verp = false (line 377)

Whether to generate VERP addresses on send.

Only applicable when sending via SMTP.

string $Encoding = '8bit' (line 61)

The message encoding.

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

  • access: public
string $ErrorInfo = '' (line 67)

Holds the most recent mailer error message.

  • access: public
integer $error_count = 0 (line 582)

The number of errors encountered.

  • access: protected
boolean $exceptions = false (line 618)

Whether to throw exceptions for errors.

  • access: protected
string $From = 'root@localhost' (line 73)

The From email address for the message.

  • access: public
string $FromName = 'Root User' (line 79)

The From name of the message.

  • access: public
string $Helo = '' (line 245)

The SMTP HELO of the message.

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

string $Host = 'localhost' (line 229)

SMTP hosts.

Either a single hostname or multiple semicolon-delimited hostnames. You can also specify a different port for each host by using this format: [hostname:port] (e.g. "smtp1.example.com:25;smtp2.example.com"). You can also specify encryption type, for example: (e.g. "tls://smtp1.example.com:587;ssl://smtp2.example.com:465"). Hosts will be tried in order.

  • access: public
string $Hostname = '' (line 199)

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

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

  • access: public
string $Ical = '' (line 128)

An iCal message part body.

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

array $language = array() (line 575)

The array of available languages.

  • access: protected
string $lastMessageID = '' (line 554)

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

  • access: protected
string $LE = "\n" (line 391)

The default line ending.

  • access: public
string $Mailer = 'mail' (line 163)

Which method to use to send mail.

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

  • access: public
string $mailHeader = '' (line 149)

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

  • access: protected
string $MessageDate = '' (line 216)

The message Date to be used in the Date header.

If empty, the current date will be added.

  • access: public
string $MessageID = '' (line 209)

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

If empty, a unique id will be generated. You can set your own, but it must be in the format "<id@domain>", as defined in RFC5322 section 3.6.4 or it will be ignored.

  • see: section-3.6.4
  • access: public
string $message_type = '' (line 561)

The message's MIME type.

  • access: protected
string $MIMEBody = '' (line 135)

The complete compiled MIME message body.

  • access: protected
string $MIMEHeader = '' (line 142)

The complete compiled MIME message headers.

  • access: protected
string $Password = '' (line 287)

SMTP password.

  • access: public
string $PluginDir = '' (line 184)

Path to PHPMailer plugins.

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

  • deprecated: Should not be needed now there is an autoloader.
  • access: public
integer $Port = 25 (line 236)

The default SMTP server port.

  • TODO: Why is this needed when the SMTP class takes care of it?
  • access: public
integer $Priority = null (line 42)

Email priority.

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

  • access: public
string $Realm = '' (line 301)

SMTP realm.

Used for NTLM auth

  • access: public
array $RecipientsQueue = array() (line 523)

An array of names and addresses queued for validation.

In send(), valid and non duplicate entries are moved to $all_recipients and one of $to, $cc, or $bcc. This array is used only for addresses with IDN.

array $ReplyTo = array() (line 502)

The array of reply-to names and addresses.

  • access: protected
array $ReplyToQueue = array() (line 533)

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

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

string $ReturnPath = '' (line 96)

The Return-Path of the message.

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

  • link: RFC5321 reference
  • deprecated: Email senders should never set a return-path header; it's the receiver's job (RFC5321 section 4.4), so this no longer does anything.
  • access: public
string $Sender = '' (line 86)

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

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

  • access: public
string $Sendmail = '/usr/sbin/sendmail' (line 169)

The path to the sendmail program.

  • access: public
string $sign_cert_file = '' (line 589)

The S/MIME certificate file path.

  • access: protected
string $sign_extracerts_file = '' (line 603)

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

  • access: protected
string $sign_key_file = '' (line 596)

The S/MIME key file path.

  • access: protected
string $sign_key_pass = '' (line 611)

The S/MIME password for the key.

Used only if the key is encrypted.

  • access: protected
boolean $SingleTo = false (line 361)

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

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

  • access: public
array $SingleToArray = array() (line 368)

Storage for addresses when SingleTo is enabled.

  • TODO: This should really not be public
  • access: public
SMTP $smtp = null (line 474)

An instance of the SMTP sender class.

  • access: protected
boolean $SMTPAuth = false (line 269)

Whether to use SMTP authentication.

Uses the Username and Password properties.

boolean $SMTPAutoTLS = true (line 260)

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

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

  • access: public
integer $SMTPDebug = 0 (line 329)

SMTP class debug output mode.

Debug output level. Options: * `0` No output * `1` Commands * `2` Data and commands * `3` As 2 plus connection status * `4` Low-level data output

boolean $SMTPKeepAlive = false (line 353)

Whether to keep SMTP connection open after each message.

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

  • access: public
array $SMTPOptions = array() (line 275)

Options array passed to stream_context_create when connecting via SMTP.

  • access: public
string $SMTPSecure = '' (line 252)

What kind of encryption to use on the SMTP connection.

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

  • access: public
string $Subject = '' (line 102)

The Subject of the message.

  • access: public
integer $Timeout = 300 (line 315)

The SMTP server timeout in seconds.

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

  • access: public
array $to = array() (line 481)

The array of 'to' names and addresses.

  • access: protected
string $uniqueid = '' (line 625)

Unique ID used for message ID and boundaries.

  • access: protected
string $Username = '' (line 281)

SMTP username.

  • access: public
boolean $UseSendmailOptions = true (line 176)

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

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

  • access: public
string $Version = '5.2.22' (line 34)

The PHPMailer Version number.

  • access: public
integer $WordWrap = 0 (line 156)

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

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

  • access: public
string $Workstation = '' (line 308)

SMTP workstation.

Used for NTLM auth

  • access: public
string $XMailer = '' (line 458)

What to put in the X-Mailer header.

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

  • access: public
Methods
static method filenameToType (line 3625)

Map a file name to a MIME type.

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

  • access: public
static string filenameToType (string $filename)
  • string $filename: A file name or full path, does not need to exist as a file
static method hasLineLongerThanMax (line 3944)

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

  • access: public
static boolean hasLineLongerThanMax (string $str)
  • string $str
static method isShellSafe (line 1439)

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.

static boolean isShellSafe (string $string)
  • string $string: The string to be validated
static method mb_pathinfo (line 3647)

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
static method normalizeBreaks (line 3729)

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.

  • access: public
static string normalizeBreaks (string $text, [string $breaktype = "\r\n"])
  • string $text
  • string $breaktype: What kind of line break to use, defaults to CRLF
static method rfcDate (line 3270)

Return an RFC 822 formatted date.

  • access: public
static string rfcDate ()
static method validateAddress (line 1068)

Check that a string looks like an email address.

  • access: public
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.
static method _mime_types (line 3510)

Get the MIME type for a file extension.

  • return: MIME type of file.
  • access: public
static string _mime_types ([string $ext = ''])
  • string $ext: File extension
Constructor __construct (line 657)

Constructor.

  • access: public
PHPMailer __construct ([boolean $exceptions = null])
  • boolean $exceptions: Should we throw external exceptions?
Destructor __destruct (line 667)

Destructor.

  • access: public
void __destruct ()
addAddress (line 817)

Add a "To" address.

  • return: true on success, false if address already used or invalid in some way
  • access: public
boolean addAddress (string $address, [string $name = ''])
  • string $address: The email address to send to
  • string $name
addAnAddress (line 913)

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.

  • return: true on success, false if address already used or invalid in some way
  • throws: phpmailerException
  • access: protected
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
addAttachment (line 2505)

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.

  • throws: phpmailerException
  • access: public
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
addBCC (line 841)

Add a "BCC" address.

  • return: true on success, false if address already used or invalid in some way
  • access: public
boolean addBCC (string $address, [string $name = ''])
  • string $address: The email address to send to
  • string $name
addCC (line 829)

Add a "CC" address.

  • return: true on success, false if address already used or invalid in some way
  • access: public
boolean addCC (string $address, [string $name = ''])
  • string $address: The email address to send to
  • string $name
addCustomHeader (line 3362)

Add a custom header.

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

  • access: public
void addCustomHeader (string $name, [string $value = null])
  • string $name: Custom header name
  • string $value: Header value
addEmbeddedImage (line 3031)

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!

  • return: True on successfully adding an attachment
  • access: public
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
addOrEnqueueAnAddress (line 869)

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.

  • return: true on success, false if address already used or invalid in some way
  • throws: phpmailerException
  • access: protected
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
addrAppend (line 1817)

Create recipient headers.

  • access: public
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'))
addReplyTo (line 852)

Add a "Reply-To" address.

  • return: true on success, false if address already used or invalid in some way
  • access: public
boolean addReplyTo (string $address, [string $name = ''])
  • string $address: The email address to reply to
  • string $name
addrFormat (line 1833)

Format an address for use in a message header.

  • access: public
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')
addStringAttachment (line 2990)

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.

  • access: public
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
addStringEmbeddedImage (line 3076)

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

  • return: True on successfully adding an attachment
  • access: public
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
alternativeExists (line 3136)

Check if this message has an alternative body set.

  • access: public
boolean alternativeExists ()
attachAll (line 2561)

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

Returns an empty string on failure.

  • access: protected
string attachAll (string $disposition_type, string $boundary)
  • string $disposition_type
  • string $boundary
attachmentExists (line 3122)

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

  • access: public
boolean attachmentExists ()
base64EncodeWrapMB (line 2856)

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
clearAddresses (line 3161)

Clear all To recipients.

  • access: public
void clearAddresses ()
clearAllRecipients (line 3210)

Clear all recipient types.

  • access: public
void clearAllRecipients ()
clearAttachments (line 3223)

Clear all filesystem, string, and binary attachments.

  • access: public
void clearAttachments ()
clearBCCs (line 3187)

Clear all BCC recipients.

  • access: public
void clearBCCs ()
clearCCs (line 3174)

Clear all CC recipients.

  • access: public
void clearCCs ()
clearCustomHeaders (line 3232)

Clear all custom headers.

  • access: public
void clearCustomHeaders ()
clearQueuedAddresses (line 3147)

Clear queued addresses of given kind.

  • access: public
void clearQueuedAddresses (string $kind)
  • string $kind: 'to', 'cc', or 'bcc'
clearReplyTos (line 3200)

Clear all ReplyTo recipients.

  • access: public
void clearReplyTos ()
createBody (line 2196)

Assemble the message body.

Returns an empty string on failure.

  • return: The assembled message body
  • throws: phpmailerException
  • access: public
string createBody ()
createHeader (line 2023)

Assemble message headers.

  • return: The assembled headers
  • access: public
string createHeader ()
DKIM_Add (line 3866)

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

  • access: public
string DKIM_Add (string $headers_line, string $subject, string $body)
  • string $headers_line: Header lines
  • string $subject: Subject
  • string $body: Body
DKIM_BodyC (line 3843)

Generate a DKIM canonicalization body.

  • access: public
string DKIM_BodyC (string $body)
  • string $body: Message Body
DKIM_HeaderC (line 3823)

Generate a DKIM canonicalization header.

  • access: public
string DKIM_HeaderC (string $signHeader)
  • string $signHeader: Header
DKIM_QP (line 3756)

Quoted-Printable-encode a DKIM header.

  • access: public
string DKIM_QP (string $txt)
  • string $txt
DKIM_Sign (line 3777)

Generate a DKIM signature.

  • return: The DKIM signature value
  • throws: phpmailerException
  • access: public
string DKIM_Sign (string $signHeader)
  • string $signHeader
doCallback (line 4015)

Perform a callback.

  • access: protected
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
edebug (line 711)

Output debugging info via user-defined method.

Only generates output if SMTP debug output is enabled (@see SMTP::$do_debug).

void edebug (string $str)
  • string $str
encodeFile (line 2686)

Encode a file attachment in requested format.

Returns an empty string on failure.

  • throws: phpmailerException
  • access: protected
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'
encodeHeader (line 2763)

Encode a header string optimally.

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

  • access: public
string encodeHeader (string $str, [string $position = 'text'])
  • string $str
  • string $position
encodeQ (line 2939)

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
encodeQP (line 2898)

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
encodeQPphp (line 2923)

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
encodeString (line 2727)

Encode a string in requested format.

Returns an empty string on failure.

  • access: public
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'
endBoundary (line 2440)

Return the end of a message boundary.

  • access: protected
string endBoundary (string $boundary)
  • string $boundary
fixEOL (line 3342)

Ensure consistent line endings in a string.

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

  • access: public
string fixEOL (string $str)
  • string $str: String to fixEOL
generateId (line 2185)

Create unique ID

  • access: protected
string generateId ()
getAllRecipientAddresses (line 4000)

Allows for public read access to 'all_recipients' property.

  • access: public
array getAllRecipientAddresses ()
getAttachments (line 2548)

Return the array of attachments.

  • access: public
array getAttachments ()
getBccAddresses (line 3978)

Allows for public read access to 'bcc' property.

  • access: public
array getBccAddresses ()
getBoundary (line 2410)

Return the start of a message boundary.

  • access: protected
string getBoundary (string $boundary, string $charSet, string $contentType, string $encoding)
  • string $boundary
  • string $charSet
  • string $contentType
  • string $encoding
getCcAddresses (line 3967)

Allows for public read access to 'cc' property.

  • access: public
array getCcAddresses ()
getCustomHeaders (line 3376)

Returns all custom headers.

  • access: public
array getCustomHeaders ()
getLastMessageID (line 1044)

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.

  • access: public
string getLastMessageID ()
getMailMIME (line 2121)

Get the message MIME type headers.

  • access: public
string getMailMIME ()
getReplyToAddresses (line 3989)

Allows for public read access to 'ReplyTo' property.

  • access: public
array getReplyToAddresses ()
getSentMIMEMessage (line 2176)

Returns the whole MIME message.

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

string getSentMIMEMessage ()
getSMTPInstance (line 1517)

Get an instance to use for SMTP operations.

Override this function to load your own SMTP implementation

  • access: public
SMTP getSMTPInstance ()
getToAddresses (line 3956)

Allows for public read access to 'to' property.

  • access: public
array getToAddresses ()
getTranslations (line 1802)

Get the array of strings for the current language.

  • access: public
array getTranslations ()
has8bitChars (line 2841)

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

  • access: public
boolean has8bitChars (string $text)
  • string $text
hasMultiBytes (line 2827)

Check if a string contains multi-byte characters.

  • access: public
boolean hasMultiBytes (string $str)
  • string $str: multi-byte text to wrap encode
headerLine (line 2477)

Format a header line.

  • access: public
string headerLine (string $name, string $value)
  • string $name
  • string $value
html2text (line 3491)

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:

  1.  // Use default conversion
  2.  $plain $mail->html2text($html);
  3.  // Use your own custom converter
  4.  $plain $mail->html2text($htmlfunction($html{
  5.      $converter new MyHtml2text($html);
  6.      return $converter->get_text();
  7.  });

  • access: public
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.
idnSupported (line 1164)

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

  • return: "true" if required functions for IDN support are present
  • access: public
bool idnSupported ()
inlineImageExists (line 3108)

Check if an inline attachment is present.

  • access: public
boolean inlineImageExists ()
isError (line 3330)

Check if an error occurred.

  • return: True if an error did occur.
  • access: public
boolean isError ()
isHTML (line 752)

Sets message type to HTML or plain.

  • access: public
void isHTML ([boolean $isHtml = true])
  • boolean $isHtml: True for HTML mode.
isMail (line 774)

Send messages using PHP's mail() function.

  • access: public
void isMail ()
isQmail (line 799)

Send messages using qmail.

  • access: public
void isQmail ()
isSendmail (line 783)

Send messages using $Sendmail.

  • access: public
void isSendmail ()
isSMTP (line 765)

Send messages using SMTP.

  • access: public
void isSMTP ()
lang (line 3305)

Get an error message in the current language.

  • access: protected
string lang (string $key)
  • string $key
mailSend (line 1473)

Send mail using the PHP mail() function.

boolean mailSend (string $header, string $body)
  • string $header: The message headers
  • string $body: The message body
msgHTML (line 3397)

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.

  • return: The transformed message Body
  • access: public
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()
parseAddresses (line 958)

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
postSend (line 1326)

Actually send a message.

Send the email via the selected mechanism

  • throws: phpmailerException
  • access: public
boolean postSend ()
preSend (line 1229)

Prepare a message for sending.

  • throws: phpmailerException
  • access: public
boolean preSend ()
punyencodeAddress (line 1181)

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
secureHeader (line 3714)

Strip newlines to prevent header injection.

  • access: public
string secureHeader (string $str)
  • string $str
send (line 1207)

Create a message and send it.

Uses the sending method specified by $Mailer.

  • return: false on error - See the ErrorInfo property for details of the error.
  • throws: phpmailerException
  • access: public
boolean send ()
sendmailSend (line 1365)

Send mail using the $Sendmail program.

boolean sendmailSend (string $header, string $body)
  • string $header: The message headers
  • string $body: The message body
serverHostname (line 3284)

Get the server hostname.

Returns 'localhost.localdomain' if unknown.

  • access: protected
string serverHostname ()
set (line 3697)

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

  • TODO: Should this not be using the __set() magic function?
  • access: public
boolean set (string $name, [mixed $value = ''])
  • string $name: The property name to set
  • mixed $value: The value to set the property to
setError (line 3243)

Add an error message to the error container.

  • access: protected
void setError (string $msg)
  • string $msg
setFrom (line 1011)

Set the From and FromName properties.

  • throws: phpmailerException
  • access: public
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
setLanguage (line 1736)

Set the language for error messages.

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

  • access: public
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)
setMessageType (line 2451)

Set the message type.

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

  • access: protected
void setMessageType ()
setWordWrap (line 1999)

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.

  • access: public
void setWordWrap ()
sign (line 3742)

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

  • access: public
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
smtpClose (line 1717)

Close the active SMTP session if one exists.

  • access: public
void smtpClose ()
smtpConnect (line 1600)

Initiate a connection to an SMTP server.

Returns false if the operation failed.

  • throws: phpmailerException
  • access: public
  • uses: SMTP
boolean smtpConnect ([array $options = null])
  • array $options: An array of options compatible with stream_context_create()

Redefined in descendants as:
smtpSend (line 1537)

Send mail via SMTP.

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

  • see: PHPMailer::getSMTPInstance() to use a different class.
  • throws: phpmailerException
  • access: protected
  • uses: SMTP
boolean smtpSend (string $header, string $body)
  • string $header: The message headers
  • string $body: The message body
textLine (line 2488)

Return a formatted mail line.

  • access: public
string textLine (string $value)
  • string $value
utf8CharBoundary (line 1954)

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

Original written by Colin Brown.

  • access: public
integer utf8CharBoundary (string $encodedText, integer $maxLength)
  • string $encodedText: utf-8 QP text
  • integer $maxLength: Find the last character boundary prior to this length
wrapText (line 1855)

Word-wrap message.

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

  • access: public
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
Class Constants
CRLF = "\r\n" (line 645)

SMTP RFC standard line ending.

MAX_LINE_LENGTH = 998 (line 651)

The maximum line length allowed by RFC 2822 section 2.1.1

STOP_CONTINUE = 1 (line 635)

Error severity: message, likely ok to continue processing.

STOP_CRITICAL = 2 (line 640)

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

STOP_MESSAGE = 0 (line 630)

Error severity: message only, continue processing.

Documentation generated on Mon, 09 Jan 2017 07:57:13 +0000 by phpDocumentor 1.4.3