CodeIgniter v4.5 API

MockEmail extends Email
in package

CodeIgniter Email Class

Permits email to be sent using Mail, Sendmail, or SMTP.

Table of Contents

Properties

$altMessage  : string
Alternative message (for HTML messages only)
$archive  : array<string|int, mixed>|null
Properties from the last successful send.
$BCCBatchMode  : bool
Whether to send messages to BCC recipients in batches.
$BCCBatchSize  : int|string
BCC Batch max number size.
$charset  : string
Character set (default: utf-8)
$CRLF  : string
CRLF character sequence
$DSN  : bool
Whether to use Delivery Status Notification.
$fromEmail  : string
$fromName  : string
$mailPath  : string
Path to the Sendmail binary.
$mailType  : string
Message format.
$newline  : string
Newline character sequence.
$priority  : int
X-Priority header value.
$protocol  : string
Which method to use for sending e-mails.
$returnValue  : bool
Value to return from mocked send().
$sendMultipart  : bool
Whether to send multipart alternatives.
$SMTPCrypto  : string
SMTP Encryption
$SMTPHost  : string
STMP Server Hostname
$SMTPKeepAlive  : bool
SMTP persistent connection
$SMTPPass  : string
SMTP Password
$SMTPPort  : int
SMTP Server port
$SMTPTimeout  : int
SMTP connection timeout in seconds
$SMTPUser  : string
SMTP Username
$userAgent  : string
Used as the User-Agent and X-Mailer headers' value.
$validate  : bool
Whether to validate e-mail addresses.
$wordWrap  : bool
Whether to apply word-wrapping to the message body.
$wrapChars  : int
Number of characters to wrap at.
$attachments  : array<string|int, mixed>
Attachment data
$baseCharsets  : array<int, string>
Character sets valid for 7-bit encoding, excluding language suffix.
$BCCArray  : array<string|int, mixed>
BCC Recipients
$bitDepths  : array<string|int, mixed>
Bit depths
$body  : string
Message body
$CCArray  : array<string|int, mixed>
CC Recipients
$debugMessage  : array<string|int, mixed>
Debug messages
$encoding  : string
Mail encoding
$finalBody  : string
Final message body to be sent.
$func_overload  : bool
mbstring.func_overload flag
$headers  : array<string|int, mixed>
Message headers
$headerStr  : string
Final headers to send
$priorities  : array<string|int, mixed>
$priority translations
$protocols  : array<string|int, mixed>
Valid $protocol values
$recipients  : array<string|int, mixed>|string
Recipients
$replyToFlag  : bool
Whether to send a Reply-To header
$SMTPAuth  : bool
Whether to perform SMTP authentication
$SMTPConnect  : resource|null
SMTP Connection socket placeholder
$subject  : string
Subject header
$tmpArchive  : array<string|int, mixed>
Properties to be added to the next archive.
$debugMessageRaw  : array<int, string>
Raw debug messages

Methods

__construct()  : mixed
__destruct()  : mixed
attach()  : bool|Email
batchBCCSend()  : void
Batch Bcc Send. Sends groups of BCCs in batches
cleanEmail()  : array<string|int, mixed>|string
clear()  : Email
initialize()  : Email
Initialize preferences
isValidEmail()  : bool
printDebugger()  : string
send()  : bool
setAltMessage()  : Email
setAttachmentCID()  : bool|string
Set and return attachment Content-ID Useful for attached inline pictures
setBCC()  : Email
setCC()  : Email
setCRLF()  : Email
setFrom()  : Email
setHeader()  : Email
setMailType()  : Email
setMessage()  : Email
setNewline()  : Email
setPriority()  : Email
setProtocol()  : Email
setReplyTo()  : Email
setSubject()  : Email
setTo()  : Email
setWordWrap()  : Email
validateEmail()  : bool
wordWrap()  : string
appendAttachments()  : void
attachmentsHaveMultipart()  : bool
buildHeaders()  : void
Build final headers
buildMessage()  : void
Build Final Body and attachments
getAltMessage()  : string
Build alternative plain text message
getContentType()  : string
getEncoding()  : string
getHostname()  : string
There are only two legal types of hostname - either a fully qualified domain name (eg: "mail.example.com") or an IP literal (eg: "[1.2.3.4]").
getMessageID()  : string
getMimeMessage()  : string
getProtocol()  : string
getSMTPData()  : string
mimeTypes()  : string
Mime Types
prepQEncoding()  : string
Performs "Q Encoding" on a string for use in email headers.
prepQuotedPrintable()  : string
Prepares string for Quoted-Printable Content-Transfer-Encoding Refer to RFC 2045 http://www.ietf.org/rfc/rfc2045.txt
removeNLCallback()  : string
Strip line-breaks via callback
sendCommand()  : bool
sendData()  : bool
sendWithMail()  : bool
Send using mail()
sendWithSendmail()  : bool
Send using Sendmail
sendWithSmtp()  : bool
Send using SMTP
setArchiveValues()  : array<string|int, mixed>
Determines the values that should be stored in $archive.
setDate()  : string
Set RFC 822 Date
setErrorMessage()  : void
SMTPAuthenticate()  : bool
SMTPConnect()  : bool|string
SMTPEnd()  : void
Shortcut to send RSET or QUIT depending on keep-alive
spoolEmail()  : bool
Spool mail to the mail server
stringToArray()  : array<string|int, mixed>
strlen()  : int
Byte-safe strlen()
substr()  : string
Byte-safe substr()
unwrapSpecials()  : void
Unwrap special elements
validateEmailForShell()  : bool
Validate email for shell
writeHeaders()  : void
Write Headers as a string
printDebuggerRaw()  : string
Returns raw debug messages

