Moodle PHP Documentation 4.5
Moodle 4.5dev (Build: 20240606) (d3ae1391abe)
|
Classes | |
class | DSNConfigurator |
Configure PHPMailer with DSN string. More... | |
class | Exception |
PHPMailer exception handler. More... | |
class | OAuth |
OAuth - OAuth2 authentication wrapper class. More... | |
interface | OAuthTokenProvider |
OAuthTokenProvider - OAuth2 token provider interface. More... | |
class | PHPMailer |
PHPMailer - PHP email creation and transport class. More... | |
Functions | |
static | _mime_types ($ext='') |
Get the MIME type for a file extension. | |
addAttachment ( $path, $name='', $encoding=self::ENCODING_BASE64, $type='', $disposition='attachment') | |
Add an attachment from a path on the filesystem. | |
addCustomHeader ($name, $value=null) | |
Add a custom header. | |
addEmbeddedImage ( $path, $cid, $name='', $encoding=self::ENCODING_BASE64, $type='', $disposition='inline') | |
Add an embedded (inline) attachment from a file. | |
addrAppend ($type, $addr) | |
Create recipient headers. | |
addrFormat ($addr) | |
Format an address for use in a message header. | |
addStringAttachment ( $string, $filename, $encoding=self::ENCODING_BASE64, $type='', $disposition='attachment') | |
Add a string or binary attachment (non-filesystem). | |
addStringEmbeddedImage ( $string, $cid, $name='', $encoding=self::ENCODING_BASE64, $type='', $disposition='inline') | |
Add an embedded stringified attachment. | |
alternativeExists () | |
Check if this message has an alternative body set. | |
attachAll ($disposition_type, $boundary) | |
Attach all file, string, and binary attachments to the message. | |
attachmentExists () | |
Check if an attachment (non-inline) is present. | |
base64EncodeWrapMB ($str, $linebreak=null) | |
Encode and wrap long multibyte strings for mail headers without breaking lines within a character. | |
cidExists ($cid) | |
Check if an embedded attachment is present with this cid. | |
clearAddresses () | |
Clear all To recipients. | |
clearAllRecipients () | |
Clear all recipient types. | |
clearAttachments () | |
Clear all filesystem, string, and binary attachments. | |
clearBCCs () | |
Clear all BCC recipients. | |
clearCCs () | |
Clear all CC recipients. | |
clearCustomHeader ($name, $value=null) | |
Clear a specific custom header by name or name and value. | |
clearCustomHeaders () | |
Clear all custom headers. | |
clearQueuedAddresses ($kind) | |
Clear queued addresses of given kind. | |
clearReplyTos () | |
Clear all ReplyTo recipients. | |
createBody () | |
Assemble the message body. | |
createHeader () | |
Assemble message headers. | |
DKIM_Add ($headers_line, $subject, $body) | |
Create the DKIM header and body in a new message header. | |
DKIM_BodyC ($body) | |
Generate a DKIM canonicalization body. | |
DKIM_HeaderC ($signHeader) | |
Generate a DKIM canonicalization header. | |
DKIM_QP ($txt) | |
Quoted-Printable-encode a DKIM header. | |
DKIM_Sign ($signHeader) | |
Generate a DKIM signature. | |
doCallback ($isSent, $to, $cc, $bcc, $subject, $body, $from, $extra) | |
Perform a callback. | |
encodeFile ($path, $encoding=self::ENCODING_BASE64) | |
Encode a file attachment in requested format. | |
encodeHeader ($str, $position='text') | |
Encode a header value (not including its label) optimally. | |
encodeQ ($str, $position='text') | |
Encode a string using Q encoding. | |
encodeQP ($string) | |
Encode a string in quoted-printable format. | |
encodeString ($str, $encoding=self::ENCODING_BASE64) | |
Encode a string in requested format. | |
endBoundary ($boundary) | |
Return the end of a message boundary. | |
static | filenameToType ($filename) |
Map a file name to a MIME type. | |
generateId () | |
Create a unique ID to use for boundaries. | |
getAllRecipientAddresses () | |
Allows for public read access to 'all_recipients' property. | |
getAttachments () | |
Return the array of attachments. | |
getBccAddresses () | |
Allows for public read access to 'bcc' property. | |
getBoundaries () | |
Get the boundaries that this message will use. | |
getBoundary ($boundary, $charSet, $contentType, $encoding) | |
Return the start of a message boundary. | |
getCcAddresses () | |
Allows for public read access to 'cc' property. | |
getCustomHeaders () | |
Returns all custom headers. | |
static | getLE () |
Return the current line break format string. | |
getMailMIME () | |
Get the message MIME type headers. | |
getOAuth () | |
Get the OAuthTokenProvider instance. | |
getReplyToAddresses () | |
Allows for public read access to 'ReplyTo' property. | |
getSentMIMEMessage () | |
Returns the whole MIME message. | |
getToAddresses () | |
Allows for public read access to 'to' property. | |
getTranslations () | |
Get the array of strings for the current language. | |
has8bitChars ($text) | |
Does a string contain any 8-bit chars (in any charset)? | |
static | hasLineLongerThanMax ($str) |
Detect if a string contains a line longer than the maximum line length allowed by RFC 2822 section 2.1.1. | |
hasMultiBytes ($str) | |
Check if a string contains multi-byte characters. | |
headerLine ($name, $value) | |
Format a header line. | |
html2text ($html, $advanced=false) | |
Convert an HTML string into plain text. | |
inlineImageExists () | |
Check if an inline attachment is present. | |
isError () | |
Check if an error occurred. | |
static | isValidHost ($host) |
Validate whether a string contains a valid value to use as a hostname or IP address. | |
lang ($key) | |
Get an error message in the current language. | |
static | mb_pathinfo ($path, $options=null) |
Multi-byte-safe pathinfo replacement. | |
msgHTML ($message, $basedir='', $advanced=false) | |
Create a message body from an HTML string. | |
static | normalizeBreaks ($text, $breaktype=null) |
Normalize line breaks in a string. | |
static | quotedString ($str) |
If a string contains any "special" characters, double-quote the name, and escape any double quotes with a backslash. | |
replaceCustomHeader ($name, $value=null) | |
Replace a custom header. | |
static | rfcDate () |
Return an RFC 822 formatted date. | |
secureHeader ($str) | |
Strip newlines to prevent header injection. | |
serverHostname () | |
Get the server hostname. | |
set ($name, $value='') | |
Set or reset instance properties. | |
setError ($msg) | |
Add an error message to the error container. | |
static | setLE ($le) |
Set the line break format string, e.g. | |
setMessageType () | |
Set the message type. | |
setOAuth (OAuthTokenProvider $oauth) | |
Set an OAuthTokenProvider instance. | |
setWordWrap () | |
Apply word wrapping to the message body. | |
sign ($cert_filename, $key_filename, $key_pass, $extracerts_filename='') | |
Set the public and private key files and password for S/MIME signing. | |
static | stripTrailingBreaks ($text) |
Strip trailing line breaks from a string. | |
static | stripTrailingWSP ($text) |
Remove trailing whitespace from a string. | |
textLine ($value) | |
Return a formatted mail line. | |
utf8CharBoundary ($encodedText, $maxLength) | |
Find the last character boundary prior to $maxLength in a utf-8 quoted-printable encoded string. | |
validateEncoding ($encoding) | |
Validate encodings. | |
wrapText ($message, $length, $qp_mode=false) | |
Word-wrap message. | |
Variables | |
$this | AltBody = static::normalizeBreaks($this->html2text($message, $advanced)) |
$this | Body = static::normalizeBreaks($message) |
|
static |
Get the MIME type for a file extension.
string | $ext | File extension |
string | MIME type of file |
PHPMailer\PHPMailer\addAttachment | ( | $path, | |
$name = '', | |||
$encoding = self::ENCODING_BASE64, | |||
$type = '', | |||
$disposition = 'attachment' ) |
Add an attachment from a path on the filesystem.
Never use a user-supplied path to a file! Returns false if the file could not be found or read. Explicitly does not support passing URLs; PHPMailer is not an HTTP client. If you need to do that, fetch the resource yourself and pass it in via a local file or string.
string | $path | Path to the attachment |
string | $name | Overrides the attachment name |
string | $encoding | File encoding (see $Encoding) |
string | $type | MIME type, e.g. image/jpeg ; determined automatically from $path if not specified |
string | $disposition | Disposition to use |
Exception |
bool |
PHPMailer\PHPMailer\addCustomHeader | ( | $name, | |
$value = null ) |
Add a custom header.
$name value can be overloaded to contain both header name and value (name:value).
string | $name | Custom header name |
string | null | $value | Header value |
bool | True if a header was set successfully |
Exception |
PHPMailer\PHPMailer\addEmbeddedImage | ( | $path, | |
$cid, | |||
$name = '', | |||
$encoding = self::ENCODING_BASE64, | |||
$type = '', | |||
$disposition = 'inline' ) |
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 in img
tags, for example <img src="cid:mylogo">
. Never use a user-supplied path to a file!
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 filename |
string | $encoding | File encoding (see $Encoding) defaults to base64 |
string | $type | File MIME type (by default mapped from the $path filename's extension) |
string | $disposition | Disposition to use: inline (default) or attachment (unlikely you want this – { |
addAttachment()
} instead)bool | True on successfully adding an attachment |
Exception |
PHPMailer\PHPMailer\addrAppend | ( | $type, | |
$addr ) |
Create recipient headers.
string | $type | |
array | $addr | An array of recipients, where each recipient is a 2-element indexed array with element 0 containing an address and element 1 containing a name, like: [['joe@e.nosp@m.xamp.nosp@m.le.co.nosp@m.m', 'Joe User'], ['zoe@e.nosp@m.xamp.nosp@m.le.co.nosp@m.m', 'Zoe User']] |
string |
PHPMailer\PHPMailer\addrFormat | ( | $addr | ) |
Format an address for use in a message header.
array | $addr | A 2-element indexed array, element 0 containing an address, element 1 containing a name like ['joe@e.nosp@m.xamp.nosp@m.le.co.nosp@m.m', 'Joe User'] |
string |
PHPMailer\PHPMailer\addStringAttachment | ( | $string, | |
$filename, | |||
$encoding = self::ENCODING_BASE64, | |||
$type = '', | |||
$disposition = 'attachment' ) |
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.
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 |
Exception |
bool | True on successfully adding an attachment |
PHPMailer\PHPMailer\addStringEmbeddedImage | ( | $string, | |
$cid, | |||
$name = '', | |||
$encoding = self::ENCODING_BASE64, | |||
$type = '', | |||
$disposition = 'inline' ) |
Add an embedded stringified attachment.
This can include images, sounds, and just about any other document type. If your filename doesn't contain an extension, be sure to set the $type to an appropriate MIME type.
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 | A filename for the attachment. If this contains an extension, PHPMailer will attempt to set a MIME type for the attachment. For example 'file.jpg' would get an 'image/jpeg' MIME type. |
string | $encoding | File encoding (see $Encoding), defaults to 'base64' |
string | $type | MIME type - will be used in preference to any automatically derived type |
string | $disposition | Disposition to use |
Exception |
bool | True on successfully adding an attachment |
PHPMailer\PHPMailer\alternativeExists | ( | ) |
Check if this message has an alternative body set.
bool |
|
protected |
Attach all file, string, and binary attachments to the message.
Returns an empty string on failure.
string | $disposition_type | |
string | $boundary |
Exception |
string |
PHPMailer\PHPMailer\attachmentExists | ( | ) |
Check if an attachment (non-inline) is present.
bool |
PHPMailer\PHPMailer\base64EncodeWrapMB | ( | $str, | |
$linebreak = null ) |
Encode and wrap long multibyte strings for mail headers without breaking lines within a character.
Adapted from a function by paravoid.
string | $str | multi-byte text to wrap encode |
string | $linebreak | string to use as linefeed/end-of-line |
string |
|
protected |
Check if an embedded attachment is present with this cid.
string | $cid |
bool |
PHPMailer\PHPMailer\clearCustomHeader | ( | $name, | |
$value = null ) |
Clear a specific custom header by name or name and value.
$name value can be overloaded to contain both header name and value (name:value).
string | $name | Custom header name |
string | null | $value | Header value |
bool | True if a header was replaced successfully |
PHPMailer\PHPMailer\clearQueuedAddresses | ( | $kind | ) |
Clear queued addresses of given kind.
string | $kind | 'to', 'cc', or 'bcc' |
PHPMailer\PHPMailer\createBody | ( | ) |
Assemble the message body.
Returns an empty string on failure.
Exception |
string | The assembled message body |
PHPMailer\PHPMailer\createHeader | ( | ) |
Assemble message headers.
string | The assembled headers |
PHPMailer\PHPMailer\DKIM_Add | ( | $headers_line, | |
$subject, | |||
$body ) |
Create the DKIM header and body in a new message header.
string | $headers_line | Header lines |
string | $subject | Subject |
string | $body | Body |
Exception |
string |
PHPMailer\PHPMailer\DKIM_BodyC | ( | $body | ) |
Generate a DKIM canonicalization body.
Uses the 'simple' algorithm from RFC6376 section 3.4.3. Canonicalized bodies should always use CRLF, regardless of mailer setting.
string | $body | Message Body |
string |
PHPMailer\PHPMailer\DKIM_HeaderC | ( | $signHeader | ) |
Generate a DKIM canonicalization header.
Uses the 'relaxed' algorithm from RFC6376 section 3.4.2. Canonicalized headers should always use CRLF, regardless of mailer setting.
string | $signHeader | Header |
string |
PHPMailer\PHPMailer\DKIM_QP | ( | $txt | ) |
Quoted-Printable-encode a DKIM header.
string | $txt |
string |
PHPMailer\PHPMailer\DKIM_Sign | ( | $signHeader | ) |
Generate a DKIM signature.
string | $signHeader |
Exception |
string | The DKIM signature value |
|
protected |
Perform a callback.
bool | $isSent | |
array | $to | |
array | $cc | |
array | $bcc | |
string | $subject | |
string | $body | |
string | $from | |
array | $extra |
|
protected |
Encode a file attachment in requested format.
Returns an empty string on failure.
string | $path | The full path to the file |
string | $encoding | The encoding to use; one of 'base64', '7bit', '8bit', 'binary', 'quoted-printable' |
string |
PHPMailer\PHPMailer\encodeHeader | ( | $str, | |
$position = 'text' ) |
Encode a header value (not including its label) optimally.
Picks shortest of Q, B, or none. Result includes folding if needed. See RFC822 definitions for phrase, comment and text positions.
string | $str | The header value to encode |
string | $position | What context the string will be used in |
string |
PHPMailer\PHPMailer\encodeQ | ( | $str, | |
$position = 'text' ) |
Encode a string using Q encoding.
string | $str | the text to encode |
string | $position | Where the text is going to be used, see the RFC for what that means |
string |
PHPMailer\PHPMailer\encodeQP | ( | $string | ) |
Encode a string in quoted-printable format.
According to RFC2045 section 6.7.
string | $string | The text to encode |
string |
PHPMailer\PHPMailer\encodeString | ( | $str, | |
$encoding = self::ENCODING_BASE64 ) |
Encode a string in requested format.
Returns an empty string on failure.
string | $str | The text to encode |
string | $encoding | The encoding to use; one of 'base64', '7bit', '8bit', 'binary', 'quoted-printable' |
Exception |
string |
|
protected |
Return the end of a message boundary.
string | $boundary |
string |
|
static |
Map a file name to a MIME type.
Defaults to 'application/octet-stream', i.e.. arbitrary binary data.
string | $filename | A file name or full path, does not need to exist as a file |
string |
|
protected |
Create a unique ID to use for boundaries.
string |
PHPMailer\PHPMailer\getAllRecipientAddresses | ( | ) |
Allows for public read access to 'all_recipients' property.
Before the send() call, queued addresses (i.e. with IDN) are not yet included.
array |
PHPMailer\PHPMailer\getAttachments | ( | ) |
Return the array of attachments.
array |
PHPMailer\PHPMailer\getBccAddresses | ( | ) |
Allows for public read access to 'bcc' property.
Before the send() call, queued addresses (i.e. with IDN) are not yet included.
array |
PHPMailer\PHPMailer\getBoundaries | ( | ) |
Get the boundaries that this message will use.
array |
|
protected |
Return the start of a message boundary.
string | $boundary | |
string | $charSet | |
string | $contentType | |
string | $encoding |
string |
PHPMailer\PHPMailer\getCcAddresses | ( | ) |
Allows for public read access to 'cc' property.
Before the send() call, queued addresses (i.e. with IDN) are not yet included.
array |
PHPMailer\PHPMailer\getCustomHeaders | ( | ) |
Returns all custom headers.
array |
|
static |
Return the current line break format string.
string |
PHPMailer\PHPMailer\getMailMIME | ( | ) |
Get the message MIME type headers.
string |
PHPMailer\PHPMailer\getOAuth | ( | ) |
Get the OAuthTokenProvider instance.
OAuthTokenProvider |
PHPMailer\PHPMailer\getReplyToAddresses | ( | ) |
Allows for public read access to 'ReplyTo' property.
Before the send() call, queued addresses (i.e. with IDN) are not yet included.
array |
PHPMailer\PHPMailer\getSentMIMEMessage | ( | ) |
Returns the whole MIME message.
Includes complete headers and body. Only valid post preSend().
string |
PHPMailer\PHPMailer\getToAddresses | ( | ) |
Allows for public read access to 'to' property.
Before the send() call, queued addresses (i.e. with IDN) are not yet included.
array |
PHPMailer\PHPMailer\getTranslations | ( | ) |
Get the array of strings for the current language.
array |
PHPMailer\PHPMailer\has8bitChars | ( | $text | ) |
Does a string contain any 8-bit chars (in any charset)?
string | $text |
bool |
|
static |
Detect if a string contains a line longer than the maximum line length allowed by RFC 2822 section 2.1.1.
string | $str |
bool |
PHPMailer\PHPMailer\hasMultiBytes | ( | $str | ) |
Check if a string contains multi-byte characters.
string | $str | multi-byte text to wrap encode |
bool |
PHPMailer\PHPMailer\headerLine | ( | $name, | |
$value ) |
Format a header line.
string | $name | |
string | int | $value |
string |
PHPMailer\PHPMailer\html2text | ( | $html, | |
$advanced = false ) |
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 removed for license reasons in #232. Example usage:
string | $html | The HTML text to convert |
bool | callable | $advanced | Any boolean value to use the internal converter, or provide your own callable for custom conversion. Never pass user-supplied data into this parameter |
string |
PHPMailer\PHPMailer\inlineImageExists | ( | ) |
Check if an inline attachment is present.
bool |
PHPMailer\PHPMailer\isError | ( | ) |
Check if an error occurred.
bool | True if an error did occur |
|
static |
Validate whether a string contains a valid value to use as a hostname or IP address.
IPv6 addresses must include [], e.g. [::1]
, not just ::1
.
string | $host | The host name or IP address to check |
bool |
|
protected |
Get an error message in the current language.
string | $key |
string |
|
static |
Multi-byte-safe pathinfo replacement.
Drop-in replacement for pathinfo(), but multibyte- and cross-platform-safe.
string | $path | A filename or path, does not need to exist as a file |
int | string | $options | Either a PATHINFO_* constant, or a string name to return only the specified piece |
string|array |
PHPMailer\PHPMailer\msgHTML | ( | $message, | |
$basedir = '', | |||
$advanced = false ) |
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. 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) Converts data-uri images into embedded attachments. If you don't want to apply these transformations to your HTML, just set Body and AltBody directly.
string | $message | HTML message string |
string | $basedir | Absolute path to a base directory to prepend to relative paths to images |
bool | callable | $advanced | Whether to use the internal HTML to text converter or your own custom converter |
string | The transformed message body |
Exception |
|
static |
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.
string | $text | |
string | $breaktype | What kind of line break to use; defaults to static\$LE |
string |
|
static |
If a string contains any "special" characters, double-quote the name, and escape any double quotes with a backslash.
string | $str |
string |
PHPMailer\PHPMailer\replaceCustomHeader | ( | $name, | |
$value = null ) |
Replace a custom header.
$name value can be overloaded to contain both header name and value (name:value).
string | $name | Custom header name |
string | null | $value | Header value |
bool | True if a header was replaced successfully |
Exception |
|
static |
Return an RFC 822 formatted date.
string |
PHPMailer\PHPMailer\secureHeader | ( | $str | ) |
Strip newlines to prevent header injection.
string | $str |
string |
|
protected |
Get the server hostname.
Returns 'localhost.localdomain' if unknown.
string |
PHPMailer\PHPMailer\set | ( | $name, | |
$value = '' ) |
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’, static\ENCRYPTION_STARTTLS); is the same as:
$mail->SMTPSecure = static\ENCRYPTION_STARTTLS;`.
string | $name | The property name to set |
mixed | $value | The value to set the property to |
bool |
|
protected |
Add an error message to the error container.
string | $msg |
|
staticprotected |
Set the line break format string, e.g.
"::r::n".
string | $le |
|
protected |
Set the message type.
PHPMailer only supports some preset message types, not arbitrary MIME structures.
PHPMailer\PHPMailer\setWordWrap | ( | ) |
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.
PHPMailer\PHPMailer\sign | ( | $cert_filename, | |
$key_filename, | |||
$key_pass, | |||
$extracerts_filename = '' ) |
Set the public and private key files and password for S/MIME signing.
string | $cert_filename | |
string | $key_filename | |
string | $key_pass | Password for private key |
string | $extracerts_filename | Optional path to chain certificate |
|
static |
Strip trailing line breaks from a string.
string | $text |
string | The text to remove breaks from |
|
static |
Remove trailing whitespace from a string.
string | $text |
string | The text to remove whitespace from |
PHPMailer\PHPMailer\textLine | ( | $value | ) |
Return a formatted mail line.
string | $value |
string |
PHPMailer\PHPMailer\utf8CharBoundary | ( | $encodedText, | |
$maxLength ) |
Find the last character boundary prior to $maxLength in a utf-8 quoted-printable encoded string.
Original written by Colin Brown.
string | $encodedText | utf-8 QP text |
int | $maxLength | Find the last character boundary prior to this length |
int |
|
protected |
Validate encodings.
string | $encoding |
bool |
PHPMailer\PHPMailer\wrapText | ( | $message, | |
$length, | |||
$qp_mode = false ) |
Word-wrap message.
For use with mailers that do not automatically perform wrapping and for quoted-printable encoded messages. Original written by philippe.
string | $message | The message to wrap |
int | $length | The line length to wrap to |
bool | $qp_mode | Whether to run in Quoted-Printable mode |
string |