CodeIgniter v4.7 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, 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  : " "|" "
CRLF character sequence
$DSN  : bool
Whether to use Delivery Status Notification.
$fromEmail  : string
$fromName  : string
$mailPath  : string
Path to the Sendmail binary.
$mailType  : "html"|"text"
Message format.
$newline  : " "|"n"
Newline character sequence.
$priority  : int<1, 5>
X-Priority header value.
$protocol  : "mail"|"sendmail"|"smtp"
Which method to use for sending e-mails.
$returnValue  : bool
Value to return from mocked send().
$sendMultipart  : bool
Whether to send multipart alternatives.
$SMTPCrypto  : ""|"ssl"|"tls"
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<int, array{name: array{0: string, 1: string|null}, disposition: string, type: string, content: string, multipart: "mixed"|"related", cid?: string}>
Attachment data
$baseCharsets  : array<int, string>
Character sets valid for 7-bit encoding, excluding language suffix.
$BCCArray  : array<int, string>
BCC Recipients
$bitDepths  : array<int, string>
Bit depths
$body  : string
Message body
$CCArray  : array<int, string>
CC Recipients
$debugMessage  : array<int, string>
Debug messages
$encoding  : "7bit"|"8bit"
Mail encoding
$finalBody  : string
Final message body to be sent.
$func_overload  : bool|null
mbstring.func_overload flag
$headers  : array<string, string>
Message headers
$headerStr  : string
Final headers to send
$priorities  : array<int, string>
$priority translations
$protocols  : array<int, string>
Valid $protocol values
$recipients  : array<int, string>
Recipients
$replyToFlag  : bool
Whether to send a Reply-To header
$SMTPAuth  : bool
Whether to perform SMTP authentication
$SMTPAuthMethod  : string
Which SMTP authentication method to use: login, plain
$SMTPConnect  : false|resource|null
SMTP Connection socket placeholder
$subject  : string
Subject header
$tmpArchive  : array<string, array<int, string>|string>
Properties to be added to the next archive.

Methods

__construct()  : mixed
__destruct()  : mixed
attach()  : bool|Email
batchBCCSend()  : void
Batch Bcc Send. Sends groups of BCCs in batches
cleanEmail()  : ($email is array ? list : string)
clear()  : $this
initialize()  : $this
Initialize preferences
isValidEmail()  : bool
printDebugger()  : string
send()  : bool
setAltMessage()  : $this
setAttachmentCID()  : bool|string
Set and return attachment Content-ID Useful for attached inline pictures
setBCC()  : $this
setCC()  : $this
setCRLF()  : $this
setFrom()  : $this
setHeader()  : $this
setMailType()  : $this
setMessage()  : $this
setNewline()  : $this
setPriority()  : $this
setProtocol()  : $this
setReplyTo()  : $this
setSubject()  : $this
setTo()  : $this
setWordWrap()  : $this
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
isSMTPConnected()  : bool
Checks if there is an active SMTP connection.
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, 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<int, string>
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

Properties

$altMessage

Alternative message (for HTML messages only)

public string $altMessage = ''

$archive

Properties from the last successful send.

public array<string, 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'

$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 "html"|"text" $mailType = 'text'

$priority

X-Priority header value.

public int<1, 5> $priority = 3

$protocol

Which method to use for sending e-mails.

public "mail"|"sendmail"|"smtp" $protocol = 'mail'

$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 ""|"ssl"|"tls" $SMTPCrypto = ''
  • tls - will issue a STARTTLS command to the server
  • ssl - means implicit SSL
  • '' - for connection on port 465

$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<int, array{name: array{0: string, 1: string|null}, disposition: string, type: string, content: string, multipart: "mixed"|"related", cid?: string}> $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<int, string> $BCCArray = []

$bitDepths

Bit depths

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

Valid mail encodings

Tags
see
Email::$encoding

$body

Message body

protected string $body = ''

$CCArray

CC Recipients

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

$encoding

Mail encoding

protected "7bit"|"8bit" $encoding = '8bit'

$finalBody

Final message body to be sent.

protected string $finalBody = ''

$func_overload

mbstring.func_overload flag

protected static bool|null $func_overload

$headers

Message headers

protected array<string, string> $headers = []

$headerStr

Final headers to send

protected string $headerStr = ''

$priorities

$priority translations

protected array<int, string> $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<int, string> $protocols = ['mail', 'sendmail', 'smtp']
Tags
see
Email::$protocol

$recipients

Recipients

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

$replyToFlag

Whether to send a Reply-To header

protected bool $replyToFlag = false

$SMTPAuth

Whether to perform SMTP authentication

protected bool $SMTPAuth = false

$SMTPAuthMethod

Which SMTP authentication method to use: login, plain

protected string $SMTPAuthMethod = 'login'

$SMTPConnect

SMTP Connection socket placeholder

protected false|resource|null $SMTPConnect

$subject

Subject header

protected string $subject = ''

$tmpArchive

Properties to be added to the next archive.

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

Methods

__construct()

public __construct([array<string, mixed>|Email|null $config = null ]) : mixed
Parameters
$config : array<string, 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<int, string>|string $email) : ($email is array ? list : string)
Parameters
$email : array<int, string>|string
Return values
($email is array ? list : string)

clear()

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

initialize()

Initialize preferences

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

isValidEmail()

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

printDebugger()

public printDebugger([array<int, string>|string $include = ['headers', 'subject', 'body'] ]) : string
Parameters
$include : array<int, string>|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) : $this
Parameters
$str : string
Return values
$this

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 = '' ]) : $this
Parameters
$bcc : string
$limit : string = ''
Return values
$this

setCC()

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

setCRLF()

public setCRLF([string $CRLF = "\n" ]) : $this
Parameters
$CRLF : string = "\n"
Return values
$this

setFrom()

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

setHeader()

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

setMailType()

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

setMessage()

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

setNewline()

public setNewline([string $newline = "\n" ]) : $this
Parameters
$newline : string = "\n"
Return values
$this

setPriority()

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

setProtocol()

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

setReplyTo()

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

setSubject()

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

setTo()

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

setWordWrap()

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

validateEmail()

public validateEmail(array<int, string>|string $email) : bool
Parameters
$email : array<int, string>|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(string $type) : bool
Parameters
$type : string
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

isSMTPConnected()

Checks if there is an active SMTP connection.

protected isSMTPConnected() : bool
Return values
bool —

True if SMTP connection is established and open, false otherwise

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, mixed>
Return values
array<string, 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<int, string>|string $email) : array<int, string>
Parameters
$email : array<int, string>|string
Return values
array<int, string>

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
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
On this page

Search results