Properties

$altMessage

Alternative message (for HTML messages only)

public string $altMessage = ''

$archive

Properties from the last successful send.

public array<string|int, mixed>|null $archive

$BCCBatchMode

Whether to send messages to BCC recipients in batches.

public bool $BCCBatchMode = false

$charset

Character set (default: utf-8)

public string $charset = 'UTF-8'

$CRLF

CRLF character sequence

public string $CRLF = "\r\n"

RFC 2045 specifies that for 'quoted-printable' encoding, "\r\n" must be used. However, it appears that some servers (even on the receiving end) don't handle it properly and switching to "\n", while improper, is the only solution that seems to work for all environments.

Tags
see
http://www.ietf.org/rfc/rfc822.txt

$DSN

Whether to use Delivery Status Notification.

public bool $DSN = false

$fromEmail

public string $fromEmail

$fromName

public string $fromName

$mailPath

Path to the Sendmail binary.

public string $mailPath = '/usr/sbin/sendmail'

$mailType

Message format.

public string $mailType = 'text'

'text' or 'html'

$priority

X-Priority header value.

public int $priority = 3

1-5

$protocol

Which method to use for sending e-mails.

public string $protocol = 'mail'

'mail', 'sendmail' or 'smtp'

$returnValue

Value to return from mocked send().

public bool $returnValue = true

$sendMultipart

Whether to send multipart alternatives.

public bool $sendMultipart = true

Yahoo! doesn't seem to like these.

$SMTPCrypto

SMTP Encryption

public string $SMTPCrypto = ''

'', 'tls' or 'ssl'. 'tls' will issue a STARTTLS command to the server. 'ssl' means implicit SSL. Connection on port 465 should set this to ''.

$SMTPHost

STMP Server Hostname

public string $SMTPHost = ''

$SMTPKeepAlive

SMTP persistent connection

public bool $SMTPKeepAlive = false

$SMTPPass

SMTP Password

public string $SMTPPass = ''

$SMTPPort

SMTP Server port

public int $SMTPPort = 25

$SMTPTimeout

SMTP connection timeout in seconds

public int $SMTPTimeout = 5

$SMTPUser

SMTP Username

public string $SMTPUser = ''

$userAgent

Used as the User-Agent and X-Mailer headers' value.

public string $userAgent = 'CodeIgniter'

$validate

Whether to validate e-mail addresses.

public bool $validate = true

$wordWrap

Whether to apply word-wrapping to the message body.

public bool $wordWrap = true

$attachments

Attachment data

protected array<string|int, mixed> $attachments = []

$baseCharsets

Character sets valid for 7-bit encoding, excluding language suffix.

protected array<int, string> $baseCharsets = ['us-ascii', 'iso-2022-']

$BCCArray

BCC Recipients

protected array<string|int, mixed> $BCCArray = []

$bitDepths

Bit depths

protected array<string|int, mixed> $bitDepths = ['7bit', '8bit']

Valid mail encodings

Tags
see
Email::$encoding

$body

Message body

protected string $body = ''

$CCArray

CC Recipients

protected array<string|int, mixed> $CCArray = []

$encoding

Mail encoding

protected string $encoding = '8bit'

'8bit' or '7bit'

$finalBody

Final message body to be sent.

protected string $finalBody = ''

$func_overload

mbstring.func_overload flag

protected static bool $func_overload

$headers

Message headers

protected array<string|int, mixed> $headers = []

$headerStr

Final headers to send

protected string $headerStr = ''

$priorities

$priority translations

protected array<string|int, mixed> $priorities = [1 => '1 (Highest)', 2 => '2 (High)', 3 => '3 (Normal)', 4 => '4 (Low)', 5 => '5 (Lowest)']

Actual values to send with the X-Priority header

$protocols

Valid $protocol values

