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 |
---|
string
Header lines
string
Subject
string
Body
string
DKIM_BodyC(string $body) : string
access | public |
---|
string
Message Body
string
DKIM_HeaderC(string $signHeader) : string
access | public |
---|
string
Header
string
DKIM_QP(string $txt) : string
access | public |
---|
string
string
DKIM_Sign(string $signHeader) : string
access | public |
---|
string
\phpmailerException |
---|
string
The DKIM signature value__construct(boolean $exceptions = null
)
boolean
Should we throw external exceptions?
__destruct()
_mime_types(string $ext = ''
) : string
access | public |
---|---|
static |
string
File extension
string
MIME type of file.addAddress(string $address, string $name = ''
) : boolean
string
The email address to send to
string
boolean
true 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.
string
Path to the attachment.
string
Overrides the attachment name.
string
File encoding (see $Encoding).
string
File extension (MIME) type.
string
Disposition to use
\phpmailerException |
---|
boolean
addBCC(string $address, string $name = ''
) : boolean
note | : This function works with the SMTP mailer on win32, not with the "mail" mailer. |
---|
string
The email address to send to
string
boolean
true 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. |
---|
string
The email address to send to
string
boolean
true 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 |
---|
string
Custom header name
string
Header 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!
string
Path to the attachment.
string
Content ID of the attachment; Use this to reference the content when using an embedded image in HTML.
string
Overrides the attachment name.
string
File encoding (see $Encoding).
string
File MIME type.
string
Disposition to use
boolean
True on successfully adding an attachmentaddReplyTo(string $address, string $name = ''
) : boolean
string
The email address to reply to
string
boolean
true 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.
string
String attachment data.
string
Name of the attachment.
string
File encoding (see $Encoding).
string
File extension (MIME) type.
string
Disposition 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'.
string
The attachment binary data.
string
Content ID of the attachment; Use this to reference the content when using an embedded image in HTML.
string
string
File encoding (see $Encoding).
string
MIME type.
string
Disposition to use
boolean
True on successfully adding an attachmentaddrAppend(string $type, array $addr) : string
access | public |
---|
string
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: array(array('joe@example.com', 'Joe User'), array('zoe@example.com', 'Zoe User'))
string
addrFormat(array $addr) : string
access | public |
---|
array
A 2-element indexed array, element 0 containing an address, element 1 containing a name like array('joe@example.com', 'Joe User')
string
alternativeExists() : boolean
boolean
base64EncodeWrapMB(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 |
string
multi-byte text to wrap encode
string
string to use as linefeed/end-of-line
string
clearAddresses() : 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 |
---|
string
The assembled message bodycreateHeader() : string
access | public |
---|
string
The assembled headersencodeHeader(string $str, string $position = 'text'
) : string
Picks shortest of Q, B, quoted-printable or none.
access | public |
---|
string
string
string
encodeQ(string $str, string $position = 'text'
) : string
link | http://tools.ietf.org/html/rfc2047 |
---|---|
access | public |
string
the text to encode
string
Where the text is going to be used, see the RFC for what that means
string
encodeQP(string $string, integer $line_max = 76
) : string
According to RFC2045 section 6.7.
access | public |
---|---|
link | Adapted from this comment |
string
The text to encode
integer
Number of chars allowed on a line before wrapping
string
encodeQPphp(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 |
---|
string
The text to encode
string
The encoding to use; one of 'base64', '7bit', '8bit', 'binary', 'quoted-printable'
string
filenameToType(string $filename) : string
Defaults to 'application/octet-stream', i.e.. arbitrary binary data.
static |
---|
string
A file name or full path, does not need to exist as a file
string
fixEOL(string $str) : string
Changes every end of line from CRLF, CR or LF to $this->LE.
access | public |
---|
string
String to fixEOL
string
getAllRecipientAddresses() : array
note | : Before the send() call, queued addresses (i.e. with IDN) are not yet included. |
---|---|
access | public |
array
getAttachments() : array
array
getBccAddresses() : array
note | : Before the send() call, queued addresses (i.e. with IDN) are not yet included. |
---|---|
access | public |
array
getCcAddresses() : array
note | : Before the send() call, queued addresses (i.e. with IDN) are not yet included. |
---|---|
access | public |
array
getCustomHeaders() : array
array
getLastMessageID() : string
Technically this is the value from the last time the headers were created, but it's also the message ID of the last sent message except in pathological cases.
string
getMailMIME() : string
access | public |
---|
string
getReplyToAddresses() : array
note | : Before the send() call, queued addresses (i.e. with IDN) are not yet included. |
---|---|
access | public |
array
getSMTPInstance() : \SMTP
Override this function to load your own SMTP implementation
\SMTP
getSentMIMEMessage() : string
getToAddresses() : array
note | : Before the send() call, queued addresses (i.e. with IDN) are not yet included. |
---|---|
access | public |
array
getTranslations() : array
array
has8bitChars(string $text) : boolean
string
boolean
hasLineLongerThanMax(string $str) : boolean
static |
---|
string
boolean
hasMultiBytes(string $str) : boolean
access | public |
---|
string
multi-byte text to wrap encode
boolean
headerLine(string $name, string $value) : string
access | public |
---|
string
string
string
html2text(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();
});
string
The HTML text to convert
boolean
callable
Any boolean value to use the internal converter, or provide your own callable for custom conversion.
string
idnSupported() : boolean
boolean
"true" if required functions for IDN support are presentinlineImageExists() : boolean
access | public |
---|
boolean
isError() : boolean
access | public |
---|
boolean
True if an error did occur.isHTML(boolean $isHtml = true
) : void
boolean
True 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 |
string
A filename or path, does not need to exist as a file
integer
string
Either a PATHINFO_* constant, or a string name to return only the specified piece, allows 'filename' to work on PHP < 5.2
string
array
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 |
---|
string
HTML message string
string
Absolute path to a base directory to prepend to relative paths to images
boolean
callable
Whether 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
string
What kind of line break to use, defaults to CRLF
string
parseAddresses(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 |
---|
string
The address list string
boolean
Whether to use the IMAP extension to parse the list
array
postSend() : boolean
Send the email via the selected mechanism
\phpmailerException |
---|
boolean
preSend() : boolean
\phpmailerException |
---|
boolean
punyencodeAddress(string $address) : string
Important: Address must be passed in same encoding as currently set in PHPMailer::$CharSet. This function silently returns unmodified address if:
see |
---|
string
The email address to convert
string
The encoded address in ASCII formrfcDate() : string
access | public |
---|---|
static |
string
secureHeader(string $str) : string
access | public |
---|
string
string
send() : boolean
Uses the sending method specified by $Mailer.
\phpmailerException |
---|
boolean
false 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? |
string
The property name to set
mixed
The value to set the property to
boolean
setFrom(string $address, string $name= ''
, boolean $auto= true
) : boolean
string
string
boolean
Whether to also set the Sender address, defaults to true
\phpmailerException |
---|
boolean
setLanguage(string $langcode= 'en'
, string $lang_path= ''
) : boolean
Returns false if it cannot load the language file. The default language is English.
access | public |
---|
string
ISO 639-1 2-character language code (e.g. French is "fr")
string
Path to the language file directory, with trailing separator (slash)
boolean
setWordWrap() : 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
string
Password for private key
string
Optional path to chain certificate
smtpClose() : void
smtpConnect(array $options = null
) : boolean
textLine(string $value) : string
access | public |
---|
string
string
utf8CharBoundary(string $encodedText, integer $maxLength) : integer
Original written by Colin Brown.
access | public |
---|
string
utf-8 QP text
integer
Find the last character boundary prior to this length
integer
validateAddress(string $address, string|callable $patternselect = null
) : boolean
static | |
---|---|
access | public |
string
The email address to check
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, 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.boolean
wrapText(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 |
---|
string
The message to wrap
integer
The line length to wrap to
boolean
Whether to run in Quoted-Printable mode
string
addAnAddress(string $kind, string $address, string $name = ''
) : boolean
Addresses that have been added already return false, but do not throw exceptions.
access | protected |
---|
string
One of 'to', 'cc', 'bcc', or 'ReplyTo'
string
The email address to send, resp. to reply to
string
\phpmailerException |
---|
boolean
true 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 |
---|
string
One of 'to', 'cc', 'bcc', or 'ReplyTo'
string
The email address to send, resp. to reply to
string
\phpmailerException |
---|
boolean
true 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
string
doCallback(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 |
---|
string
The full path to the file
string
The encoding to use; one of 'base64', '7bit', '8bit', 'binary', 'quoted-printable'
\phpmailerException |
---|
string
endBoundary(string $boundary) : string
access | protected |
---|
string
string
generateId() : string
string
getBoundary(string $boundary, string $charSet, string $contentType, string $encoding) : string
access | protected |
---|
string
string
string
string
string
isPermittedPath(string $path) : boolean
Used to reject URLs and phar files from functions that access local file paths, such as addAttachment.
string
A relative or absolute path to a file.
boolean
isShellSafe(string $string) : boolean
Note that escapeshellarg and escapeshellcmd are inadequate for our purposes, especially on Windows.
see | CVE-2016-10045 bug report |
---|---|
access | protected |
string
The string to be validated
boolean
lang(string $key) : string
access | protected |
---|
string
string
mailSend(string $header, string $body) : boolean
link | http://www.php.net/manual/en/book.mail.php |
---|---|
access | protected |
string
The message headers
string
The message body
\phpmailerException |
---|
boolean
sendmailSend(string $header, string $body) : boolean
serverHostname() : string
Returns 'localhost.localdomain' if unknown.
access | protected |
---|
string
setError(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 |
string
The message headers
string
The message body
\phpmailerException |
---|
boolean
mailPassthru(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 |
---|
string
To
string
Subject
string
Message Body
string
Additional Header(s)
string
Params
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
null
Options: 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
true
Be aware that in PHP >= 5.6 this requires that the server's certificates are valid.
$SMTPDebug : integer
0
$SMTPKeepAlive : boolean
false
If 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
false
Only supported in mail
and sendmail
transports, not in SMTP.
$SingleToArray : array
array()
TODO | This should really not be public |
---|
$Subject : string
''
$Timeout : integer
300
Default of 5 minutes (300sec) is from RFC2821 section 4.5.3.2
$UseSendmailOptions : boolean
true
One which supports sendmail's "-oi -f" options.
$Username : string
''
$Version : string
'5.2.27'
$WordWrap : integer
0
Set 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
false
Only 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