PHPMailer - PHP email creation and transport class.
| package | PHPMailer |
|---|---|
| author | Marcus Bointon (Synchro/coolbru) |
| author | Jim Jagielski (jimjag) |
| author | Andy Prevost (codeworxtech) |
| author | Brent R. Matzelle (original founder) |
DKIM_Add(string $headers_line, string $subject, string $body) : string
| access | public |
|---|
stringHeader lines
stringSubject
stringBody
stringDKIM_BodyC(string $body) : string
| access | public |
|---|
stringMessage Body
stringDKIM_HeaderC(string $signHeader) : string
| access | public |
|---|
stringHeader
stringDKIM_QP(string $txt) : string
| access | public |
|---|
string
stringDKIM_Sign(string $signHeader) : string
| access | public |
|---|
string
\phpmailerException |
|---|
stringThe DKIM signature value__construct(boolean $exceptions = null)
booleanShould we throw external exceptions?
__destruct()
_mime_types(string $ext = '') : string
| access | public |
|---|---|
| static |
stringFile extension
stringMIME type of file.addAddress(string $address, string $name = '') : boolean
stringThe email address to send to
string
booleantrue on success, false if address already used or invalid in some wayaddAttachment(string $path, string $name= '', string $encoding= 'base64', string $type= '', string $disposition= 'attachment') : boolean
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.
stringPath to the attachment.
stringOverrides the attachment name.
stringFile encoding (see $Encoding).
stringFile extension (MIME) type.
stringDisposition to use
\phpmailerException |
|---|
booleanaddBCC(string $address, string $name = '') : boolean
| note | : This function works with the SMTP mailer on win32, not with the "mail" mailer. |
|---|
stringThe email address to send to
string
booleantrue on success, false if address already used or invalid in some wayaddCC(string $address, string $name = '') : boolean
| note | : This function works with the SMTP mailer on win32, not with the "mail" mailer. |
|---|
stringThe email address to send to
string
booleantrue on success, false if address already used or invalid in some wayaddCustomHeader(string $name, string $value = null) : void
$name value can be overloaded to contain both header name and value (name:value)
| access | public |
|---|
stringCustom header name
stringHeader value
addEmbeddedImage(string $path, string $cid, string $name= '', string $encoding= 'base64', string $type= '', string $disposition= 'inline') : boolean
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!
stringPath to the attachment.
stringContent ID of the attachment; Use this to reference the content when using an embedded image in HTML.
stringOverrides the attachment name.
stringFile encoding (see $Encoding).
stringFile MIME type.
stringDisposition to use
booleanTrue on successfully adding an attachmentaddReplyTo(string $address, string $name = '') : boolean
stringThe email address to reply to
string
booleantrue on success, false if address already used or invalid in some wayaddStringAttachment(string $string, string $filename, string $encoding= 'base64', string $type= '', string $disposition= 'attachment') : void
This method can be used to attach ascii or binary data, such as a BLOB record from a database.
stringString attachment data.
stringName of the attachment.
stringFile encoding (see $Encoding).
stringFile extension (MIME) type.
stringDisposition to use
addStringEmbeddedImage(string $string, string $cid, string $name= '', string $encoding= 'base64', string $type= '', string $disposition= 'inline') : boolean
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'.
stringThe attachment binary data.
stringContent ID of the attachment; Use this to reference the content when using an embedded image in HTML.
string
stringFile encoding (see $Encoding).
stringMIME type.
stringDisposition to use
booleanTrue on successfully adding an attachmentaddrAppend(string $type, array $addr) : string
| access | public |
|---|
string
arrayAn 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'))
stringaddrFormat(array $addr) : string
| access | public |
|---|
arrayA 2-element indexed array, element 0 containing an address, element 1 containing a name like array('joe@example.com', 'Joe User')
stringalternativeExists() : boolean
booleanbase64EncodeWrapMB(string $str, string $linebreak = null) : string
Adapted from a function by paravoid
| link | http://www.php.net/manual/en/function.mb-encode-mimeheader.php#60283 |
|---|---|
| access | public |
stringmulti-byte text to wrap encode
stringstring to use as linefeed/end-of-line
stringclearAddresses() : void
clearAllRecipients() : void
clearAttachments() : void
clearBCCs() : void
clearCCs() : void
clearCustomHeaders() : void
clearQueuedAddresses(string $kind) : void
| access | protected |
|---|
string'to', 'cc', or 'bcc'
clearReplyTos() : void
createBody() : string
Returns an empty string on failure.
| access | public |
|---|
\phpmailerException |
|---|
stringThe assembled message bodycreateHeader() : string
| access | public |
|---|
stringThe assembled headersencodeHeader(string $str, string $position = 'text') : string
Picks shortest of Q, B, quoted-printable or none.
| access | public |
|---|
string
string
stringencodeQ(string $str, string $position = 'text') : string
| link | http://tools.ietf.org/html/rfc2047 |
|---|---|
| access | public |
stringthe text to encode
stringWhere the text is going to be used, see the RFC for what that means
stringencodeQP(string $string, integer $line_max = 76) : string
According to RFC2045 section 6.7.
| access | public |
|---|---|
| link | Adapted from this comment |
stringThe text to encode
integerNumber of chars allowed on a line before wrapping
stringencodeQPphp(string $string, integer $line_max= 76, boolean $space_conv= false) : string
encodeString(string $str, string $encoding = 'base64') : string
Returns an empty string on failure.
| access | public |
|---|
stringThe text to encode
stringThe encoding to use; one of 'base64', '7bit', '8bit', 'binary', 'quoted-printable'
stringfilenameToType(string $filename) : string
Defaults to 'application/octet-stream', i.e.. arbitrary binary data.
| static |
|---|
stringA file name or full path, does not need to exist as a file
stringfixEOL(string $str) : string
Changes every end of line from CRLF, CR or LF to $this->LE.
| access | public |
|---|
stringString to fixEOL
stringgetAllRecipientAddresses() : array
| note | : Before the send() call, queued addresses (i.e. with IDN) are not yet included. |
|---|---|
| access | public |
arraygetAttachments() : array
arraygetBccAddresses() : array
| note | : Before the send() call, queued addresses (i.e. with IDN) are not yet included. |
|---|---|
| access | public |
arraygetCcAddresses() : array
| note | : Before the send() call, queued addresses (i.e. with IDN) are not yet included. |
|---|---|
| access | public |
arraygetCustomHeaders() : array
arraygetLastMessageID() : string
Technically this is the value from the last time the headers were created, but it's also the message ID of the last sent message except in pathological cases.
stringgetMailMIME() : string
| access | public |
|---|
stringgetReplyToAddresses() : array
| note | : Before the send() call, queued addresses (i.e. with IDN) are not yet included. |
|---|---|
| access | public |
arraygetSMTPInstance() : \SMTP
Override this function to load your own SMTP implementation
\SMTPgetSentMIMEMessage() : string
getToAddresses() : array
| note | : Before the send() call, queued addresses (i.e. with IDN) are not yet included. |
|---|---|
| access | public |
arraygetTranslations() : array
arrayhas8bitChars(string $text) : boolean
string
booleanhasLineLongerThanMax(string $str) : boolean
| static |
|---|
string
booleanhasMultiBytes(string $str) : boolean
| access | public |
|---|
stringmulti-byte text to wrap encode
booleanheaderLine(string $name, string $value) : string
| access | public |
|---|
string
string
stringhtml2text(string $html, boolean|callable $advanced = false) : string
This is used by msgHTML().
Note - older versions of this function used a bundled advanced converter
which was been removed for license reasons in #232.
Example usage:
// Use default conversion
$plain = $mail->html2text($html);
// Use your own custom converter
$plain = $mail->html2text($html, function($html) {
$converter = new MyHtml2text($html);
return $converter->get_text();
});
stringThe HTML text to convert
booleancallableAny boolean value to use the internal converter, or provide your own callable for custom conversion.
stringidnSupported() : boolean
boolean"true" if required functions for IDN support are presentinlineImageExists() : boolean
| access | public |
|---|
booleanisError() : boolean
| access | public |
|---|
booleanTrue if an error did occur.isHTML(boolean $isHtml = true) : void
booleanTrue for HTML mode.
isMail() : void
isQmail() : void
isSMTP() : void
isSendmail() : void
mb_pathinfo(string $path, integer|string $options = null) : string | array
Drop-in replacement for pathinfo(), but multibyte-safe, cross-platform-safe, old-version-safe. Works similarly to the one in PHP >= 5.2.0
| link | http://www.php.net/manual/en/function.pathinfo.php#107461 |
|---|---|
| static |
stringA filename or path, does not need to exist as a file
integerstringEither a PATHINFO_* constant, or a string name to return only the specified piece, allows 'filename' to work on PHP < 5.2
stringarray
msgHTML(string $message, string $basedir= '', boolean|callable $advanced= false) : string
Automatically inlines images and creates a plain-text version by converting the HTML,
overwriting any existing values in Body and AltBody.
Do not source $message content from user input!
$basedir is prepended when handling relative URLs, e.g.
and must not be empty
will look for an image file in $basedir/images/a.png and convert it to inline.
If you don't provide a $basedir, relative paths will be left untouched (and thus probably break in email)
If you don't want to apply these transformations to your HTML, just set Body and AltBody directly.
| access | public |
|---|
stringHTML message string
stringAbsolute path to a base directory to prepend to relative paths to images
booleancallableWhether to use the internal HTML to text converter or your own custom converter @see PHPMailer::html2text()
string$message The transformed message BodynormalizeBreaks(string $text, string $breaktype = "\r\n") : 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
stringWhat kind of line break to use, defaults to CRLF
stringparseAddresses(string $addrstr, boolean $useimap = true) : array
Uses the imap_rfc822_parse_adrlist function if the IMAP extension is available. Note that quotes in the name part are removed.
| link | A more careful implementation |
|---|
stringThe address list string
booleanWhether to use the IMAP extension to parse the list
arraypostSend() : boolean
Send the email via the selected mechanism
\phpmailerException |
|---|
booleanpreSend() : boolean
\phpmailerException |
|---|
booleanpunyencodeAddress(string $address) : string
Important: Address must be passed in same encoding as currently set in PHPMailer::$CharSet. This function silently returns unmodified address if:
| see |
|---|
stringThe email address to convert
stringThe encoded address in ASCII formrfcDate() : string
| access | public |
|---|---|
| static |
stringsecureHeader(string $str) : string
| access | public |
|---|
string
stringsend() : boolean
Uses the sending method specified by $Mailer.
\phpmailerException |
|---|
booleanfalse on error - See the ErrorInfo property for details of the error.set(string $name, mixed $value = '') : boolean
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';
| access | public |
|---|---|
| TODO | Should this not be using the __set() magic function? |
stringThe property name to set
mixedThe value to set the property to
booleansetFrom(string $address, string $name= '', boolean $auto= true) : boolean
string
string
booleanWhether to also set the Sender address, defaults to true
\phpmailerException |
|---|
booleansetLanguage(string $langcode= 'en', string $lang_path= '') : boolean
Returns false if it cannot load the language file. The default language is English.
| access | public |
|---|
stringISO 639-1 2-character language code (e.g. French is "fr")
stringPath to the language file directory, with trailing separator (slash)
booleansetWordWrap() : void
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 |
|---|
sign(string $cert_filename, string $key_filename, string $key_pass, string $extracerts_filename = '')
| access | public |
|---|
string
string
stringPassword for private key
stringOptional path to chain certificate
smtpClose() : void
smtpConnect(array $options = null) : boolean
textLine(string $value) : string
| access | public |
|---|
string
stringutf8CharBoundary(string $encodedText, integer $maxLength) : integer
Original written by Colin Brown.
| access | public |
|---|
stringutf-8 QP text
integerFind the last character boundary prior to this length
integervalidateAddress(string $address, string|callable $patternselect = null) : boolean
| static | |
|---|---|
| access | public |
stringThe email address to check
stringcallableA 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.booleanwrapText(string $message, integer $length, boolean $qp_mode = false) : string
For use with mailers that do not automatically perform wrapping and for quoted-printable encoded messages. Original written by philippe.
| access | public |
|---|
stringThe message to wrap
integerThe line length to wrap to
booleanWhether to run in Quoted-Printable mode
stringaddAnAddress(string $kind, string $address, string $name = '') : boolean
Addresses that have been added already return false, but do not throw exceptions.
| access | protected |
|---|
stringOne of 'to', 'cc', 'bcc', or 'ReplyTo'
stringThe email address to send, resp. to reply to
string
\phpmailerException |
|---|
booleantrue on success, false if address already used or invalid in some wayaddOrEnqueueAnAddress(string $kind, string $address, string $name) : boolean
Addresses that have been added already return false, but do not throw exceptions.
| access | protected |
|---|
stringOne of 'to', 'cc', 'bcc', or 'ReplyTo'
stringThe email address to send, resp. to reply to
string
\phpmailerException |
|---|
booleantrue on success, false if address already used or invalid in some wayattachAll(string $disposition_type, string $boundary) : string
Returns an empty string on failure.
| access | protected |
|---|
string
string
stringdoCallback(boolean $isSent, array $to, array $cc, array $bcc, string $subject, string $body, string $from)
boolean
array
array
array
string
string
string
edebug(string $str)
encodeFile(string $path, string $encoding = 'base64') : string
Returns an empty string on failure.
| access | protected |
|---|
stringThe full path to the file
stringThe encoding to use; one of 'base64', '7bit', '8bit', 'binary', 'quoted-printable'
\phpmailerException |
|---|
stringendBoundary(string $boundary) : string
| access | protected |
|---|
string
stringgenerateId() : string
stringgetBoundary(string $boundary, string $charSet, string $contentType, string $encoding) : string
| access | protected |
|---|
string
string
string
string
stringisPermittedPath(string $path) : boolean
Used to reject URLs and phar files from functions that access local file paths, such as addAttachment.
stringA relative or absolute path to a file.
booleanisShellSafe(string $string) : boolean
Note that escapeshellarg and escapeshellcmd are inadequate for our purposes, especially on Windows.
| see | CVE-2016-10045 bug report |
|---|---|
| access | protected |
stringThe string to be validated
booleanlang(string $key) : string
| access | protected |
|---|
string
stringmailSend(string $header, string $body) : boolean
| link | http://www.php.net/manual/en/book.mail.php |
|---|---|
| access | protected |
stringThe message headers
stringThe message body
\phpmailerException |
|---|
booleansendmailSend(string $header, string $body) : boolean
serverHostname() : string
Returns 'localhost.localdomain' if unknown.
| access | protected |
|---|
stringsetError(string $msg) : void
| access | protected |
|---|
string
setMessageType() : void
PHPMailer only supports some preset message types, not arbitrary MIME structures.
| access | protected |
|---|
smtpSend(string $header, string $body) : boolean
Returns false if there is a bad MAIL FROM, RCPT, or DATA input. Uses the PHPMailerSMTP class by default.
| see | to use a different class. |
|---|---|
| uses | |
| access | protected |
stringThe message headers
stringThe message body
\phpmailerException |
|---|
booleanmailPassthru(string $to, string $subject, string $body, string $header, string $params) : boolean
Also, unless sendmail_path points to sendmail (or something that claims to be sendmail), don't pass params (not a perfect fix, but it will do)
| access | private |
|---|
stringTo
stringSubject
stringMessage Body
stringAdditional Header(s)
stringParams
boolean$AllowEmpty : boolean
false$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 CRAM-MD5, LOGIN, PLAIN, attempted in that order if not specified
$Body : string
''If HTML then call isHTML(true).
$CharSet : string
'iso-8859-1'$ConfirmReadingTo : string
''$ContentType : string
'text/plain'$DKIM_domain : string
''| example |
|---|
$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_string : string
''If set, takes precedence over $DKIM_private.
$DKIM_selector : string
''$Debugoutput : string | callable
'echo'Options:
echo Output plain-text as-is, appropriate for CLIhtml Output escaped, line breaks converted to <br>, appropriate for browser outputerror_log Output to error log as configured in php.iniAlternatively, 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 |
|---|
$Encoding : string
'8bit'Options: "8bit", "7bit", "binary", "base64", and "quoted-printable".
$ErrorInfo : string
''$From : string
'root@localhost'$FromName : string
'Root User'$Helo : string
''$Host : string
'localhost'Either a single hostname or multiple semicolon-delimited hostnames. You can also specify a different port for each host by using this format: [hostname:port] (e.g. "smtp1.example.com:25;smtp2.example.com"). You can also specify encryption type, for example: (e.g. "tls://smtp1.example.com:587;ssl://smtp2.example.com:465"). Hosts will be tried in order.
$Hostname : 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
| link | http://sprain.ch/blog/downloads/php-class-easypeasyics-create-ical-files-with-php/ |
|---|---|
| link | http://kigkonsult.se/iCalcreator/ |
$LE : string
"\n"| note | The default remains "\n". We force CRLF where we know it must be used via self::CRLF. |
|---|
$Mailer : string
'mail'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. 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 |
|---|
$Password : string
''$PluginDir : string
''Useful if the SMTP class is not in the PHP include path.
| deprecated | Should not be needed now there is an autoloader. |
|---|
$Port : integer
25| TODO | Why is this needed when the SMTP class takes care of it? |
|---|
$Priority : integer
nullOptions: null (default), 1 = High, 3 = Normal, 5 = low. When null, the header is not set at all.
$Realm : string
''Used for NTLM auth
$ReturnPath : string
''If empty, it will be set to either From or Sender.
| 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. |
|---|---|
| link | RFC5321 reference |
$SMTPAuth : boolean
false$SMTPAutoTLS : boolean
trueBe aware that in PHP >= 5.6 this requires that the server's certificates are valid.
$SMTPDebug : integer
0$SMTPKeepAlive : boolean
falseIf this is set to true then to close the connection requires an explicit call to smtpClose().
$SMTPOptions : array
array()$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
'/usr/sbin/sendmail'$SingleTo : boolean
falseOnly supported in mail and sendmail transports, not in SMTP.
$SingleToArray : array
array()| TODO | This should really not be public |
|---|
$Subject : string
''$Timeout : integer
300Default of 5 minutes (300sec) is from RFC2821 section 4.5.3.2
$UseSendmailOptions : boolean
trueOne which supports sendmail's "-oi -f" options.
$Username : string
''$Version : string
'5.2.27'$WordWrap : integer
0Set to 0 to not wrap. A useful value here is 78, for RFC2822 section 2.1.1 compliance.
$Workstation : string
''Used for NTLM auth
$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 array $to email addresses of the recipients array $cc cc email addresses array $bcc bcc email addresses string $subject the subject string $body the email body string $from email address of sender
$do_verp : boolean
falseOnly applicable when sending via SMTP.
| link | https://en.wikipedia.org/wiki/Variable_envelope_return_path |
|---|---|
| link | Postfix VERP info |
$validator : string | callable
'auto'$CustomHeader : array
array()| access | protected |
|---|
$MIMEBody : string
''| access | protected |
|---|
$MIMEHeader : string
''| access | protected |
|---|
$RecipientsQueue : array
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.
| access | protected |
|---|---|
| see | @see PHPMailer::$cc @see PHPMailer::$bcc |
| see |
$ReplyTo : array
array()| access | protected |
|---|
$ReplyToQueue : array
array()$all_recipients : array
array()Includes all of $to, $cc, $bcc
| access | protected |
|---|---|
| see | @see PHPMailer::$cc @see PHPMailer::$bcc |
$bcc : array
array()| access | protected |
|---|
$boundary : array
array()| access | protected |
|---|
$cc : array
array()| access | protected |
|---|
$error_count : integer
0| access | protected |
|---|
$exceptions : boolean
false| access | protected |
|---|
$language : array
array()| access | protected |
|---|
$lastMessageID : string
''| access | protected |
|---|
$mailHeader : string
''| access | protected |
|---|
$sign_cert_file : string
''| access | protected |
|---|
$sign_extracerts_file : string
''| access | protected |
|---|
$sign_key_file : string
''| access | protected |
|---|
$sign_key_pass : string
''Used only if the key is encrypted.
| access | protected |
|---|
$smtp : \SMTP
null| access | protected |
|---|
$to : array
array()| access | protected |
|---|
$uniqueid : string
''| access | protected |
|---|
CRLF = "\r\n"
MAX_LINE_LENGTH = 998 : integer
STOP_CONTINUE = 1
STOP_CRITICAL = 2
STOP_MESSAGE = 0