protected array<string|int, mixed> $protocols = ['mail', 'sendmail', 'smtp']
Tags
see
Email::$protocol

$recipients

Recipients

protected array<string|int, mixed>|string $recipients = []

$replyToFlag

Whether to send a Reply-To header

protected bool $replyToFlag = false

$SMTPAuth

Whether to perform SMTP authentication

protected bool $SMTPAuth = false

$SMTPConnect

SMTP Connection socket placeholder

protected resource|null $SMTPConnect

$subject

Subject header

protected string $subject = ''

$tmpArchive

Properties to be added to the next archive.

protected array<string|int, mixed> $tmpArchive = []

$debugMessageRaw

Raw debug messages

private array<int, string> $debugMessageRaw = []

Methods

__construct()

public __construct([array<string|int, mixed>|Email|null $config = null ]) : mixed
Parameters
$config : array<string|int, mixed>|Email|null = null

__destruct()

public __destruct() : mixed

attach()

public attach(string $file[, string $disposition = '' ][, string|null $newname = null ][, string $mime = '' ]) : bool|Email
Parameters
$file : string

Can be local path, URL or buffered content

$disposition : string = ''

'attachment'

$newname : string|null = null
$mime : string = ''
Return values
bool|Email

batchBCCSend()

Batch Bcc Send. Sends groups of BCCs in batches

public batchBCCSend() : void

cleanEmail()

public cleanEmail(array<string|int, mixed>|string $email) : array<string|int, mixed>|string
Parameters
$email : array<string|int, mixed>|string
Return values
array<string|int, mixed>|string

clear()

public clear([bool $clearAttachments = false ]) : Email
Parameters
$clearAttachments : bool = false
Return values
Email

initialize()

Initialize preferences

public initialize(array<string|int, mixed>|Email|null $config) : Email
Parameters
$config : array<string|int, mixed>|Email|null
Return values
Email

isValidEmail()

public isValidEmail(string $email) : bool
Parameters
$email : string
Return values
bool

printDebugger()

public printDebugger([array<string|int, mixed>|string $include = ['headers', 'subject', 'body'] ]) : string
Parameters
$include : array<string|int, mixed>|string = ['headers', 'subject', 'body']

List of raw data chunks to include in the output Valid options are: 'headers', 'subject', 'body'

Return values
string

send()

public send([mixed $autoClear = true ]) : bool
Parameters
$autoClear : mixed = true
Return values
bool

setAltMessage()

public setAltMessage(string $str) : Email
Parameters
$str : string
Return values
Email

setAttachmentCID()

Set and return attachment Content-ID Useful for attached inline pictures

public setAttachmentCID(string $filename) : bool|string
Parameters
$filename : string
Return values
bool|string

setBCC()

public setBCC(string $bcc[, string $limit = '' ]) : Email
Parameters
$bcc : string
$limit : string = ''
Return values
Email

setCC()

public setCC(string $cc) : Email
Parameters
$cc : string
Return values
Email

setCRLF()

public setCRLF([string $CRLF = " " ]) : Email
Parameters
$CRLF : string = " "
Return values
Email

setFrom()

public setFrom(string $from[, string $name = '' ][, string|null $returnPath = null ]) : Email
Parameters
$from : string
$name : string = ''
$returnPath : string|null = null

Return-Path

Return values
Email

setHeader()

public setHeader(string $header, string $value) : Email
Parameters
$header : string
$value : string
Return values
Email

setMailType()

public setMailType([string $type = 'text' ]) : Email
Parameters
$type : string = 'text'
Return values
Email

setMessage()

public setMessage(string $body) : Email
Parameters
$body : string
Return values
Email

setNewline()

public setNewline([string $newline = " " ]) : Email
Parameters
$newline : string = " "
Return values
Email

setPriority()

public setPriority([int $n = 3 ]) : Email
Parameters
$n : int = 3
Return values
Email

setProtocol()

public setProtocol([string $protocol = 'mail' ]) : Email
Parameters
$protocol : string = 'mail'
Return values
Email

setReplyTo()

public setReplyTo(string $replyto[, string $name = '' ]) : Email
Parameters
$replyto : string
$name : string = ''
Return values
Email

setSubject()

public setSubject(string $subject) : Email
Parameters
$subject : string
Return values
Email

setTo()

public setTo(array<string|int, mixed>|string $to) : Email
Parameters
$to : array<string|int, mixed>|string
Return values
Email

setWordWrap()

public setWordWrap([bool $wordWrap = true ]) : Email
Parameters
$wordWrap : bool = true
Return values
Email

validateEmail()

public validateEmail(array<string|int, mixed>|string $email) : bool
Parameters
$email : array<string|int, mixed>|string
Return values
bool

wordWrap()

