MMO\core\server ยท 1 symbol ยท generated 30 Sep 2026
Build and send a MIME email via PHP's mail() (which shells out to sendmail), with support for HTML/plain alternative bodies, attachments, inline (data-URI) images, and DKIM signing. Adapted from PHPMailer.
- Namespace
MMO\core\server- Uses traits
- tWithHeaders
Index
| MAX_LINE_LENGTH | ||
| attachments | ||
| body | ||
| bodyAlt | ||
| dkimDomain | DKIM signing domain name. | |
| DKIMHeaders static | ||
| dkimIdentity | DKIM Identity: Usually the email address used as the source of the email. | |
| dkimPassphrase | DKIM passphrase if your key is encrypted. | |
| dkimPrivateFile | DKIM private key file path. | |
| dkimSelector | DKIM selector. | |
| headers | ||
| ikeys | ||
| recipients | ||
| subject | ||
| uniqueid | identifiant for boundaries | |
| addAttachment($path, $name, $type, $disposition, $id) | Add an attachment from a file. | |
| addBCC($address, $name) | ||
| addCC($address, $name) | ||
| addConfirmReading($address, $name) | ||
| addHeader($name, $value) | Append a value to a header, keeping any value(s) already set (as opposed to setHeader, which replaces). | |
| addInlineAttachment($cid, $path, $name, $type) | Add an inline attachment from a file. | |
| addRecipient($kind, $address, $name) | ||
| addReplyTo($address, $name) | ||
| addTo($address, $name) | Add one To recipient (on top of any already set -- setTo to replace them all). | |
| clearAttachments() | Remove every attachment (regular and inline). | |
| debugName() | ||
| DKIMEncodeBody($body) | Generate a DKIM canonicalization body. | |
| DKIMEncodeHeaders($headers, $subject, $body) | ||
| DKIMEncodeRelaxedHeader($header) | Generate a DKIM canonicalization header. | |
| DKIMEncodeText($txt) | Quoted-Printable-encode a DKIM header. | |
| DKIMSign($header) | ||
| encodeHeader($text, $secure) | Encode text to be placed in the header. | |
| getBCC() | ||
| getCC() | ||
| getCharset() | ||
| getConfirmReading() | ||
| getContentExtension() | ||
| getContentType($single) | ||
| getFrom() | ||
| getHeader($name) | Retrieves a message header value by the given case-insensitive name. | |
| getHeaderLine($name) | Retrieves a comma-separated string of the values for a single header. | |
| getHeaders($boundaries) | Build the full header set for send: the manually-set headers (tWithHeaders) plus one line per recipient kind (except 'To', which send passes to mail() separately)โฆ | |
| getOrigin() | Get origin of the request by looking at 'Origin', then 'Referer', then 'Sender' in the request's headers. | |
| getPriority() | ||
| getReplyTo() | ||
| getTo() | ||
| getUserAgent() | ||
| hasAttachment() | ||
| hasBCC($address) | ||
| hasCC($address) | ||
| hasConfirmReading($address) | ||
| hasHeader($name) | Checks if a header exists by the given case-insensitive name. | |
| hasInlineAttachment() | ||
| hasRecipient($kind, $address) | ||
| hasReplyTo($address) | ||
| hasTo($address) | ||
| isHTML() | ||
| isIe() | ||
| isIphone() | ||
| isJSON() | ||
| isMac() | ||
| isMobile() | ||
| isMultipart() | ||
| isWindows() | ||
| replaceInlineImage($text) | Replace all images passed as datauri (<img src="data:....>) to inline attachment | |
| secureHeader($text) | Strip CR/LF from $text -- prevents header injection when embedding untrusted content (e.g. | |
| send() | Build the full MIME message (headers, multipart body, DKIM signature if $dkimIdentity is set) and send it via PHP's mail(). | |
| setBCC($addresses) | ||
| setBody($body) | Set the body and replace all uri images into inline attachment | |
| setCacheControl($cache, $pragma) | Set the Cache-Control header (and, optionally, the legacy Pragma header alongside it). | |
| setCC($addresses) | ||
| setConfirmReading($addresses) | ||
| setContentType($type, $charset) | Set the Content-Type header, appending a charset parameter (unless $charset is null/empty). | |
| setExpires($time) | Set the Expires header from a unix timestamp, formatted as an RFC 7231 HTTP-date. | |
| setFrom($address, $name) | Replaces the From address (there is only ever one). | |
| setHeader($name, $value) | Set header, replacing any previous value(s) for the same (case-insensitively matched) header name. | |
| setPriority($value) | Email priority. | |
| setRecipients($kind, $addresses) | Set recipients of a kind | |
| setReplyTo($addresses) | ||
| setTo($addresses) | Replace every To recipient. | |
| unsetHeader($name) | Remove a header entirely. | |
| __construct($to, $subject, $body, $from, $contentType, $charset) |
Constants1
MAX_LINE_LENGTH
Properties14
attachments
- Type
- array
body
- Type
- string
bodyAlt
dkimDomain
DKIM signing domain name.
- Type
- string
DKIMHeaders
static- Type
- array
dkimIdentity
DKIM Identity: Usually the email address used as the source of the email.
dkimPassphrase
DKIM passphrase if your key is encrypted.
dkimPrivateFile
DKIM private key file path.
dkimSelector
DKIM selector.
- Type
- string
headers
ikeys
recipients
- Type
- array
subject
- Type
- string
uniqueid
identifiant for boundaries
- Type
- string
Methods67
addAttachment($path, $name, $type, $disposition, $id)
Mail.php:470Add an attachment from a file.
| $path | string | Path to the attachment |
| $name = null | null | string | Overrides the attachment filename |
| $type = null | null | string | File MIME type (by default mapped from the $path filename's extension) |
| $disposition = 'attachment' | string | Disposition to use: inline or attachment |
| $id = null | null | string | the identifaint to use for inline attachment |
| returns | void |
addBCC($address, $name)
Mail.php:384addCC($address, $name)
Mail.php:363addConfirmReading($address, $name)
Mail.php:424addHeader($name, $value)
tWithHeaders.php:166Append a value to a header, keeping any value(s) already set (as opposed to setHeader, which replaces).
| $name | string | |
| $value | array | string | a plain string is appended as a single new value (NOT split on ',', unlike setHeader) |
| returns | self |
addInlineAttachment($cid, $path, $name, $type)
Mail.php:491Add an inline attachment from a file.
| $cid | string | Content ID of the attachment; Use this to reference the content when using an embedded image in HTML |
| $path | string | Path to the attachment |
| $name = null | null | string | Overrides the attachment filename |
| $type = null | null | string | File MIME type (by default mapped from the $path filename's extension) |
| returns | void |
addRecipient($kind, $address, $name)
Mail.php:276| $kind | string | e.g. 'To', 'Cc', 'Bcc', 'Reply-To', 'From'. @param string $address secureHeader'd before storing. |
| $address | string | |
| $name = null | null | string | |
| returns |
addReplyTo($address, $name)
Mail.php:404addTo($address, $name)
Mail.php:335Add one To recipient (on top of any already set -- setTo to replace them all).
clearAttachments()
Mail.php:443Remove every attachment (regular and inline).
| returns |
debugName()
Mail.php:170| returns | string | the class name. |
DKIMEncodeBody($body)
Mail.php:525Generate a DKIM canonicalization body.
DKIMEncodeHeaders($headers, $subject, $body)
Mail.php:570DKIMEncodeRelaxedHeader($header)
Mail.php:543Generate a DKIM canonicalization header.
DKIMEncodeText($txt)
Mail.php:503Quoted-Printable-encode a DKIM header.
DKIMSign($header)
Mail.php:562encodeHeader($text, $secure)
Mail.php:226Encode text to be placed in the header.
getBCC()
Mail.php:379| returns | array |
getCC()
Mail.php:358| returns | array |
getCharset()
tWithHeaders.php:55getConfirmReading()
Mail.php:419| returns | array |
getContentExtension()
tWithHeaders.php:63| returns | null | string | the file extension conventionally associated with the Content-Type header (e.g. 'html', 'json') |
getContentType($single)
tWithHeaders.php:47| $single = true | bool | if true, return only the media type (e.g. 'text/html'); if false, every parameter too |
| returns | array | string |
getFrom()
Mail.php:309getHeader($name)
tWithHeaders.php:254Retrieves a message header value by the given case-insensitive name.
| $name | string | Case-insensitive header field name. |
| returns | array | An array of string values as provided for the given header. If the header does not appear in the message, this method MUST return an empty array. |
getHeaderLine($name)
tWithHeaders.php:281Retrieves a comma-separated string of the values for a single header.
| $name | string | Case-insensitive header field name. |
| returns | string | A string of values as provided for the given header concatenated together using a comma. If the header does not appear in the message, this method MUST return an empty string. |
getHeaders($boundaries)
Mail.php:635Build the full header set for send: the manually-set headers (tWithHeaders) plus one line per recipient kind (except 'To', which send passes to mail() separately) and the right Content-Type for whatever MIME structure the message needs (isMultipart).
getOrigin()
tWithHeaders.php:35Get origin of the request by looking at 'Origin', then 'Referer', then 'Sender' in the request's headers.
| returns | string | '' if none of those headers are set |
getPriority()
Mail.php:199| returns | null | int | the current priority (setPriority), or null if unset. |
getReplyTo()
Mail.php:399| returns | array |
getTo()
Mail.php:327getUserAgent()
tWithHeaders.php:70hasAttachment()
Mail.php:453| returns | bool | whether any regular (non-inline) attachment is set (addAttachment). |
hasBCC($address)
Mail.php:394hasCC($address)
Mail.php:373hasConfirmReading($address)
Mail.php:434hasHeader($name)
tWithHeaders.php:231Checks if a header exists by the given case-insensitive name.
| $name | string | Case-insensitive header field name. |
| returns | bool | Returns true if any header names match the given header name using a case-insensitive string comparison. Returns false if no matching header name is found in the message. |
hasInlineAttachment()
Mail.php:448| returns | bool | whether any inline attachment is set (addInlineAttachment/setBody's data-URI extraction). |
hasRecipient($kind, $address)
Mail.php:303hasReplyTo($address)
Mail.php:414hasTo($address)
Mail.php:353isHTML()
tWithHeaders.php:119| returns | bool | true if getContentExtension is 'html' |
isIe()
tWithHeaders.php:84| returns | bool | true if the User-Agent looks like Internet Explorer |
isIphone()
tWithHeaders.php:77| returns | bool | true if the User-Agent looks like mobile Safari on iPhone |
isJSON()
tWithHeaders.php:126| returns | bool | true if getContentExtension is 'json' |
isMac()
tWithHeaders.php:98| returns | bool | true if the User-Agent mentions macOS |
isMobile()
tWithHeaders.php:105| returns | bool | true if the User-Agent looks like a mobile device/browser |
isMultipart()
Mail.php:458| returns | bool | whether the message will be sent as MIME multipart (attachments, inline images, or an alternative body). |
isWindows()
tWithHeaders.php:91| returns | bool | true if the User-Agent mentions Windows |
replaceInlineImage($text)
Mail.php:248Replace all images passed as datauri (<img src="data:....>) to inline attachment
secureHeader($text)
Mail.php:215Strip CR/LF from $text -- prevents header injection when embedding untrusted content (e.g. a recipient name) into a header line.
send()
Mail.php:685Build the full MIME message (headers, multipart body, DKIM signature if $dkimIdentity is set) and send it via PHP's mail().
| returns | ||
| throws | if no From/To address or body is set, mail() itself fails, or (via DKIMSign) DKIM signing fails. |
setBCC($addresses)
Mail.php:389setBody($body)
Mail.php:208Set the body and replace all uri images into inline attachment
setCacheControl($cache, $pragma)
tWithHeaders.php:305Set the Cache-Control header (and, optionally, the legacy Pragma header alongside it).
| $cache | cache method 'public', 'private', 'no-cache', 'no-store' | |
| $pragma = null | if given, also sets the Pragma header (e.g. 'no-cache', for HTTP/1.0 clients) | |
| returns | self |
setCC($addresses)
Mail.php:368setConfirmReading($addresses)
Mail.php:429setContentType($type, $charset)
tWithHeaders.php:293Set the Content-Type header, appending a charset parameter (unless $charset is null/empty).
| $type | string | the media type, e.g. 'text/html' or one of the framework's MIME_* constants |
| $charset = 'utf-8' | null | string | appended as ;charset=$charset; pass null/'' to omit it entirely |
| returns | self |
setExpires($time)
tWithHeaders.php:317Set the Expires header from a unix timestamp, formatted as an RFC 7231 HTTP-date.
| $time | null | int | a unix timestamp; 0 (or any past time) tells clients/caches the response is already stale |
| returns | self |
setFrom($address, $name)
Mail.php:317Replaces the From address (there is only ever one).
setHeader($name, $value)
tWithHeaders.php:143Set header, replacing any previous value(s) for the same (case-insensitively matched) header name.
| $name | string | |
| $value | array | string | if a string, it is split on ',' into the multiple values PSR-7 expects a header to hold (e.g. 'a,b' becomes ['a', 'b']) -- pass an array (even a single-element one, e.g. [$value]) if $value may itself legitimately contain a comma that must NOT be split (an HTTP-date value like 'Thu, 01 Jan ...' is the classic example -- see setExpires) |
| returns | self |
setPriority($value)
Mail.php:193Email priority.
setRecipients($kind, $addresses)
Mail.php:287Set recipients of a kind
setReplyTo($addresses)
Mail.php:409setTo($addresses)
Mail.php:345Replace every To recipient.
| $addresses | array | string | ['name' => 'address', ...] (or a plain list, name null), or a single "Name <address>, address2, ..."-style string (decodeRecipients). |
| returns |
unsetHeader($name)
tWithHeaders.php:179Remove a header entirely.