Moodle PHP Documentation 4.3
Moodle 4.3.5 (Build: 20240610) (7dcfaa79f78)
|
Moodle Customised version of the PHPMailer class. More...
Public Member Functions | |
__construct () | |
Constructor - creates an instance of the PHPMailer class with Moodle defaults. | |
addAddress ($address, $name='') | |
Add a "To" address. | |
addBCC ($address, $name='') | |
Add a "BCC" address. | |
addCC ($address, $name='') | |
Add a "CC" address. | |
addCustomHeader ($custom_header, $value=null) | |
Extended AddCustomHeader function in order to stop duplicate message-ids http://tracker.moodle.org/browse/MDL-3681. | |
addReplyTo ($address, $name='') | |
Add a "Reply-To" address. | |
encodeHeader ($str, $position='text') | |
Use internal moodles own core_text to encode mimeheaders. | |
getLastMessageID () | |
Return the Message-ID header of the last email. | |
getSMTPInstance () | |
Get an instance to use for SMTP operations. | |
isHTML ($isHtml=true) | |
Sets message type to HTML or plain. | |
isMail () | |
Send messages using PHP's mail() function. | |
isQmail () | |
Send messages using qmail. | |
isSendmail () | |
Send messages using $Sendmail. | |
isSMTP () | |
Send messages using SMTP. | |
postSend () | |
Sends this mail. | |
preSend () | |
Prepare a message for sending. | |
punyencodeAddress ($address) | |
Converts IDN in given email address to its ASCII form, also known as punycode, if possible. | |
send () | |
Create a message and send it. | |
setBoundaries () | |
Set the boundaries to use for delimiting MIME parts. | |
setFrom ($address, $name='', $auto=true) | |
Set the From and FromName properties. | |
setLanguage ($langcode='en', $lang_path='') | |
Set the language for error messages. | |
setSMTPInstance (SMTP $smtp) | |
Provide an instance to use for SMTP operations. | |
smtpClose () | |
Close the active SMTP session if one exists. | |
smtpConnect ($options=null) | |
Initiate a connection to an SMTP server. | |
Static Public Member Functions | |
static | idnSupported () |
Tells whether IDNs (Internationalized Domain Names) are supported or not. | |
static | parseAddresses ($addrstr, $useimap=true, $charset=self::CHARSET_ISO88591) |
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. | |
static | rfcDate () |
Replaced function to fix tz bug: http://tracker.moodle.org/browse/MDL-12596. | |
static | validateAddress ($address, $patternselect=null) |
Check that a string looks like an email address. | |
Public Attributes | |
string | $action_function = '' |
Callback Action function name. | |
bool | $AllowEmpty = false |
Whether to allow sending messages with an empty body. | |
string | $AltBody = '' |
The plain-text message body. | |
string | $AuthType = '' |
SMTP authentication type. | |
string | $Body = '' |
An HTML or plain text message body. | |
string | $CharSet = self::CHARSET_ISO88591 |
The character set of the message. | |
string | $ConfirmReadingTo = '' |
The email address that a reading confirmation should be sent to, also known as read receipt. | |
string | $ContentType = self::CONTENT_TYPE_PLAINTEXT |
The MIME Content-type of the message. | |
string callable Psr Log LoggerInterface | $Debugoutput = 'echo' |
How to handle debug output. | |
bool | $DKIM_copyHeaderFields = true |
DKIM Copy header field values for diagnostic use. | |
string | $DKIM_domain = '' |
array | $DKIM_extraHeaders = [] |
string | $DKIM_identity = '' |
DKIM Identity. | |
string | $DKIM_passphrase = '' |
DKIM passphrase. | |
string | $DKIM_private = '' |
DKIM private key file path. | |
string | $DKIM_private_string = '' |
DKIM private key string. | |
string | $DKIM_selector = '' |
DKIM selector. | |
bool | $do_verp = false |
Whether to generate VERP addresses on send. | |
$dsn = '' | |
Comma separated list of DSN notifications 'NEVER' under no circumstances a DSN must be returned to the sender. | |
string | $Encoding = self::ENCODING_8BIT |
The message encoding. | |
string | $ErrorInfo = '' |
Holds the most recent mailer error message. | |
return | $foundlang |
string | $From = '' |
The From email address for the message. | |
string | $FromName = '' |
The From name of the message. | |
string | $Helo = '' |
The SMTP HELO/EHLO name used for the SMTP connection. | |
string | $Host = 'localhost' |
SMTP hosts. | |
string | $Hostname = '' |
The hostname to use in the Message-ID header and as default HELO string. | |
string | $Ical = '' |
An iCal message part body. | |
string | $Mailer = 'mail' |
Which method to use to send mail. | |
string | $MessageDate = '' |
The message Date to be used in the Date header. | |
string | $MessageID = '' |
An ID to be used in the Message-ID header. | |
string | $Password = '' |
SMTP password. | |
int | $Port = 25 |
The default SMTP server port. | |
int null | $Priority |
Email priority. | |
string | $Sender = '' |
The envelope sender of the message. | |
string | $Sendmail = '/usr/sbin/sendmail' |
The path to the sendmail program. | |
bool | $SingleTo = false |
Whether to split multiple to addresses into multiple messages or send them all in one message. | |
bool | $SMTPAuth = false |
Whether to use SMTP authentication. | |
bool | $SMTPAutoTLS = true |
Whether to enable TLS encryption automatically if a server supports it, even if SMTPSecure is not set to 'tls'. | |
int | $SMTPDebug = 0 |
SMTP class debug output mode. | |
bool | $SMTPKeepAlive = false |
Whether to keep the SMTP connection open after each message. | |
array | $SMTPOptions = [] |
Options array passed to stream_context_create when connecting via SMTP. | |
string | $SMTPSecure = '' |
What kind of encryption to use on the SMTP connection. | |
string | $Subject = '' |
The Subject of the message. | |
int | $Timeout = 300 |
The SMTP server timeout in seconds. | |
string | $Username = '' |
SMTP username. | |
bool | $UseSendmailOptions = true |
Whether mail() uses a fully sendmail-compatible MTA. | |
int | $WordWrap = 0 |
Word-wrap the message body to this number of chars. | |
string null | $XMailer = '' |
What to put in the X-Mailer header. | |
const | CHARSET_ASCII = 'us-ascii' |
const | CHARSET_ISO88591 = 'iso-8859-1' |
const | CHARSET_UTF8 = 'utf-8' |
const | CONTENT_TYPE_MULTIPART_ALTERNATIVE = 'multipart/alternative' |
const | CONTENT_TYPE_MULTIPART_MIXED = 'multipart/mixed' |
const | CONTENT_TYPE_MULTIPART_RELATED = 'multipart/related' |
const | CONTENT_TYPE_PLAINTEXT = 'text/plain' |
const | CONTENT_TYPE_TEXT_CALENDAR = 'text/calendar' |
const | CONTENT_TYPE_TEXT_HTML = 'text/html' |
const | CRLF = "\r\n" |
The SMTP standard CRLF line break. | |
const | ENCODING_7BIT = '7bit' |
const | ENCODING_8BIT = '8bit' |
const | ENCODING_BASE64 = 'base64' |
const | ENCODING_BINARY = 'binary' |
const | ENCODING_QUOTED_PRINTABLE = 'quoted-printable' |
const | ENCRYPTION_SMTPS = 'ssl' |
const | ENCRYPTION_STARTTLS = 'tls' |
const | FWS = ' ' |
"Folding White Space" a white space string used for line folding. | |
const | ICAL_METHOD_ADD = 'ADD' |
const | ICAL_METHOD_CANCEL = 'CANCEL' |
const | ICAL_METHOD_COUNTER = 'COUNTER' |
const | ICAL_METHOD_DECLINECOUNTER = 'DECLINECOUNTER' |
const | ICAL_METHOD_PUBLISH = 'PUBLISH' |
const | ICAL_METHOD_REFRESH = 'REFRESH' |
const | ICAL_METHOD_REPLY = 'REPLY' |
const | ICAL_METHOD_REQUEST = 'REQUEST' |
$this | language = $PHPMAILER_LANG |
int const | MAIL_MAX_LINE_LENGTH = 63 |
The maximum line length supported by mail(). | |
int const | MAX_LINE_LENGTH = 998 |
The maximum line length allowed by RFC 2822 section 2.1.1. | |
int const | STD_LINE_LENGTH = 76 |
The lower maximum line length allowed by RFC 2822 section 2.1.1. | |
int const | STOP_CONTINUE = 1 |
Error severity: message, likely ok to continue processing. | |
int const | STOP_CRITICAL = 2 |
Error severity: message, plus full stop, critical error reached. | |
int const | STOP_MESSAGE = 0 |
Error severity: message only, continue processing. | |
string const | VERSION = '6.8.0' |
The PHPMailer Version number. | |
Static Public Attributes | |
static string callable | $validator = 'php' |
Which validator to use by default when validating email addresses. | |
Protected Member Functions | |
addAnAddress ($kind, $address, $name='') | |
Add an address to one of the recipient arrays or to the ReplyTo array. | |
addOrEnqueueAnAddress ($kind, $address, $name) | |
Add an address to one of the recipient arrays or to the ReplyTo array. | |
edebug ($str) | |
Output debugging info via a user-defined method. | |
mailSend ($header, $body) | |
Send mail using the PHP mail() function. | |
sendmailSend ($header, $body) | |
Send mail using the $Sendmail program. | |
smtpSend ($header, $body) | |
Send mail via SMTP. | |
Static Protected Member Functions | |
static | fileIsAccessible ($path) |
Check whether a file path is safe, accessible, and readable. | |
static | isPermittedPath ($path) |
Check whether a file path is of a permitted type. | |
static | isShellSafe ($string) |
Fix CVE-2016-10033 and CVE-2016-10045 by disallowing potentially unsafe shell characters. | |
Protected Attributes | |
array | $all_recipients = [] |
An array of all kinds of addresses. | |
array | $attachment = [] |
The array of attachments. | |
array | $bcc = [] |
The array of 'bcc' names and addresses. | |
array | $boundary = [] |
The array of MIME boundary strings. | |
array | $cc = [] |
The array of 'cc' names and addresses. | |
array | $CustomHeader = [] |
The array of custom headers. | |
int | $error_count = 0 |
The number of errors encountered. | |
bool | $exceptions = false |
Whether to throw exceptions for errors. | |
array | $language = [] |
The array of available text strings for the current language. | |
string | $lastMessageID = '' |
The most recent Message-ID (including angular brackets). | |
string | $mailHeader = '' |
Extra headers that createHeader() doesn't fold in. | |
string | $message_type = '' |
The message's MIME type. | |
string | $MIMEBody = '' |
The complete compiled MIME message body. | |
string | $MIMEHeader = '' |
The complete compiled MIME message headers. | |
OAuthTokenProvider | $oauth |
An implementation of the PHPMailer OAuthTokenProvider interface. | |
array | $RecipientsQueue = [] |
An array of names and addresses queued for validation. | |
array | $ReplyTo = [] |
The array of reply-to names and addresses. | |
array | $ReplyToQueue = [] |
An array of reply-to names and addresses queued for validation. | |
string | $sign_cert_file = '' |
The S/MIME certificate file path. | |
string | $sign_extracerts_file = '' |
The optional S/MIME extra certificates ("CA Chain") file path. | |
string | $sign_key_file = '' |
The S/MIME key file path. | |
string | $sign_key_pass = '' |
The S/MIME password for the key. | |
array | $SingleToArray = [] |
Storage for addresses when SingleTo is enabled. | |
SMTP | $smtp |
An instance of the SMTP sender class. | |
array | $to = [] |
The array of 'to' names and addresses. | |
string | $uniqueid = '' |
Unique ID used for message ID and boundaries. | |
Static Protected Attributes | |
static string[] | $IcalMethods |
Value-array of "method" in Contenttype header "text/calendar". | |
static string | $LE = self::CRLF |
SMTP RFC standard line ending; Carriage Return, Line Feed. | |
Moodle Customised version of the PHPMailer class.
This class extends the stock PHPMailer class in order to make sensible configuration choices, and behave in a way which is friendly to moodle.
|
inherited |
Add a "To" address.
string | $address | The email address to send to |
string | $name |
Exception |
bool | true on success, false if address already used or invalid in some way |
|
protectedinherited |
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.
string | $kind | One of 'to', 'cc', 'bcc', or 'ReplyTo' |
string | $address | The email address to send, resp. to reply to |
string | $name |
Exception |
bool | true on success, false if address already used or invalid in some way |
|
inherited |
Add a "BCC" address.
string | $address | The email address to send to |
string | $name |
Exception |
bool | true on success, false if address already used or invalid in some way |
|
inherited |
Add a "CC" address.
string | $address | The email address to send to |
string | $name |
Exception |
bool | true on success, false if address already used or invalid in some way |
|
protectedinherited |
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.
string | $kind | One of 'to', 'cc', 'bcc', or 'ReplyTo' |
string | $address | The email address |
string | $name | An optional username associated with the address |
Exception |
bool | true on success, false if address already used or invalid in some way |
|
inherited |
Add a "Reply-To" address.
string | $address | The email address to reply to |
string | $name |
Exception |
bool | true on success, false if address already used or invalid in some way |
|
protectedinherited |
Output debugging info via a user-defined method.
Only generates output if debug output is enabled.
string | $str |
moodle_phpmailer::encodeHeader | ( | $str, | |
$position = 'text' ) |
Use internal moodles own core_text to encode mimeheaders.
Fall back to phpmailers inbuilt functions if not
|
staticprotectedinherited |
Check whether a file path is safe, accessible, and readable.
string | $path | A relative or absolute path to a file |
bool |
|
inherited |
Return the Message-ID header of the last email.
Technically this is the value from the last time the headers were created, but it's also the message ID of the last sent message except in pathological cases.
string |
|
inherited |
Get an instance to use for SMTP operations.
Override this function to load your own SMTP implementation, or set one with setSMTPInstance.
SMTP |
|
staticinherited |
Tells whether IDNs (Internationalized Domain Names) are supported or not.
This requires the intl
and mbstring
PHP extensions.
bool | true if required functions for IDN support are present |
|
inherited |
Sets message type to HTML or plain.
bool | $isHtml | True for HTML mode |
|
staticprotectedinherited |
Check whether a file path is of a permitted type.
Used to reject URLs and phar files from functions that access local file paths, such as addAttachment.
string | $path | A relative or absolute path to a file |
bool |
|
staticprotectedinherited |
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.
string | $string | The string to be validated |
bool |
|
protectedinherited |
Send mail using the PHP mail() function.
string | $header | The message headers |
string | $body | The message body |
Exception |
bool |
|
staticinherited |
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.
string | $addrstr | The address list string |
bool | $useimap | Whether to use the IMAP extension to parse the list |
string | $charset | The charset to use when decoding the address list string. |
array |
moodle_phpmailer::postSend | ( | ) |
Sends this mail.
This function has been overridden to facilitate unit testing.
bool |
Reimplemented from PHPMailer\PHPMailer\PHPMailer.
|
inherited |
|
inherited |
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:
string | $address | The email address to convert |
string | The encoded address in ASCII form |
|
inherited |
Create a message and send it.
Uses the sending method specified by $Mailer.
Exception |
bool | false on error - See the ErrorInfo property for details of the error |
|
protectedinherited |
Send mail using the $Sendmail program.
string | $header | The message headers |
string | $body | The message body |
Exception |
bool |
|
inherited |
Set the boundaries to use for delimiting MIME parts.
If you override this, ensure you set all 3 boundaries to unique values. The default boundaries include a "=_" sequence which cannot occur in quoted-printable bodies, as suggested by https://www.rfc-editor.org/rfc/rfc2045#section-6.7
void |
|
inherited |
Set the From and FromName properties.
string | $address | |
string | $name | |
bool | $auto | Whether to also set the Sender address, defaults to true |
Exception |
bool |
|
inherited |
Set the language for error messages.
The default language is English.
string | $langcode | ISO 639-1 2-character language code (e.g. French is "fr") Optionally, the language code can be enhanced with a 4-character script annotation and/or a 2-character country annotation. |
string | $lang_path | Path to the language file directory, with trailing separator (slash) Do not set this from user input! |
bool | Returns true if the requested language was loaded, false otherwise. |
|
inherited |
Provide an instance to use for SMTP operations.
SMTP |
|
inherited |
Initiate a connection to an SMTP server.
Returns false if the operation failed.
array | $options | An array of options compatible with stream_context_create() |
Exception |
@uses PHPMailer\PHPMailer\SMTP
bool |
|
protectedinherited |
Send mail via SMTP.
Returns false if there is a bad MAIL FROM, RCPT, or DATA input.
@uses PHPMailer\PHPMailer\SMTP
string | $header | The message headers |
string | $body | The message body |
Exception |
bool |
|
staticinherited |
Check that a string looks like an email address.
Validation patterns supported:
auto
Pick best pattern automatically;pcre8
Use the squiloople.com pattern, requires PCRE > 8.0;pcre
Use old PCRE implementation;php
Use PHP built-in FILTER_VALIDATE_EMAIL;html5
Use the pattern given by the HTML5 spec for 'email' type form input elements.noregex
Don't use a regex: super fast, really dumb. Alternatively you may pass in a callable to inject your own validator, for example:You can also set the PHPMailer\$validator static to a callable, allowing built-in methods to use your validator.
string | $address | The email address to check |
string | callable | $patternselect | Which pattern to use |
bool |
|
inherited |
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: bool $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 string $extra extra information of possible use "smtp_transaction_id' => last smtp transaction id
|
protectedinherited |
An array of all kinds of addresses.
Includes all of $to, $cc, $bcc.
|
inherited |
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.
|
inherited |
SMTP authentication type.
Options are CRAM-MD5, LOGIN, PLAIN, XOAUTH2. If not specified, the first one from that list that the server supports will be selected.
|
inherited |
An HTML or plain text message body.
If HTML then call isHTML(true).
|
inherited |
How to handle debug output.
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.ini By default PHPMailer will use echo
if run from a cli
or cli-server
SAPI, html
otherwise. Alternatively, you can provide a callable expecting two params: a message string and the debug level:Alternatively, you can pass in an instance of a PSR-3 compatible logger, though only debug
level output is used:
|
inherited |
DKIM Identity.
Usually the email address used as the source of the email.
|
inherited |
DKIM passphrase.
Used if your key is encrypted.
|
inherited |
DKIM private key string.
If set, takes precedence over $DKIM_private
.
|
inherited |
Whether to generate VERP addresses on send.
Only applicable when sending via SMTP.
|
inherited |
Comma separated list of DSN notifications 'NEVER' under no circumstances a DSN must be returned to the sender.
If you use NEVER all other notifications will be ignored. 'SUCCESS' will notify you when your mail has arrived at its destination. 'FAILURE' will arrive if an error occurred during delivery. 'DELAY' will notify you if there is an unusual delay in delivery, but the actual delivery's outcome (success or failure) is not yet decided.
|
inherited |
The message encoding.
Options: "8bit", "7bit", "binary", "base64", and "quoted-printable".
|
inherited |
The SMTP HELO/EHLO name used for the SMTP connection.
Default is $Hostname. If $Hostname is empty, PHPMailer attempts to find one with the same method described above for $Hostname.
|
inherited |
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.
|
inherited |
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'.
|
inherited |
An iCal message part body.
Only supported in simple alt or alt_inline message types To generate iCal event structures, use classes like EasyPeasyICS or iCalcreator.
|
staticprotectedinherited |
Value-array of "method" in Contenttype header "text/calendar".
|
inherited |
Which method to use to send mail.
Options: "mail", "sendmail", or "smtp".
|
inherited |
|
inherited |
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.
|
inherited |
Email priority.
Options: null (default), 1 = High, 3 = Normal, 5 = low. When null, the header is not set at all.
|
protectedinherited |
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.
|
protectedinherited |
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.
|
inherited |
The envelope sender of the message.
This will usually be turned into a Return-Path header by the receiver, and is the address that bounces will be sent to. If not empty, will be passed via -f
to sendmail or as the 'MAIL FROM' value over SMTP.
|
protectedinherited |
The S/MIME password for the key.
Used only if the key is encrypted.
|
inherited |
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.
|
inherited |
Whether to use SMTP authentication.
Uses the Username and Password properties.
|
inherited |
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.
|
inherited |
SMTP class debug output mode.
Debug output level. Options:
|
inherited |
Whether to keep the SMTP connection open after each message.
If this is set to true then the connection will remain open after a send, and closing the connection will require an explicit call to smtpClose(). It's a good idea to use this if you are sending multiple messages as it reduces overhead. See the mailing list example for how to use it.
|
inherited |
What kind of encryption to use on the SMTP connection.
Options: '', static\ENCRYPTION_STARTTLS, or static\ENCRYPTION_SMTPS.
|
inherited |
The SMTP server timeout in seconds.
Default of 5 minutes (300sec) is from RFC2821 section 4.5.3.2.
|
inherited |
Whether mail() uses a fully sendmail-compatible MTA.
One which supports sendmail's "-oi -f" options.
|
staticinherited |
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. The default validator uses PHP's FILTER_VALIDATE_EMAIL filter_var option.
|
inherited |
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.
|
inherited |
What to put in the X-Mailer header.
Options: An empty string for PHPMailer default, whitespace/null for none, or a string to use.
|
inherited |
The SMTP standard CRLF line break.
If you want to change line break format, change static\$LE, not this.
|
inherited |
The maximum line length supported by mail().
Background: mail() will sometimes corrupt messages with headers headers longer than 65 chars, see #818.
|
inherited |
The lower maximum line length allowed by RFC 2822 section 2.1.1.
This length does NOT include the line break 76 means that lines will be 77 or 78 chars depending on whether the line break format is LF or CRLF; both are valid.