public wordWrap(string $str[, int|null $charlim = null ]) : string
Parameters
$str : string
$charlim : int|null = null

Line-length limit

Return values
string

appendAttachments()

protected appendAttachments(string &$body, string $boundary[, string|null $multipart = null ]) : void
Parameters
$body : string

Message body to append to

$boundary : string

Multipart boundary

$multipart : string|null = null

When provided, only attachments of this type will be processed

attachmentsHaveMultipart()

protected attachmentsHaveMultipart(mixed $type) : bool
Parameters
$type : mixed
Return values
bool

buildHeaders()

Build final headers

protected buildHeaders() : void

buildMessage()

Build Final Body and attachments

protected buildMessage() : void

getAltMessage()

Build alternative plain text message

protected getAltMessage() : string

Provides the raw message for use in plain-text headers of HTML-formatted emails.

If the user hasn't specified his own alternative message it creates one by stripping the HTML

Return values
string

getContentType()

protected getContentType() : string
Return values
string

getEncoding()

protected getEncoding() : string
Return values
string

getMessageID()

protected getMessageID() : string
Return values
string

getMimeMessage()

protected getMimeMessage() : string
Return values
string

getProtocol()

protected getProtocol() : string
Return values
string

getSMTPData()

protected getSMTPData() : string
Return values
string

mimeTypes()

Mime Types

protected mimeTypes([string $ext = '' ]) : string
Parameters
$ext : string = ''
Return values
string

prepQEncoding()

Performs "Q Encoding" on a string for use in email headers.

protected prepQEncoding(string $str) : string

It's related but not identical to quoted-printable, so it has its own method.

Parameters
$str : string
Return values
string

prepQuotedPrintable()

Prepares string for Quoted-Printable Content-Transfer-Encoding Refer to RFC 2045 http://www.ietf.org/rfc/rfc2045.txt

protected prepQuotedPrintable(string $str) : string
Parameters
$str : string
Return values
string

removeNLCallback()

Strip line-breaks via callback

protected removeNLCallback(array<int, string> $matches) : string
Parameters
$matches : array<int, string>
Tags
used-by

unwrapSpecials()

Return values
string

sendCommand()

protected sendCommand(string $cmd[, string $data = '' ]) : bool
Parameters
$cmd : string
$data : string = ''
Return values
bool

sendData()

protected sendData(string $data) : bool
Parameters
$data : string
Return values
bool

sendWithMail()

Send using mail()

protected sendWithMail() : bool
Return values
bool

sendWithSendmail()

Send using Sendmail

protected sendWithSendmail() : bool
Return values
bool

sendWithSmtp()

Send using SMTP

protected sendWithSmtp() : bool
Return values
bool

setArchiveValues()

Determines the values that should be stored in $archive.

protected setArchiveValues() : array<string|int, mixed>
Return values
array<string|int, mixed>

The updated archive values

setDate()

Set RFC 822 Date

protected setDate() : string
Return values
string

setErrorMessage()

protected setErrorMessage(string $msg) : void
Parameters
$msg : string

SMTPAuthenticate()

protected SMTPAuthenticate() : bool
Return values
bool

SMTPConnect()

protected SMTPConnect() : bool|string
Return values
bool|string

SMTPEnd()

Shortcut to send RSET or QUIT depending on keep-alive

protected SMTPEnd() : void

spoolEmail()

Spool mail to the mail server

protected spoolEmail() : bool
Return values
bool

stringToArray()

protected stringToArray(array<string|int, mixed>|string $email) : array<string|int, mixed>
Parameters
$email : array<string|int, mixed>|string
Return values
array<string|int, mixed>

strlen()

Byte-safe strlen()

protected static strlen(string $str) : int
Parameters
$str : string
Return values
int

substr()

Byte-safe substr()

protected static substr(string $str, int $start[, int|null $length = null ]) : string
Parameters
$str : string
$start : int
$length : int|null = null
Return values
string

unwrapSpecials()

Unwrap special elements

protected unwrapSpecials() : void

validateEmailForShell()

Validate email for shell

protected validateEmailForShell(string &$email) : bool

Applies stricter, shell-safe validation to email addresses. Introduced to prevent RCE via sendmail's -f option.

Parameters
$email : string
Tags
see
https://github.com/codeigniter4/CodeIgniter/issues/4963
see
https://gist.github.com/Zenexer/40d02da5e07f151adeaeeaa11af9ab36
license

https://creativecommons.org/publicdomain/zero/1.0/ CC0 1.0, Public Domain

Credits for the base concept go to Paul Buonopane paul@namepros.com

Return values
bool

writeHeaders()

Write Headers as a string

protected writeHeaders() : void

printDebuggerRaw()

Returns raw debug messages

private printDebuggerRaw() : string
Return values
string

        
On this page

Search results