Documentation

Email
in package

CodeIgniter Email Class

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

Table of Contents

$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.
$sendMultipart  : bool
Whether to send multipart alternatives.
$SMTPCrypto  : string
SMTP Encryption
$SMTPHost  : string
STMP Server host
$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<string|int, mixed>
Base charsets
$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.
__construct()  : mixed
Constructor - Sets Email Preferences
__destruct()  : mixed
Destructor
attach()  : Email|bool
Assign file attachments
batchBCCSend()  : mixed
Batch Bcc Send. Sends groups of BCCs in batches
cleanEmail()  : array<string|int, mixed>|string
Clean Extended Email Address: Joe Smith <joe@smith.com>
clear()  : Email
Initialize the Email Data
initialize()  : Email
Initialize preferences
isValidEmail()  : bool
Email Validation
printDebugger()  : string
Get Debug Message
send()  : bool
Send Email
setAltMessage()  : Email
Set Multipart Value
setAttachmentCID()  : string|bool
Set and return attachment Content-ID
setBCC()  : Email
Set BCC
setCC()  : Email
Set CC
setCRLF()  : Email
Set CRLF
setFrom()  : Email
Set FROM
setHeader()  : Email
Add a Header Item
setMailType()  : Email
Set Mailtype
setMessage()  : Email
Set Body
setNewline()  : Email
Set Newline Character
setPriority()  : Email
Set Priority
setProtocol()  : Email
Set Protocol
setReplyTo()  : Email
Set Reply-to
setSubject()  : Email
Set Email Subject
setTo()  : Email
Set Recipients
setWordWrap()  : Email
Set Wordwrap
validateEmail()  : bool
Validate Email Address
wordWrap()  : string
Word Wrap
appendAttachments()  : void
Prepares attachment string
attachmentsHaveMultipart()  : bool
buildHeaders()  : mixed
Build final headers
buildMessage()  : mixed
Build Final Body and attachments
getAltMessage()  : string
Build alternative plain text message
getContentType()  : string
Get content type (text/html/attachment)
getEncoding()  : string
Get Mail Encoding
getHostname()  : string
Get Hostname
getMessageID()  : string
Get the Message ID
getMimeMessage()  : string
Mime message
getProtocol()  : string
Get Mail Protocol
getSMTPData()  : string
Get SMTP data
mimeTypes()  : string
Mime Types
prepQEncoding()  : string
Prep Q Encoding
prepQuotedPrintable()  : string
Prep Quoted Printable
removeNLCallback()  : string
Strip line-breaks via callback
sendCommand()  : bool
Send SMTP command
sendData()  : bool
Send SMTP data
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()  : mixed
Set Message
SMTPAuthenticate()  : bool
SMTP Authenticate
SMTPConnect()  : string|bool
SMTP Connect
SMTPEnd()  : mixed
SMTP End
spoolEmail()  : bool
Spool mail to the mail server
stringToArray()  : array<string|int, mixed>
Convert a String to an Array
strlen()  : int
Byte-safe strlen()
substr()  : string
Byte-safe substr()
unwrapSpecials()  : mixed
Unwrap special elements
validateEmailForShell()  : bool
Validate email for shell
writeHeaders()  : mixed
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|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 = " "

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
link
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'

$sendMultipart

Whether to send multipart alternatives.

public bool $sendMultipart = true

Yahoo! doesn't seem to like these.

$SMTPCrypto

SMTP Encryption

public string $SMTPCrypto = ''

Empty, 'tls' or 'ssl'

$SMTPHost

STMP Server host

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

Base charsets

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

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

$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 = []

Methods

__construct()

Constructor - Sets Email Preferences

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

The constructor can be passed an array of config values

Parameters
$config : array<string|int, mixed>|null = null
Return values
mixed

__destruct()

Destructor

public __destruct() : mixed
Return values
mixed

attach()

Assign file attachments

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

Can be local path, URL or buffered content

$disposition : string = ''

'attachment'

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

batchBCCSend()

Batch Bcc Send. Sends groups of BCCs in batches

public batchBCCSend() : mixed
Return values
mixed

cleanEmail()

Clean Extended Email Address: Joe Smith <joe@smith.com>

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

clear()

Initialize the Email Data

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

initialize()

Initialize preferences

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

isValidEmail()

Email Validation

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

printDebugger()

Get Debug Message

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

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

Return values
string

send()

Send Email

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

setAltMessage()

Set Multipart Value

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

setAttachmentCID()

Set and return attachment Content-ID

public setAttachmentCID(string $filename) : string|bool

Useful for attached inline pictures

Parameters
$filename : string
Return values
string|bool

setBCC()

Set BCC

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

setCC()

Set CC

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

setCRLF()

Set CRLF

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

setFrom()

Set FROM

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()

Add a Header Item

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

setMailType()

Set Mailtype

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

setMessage()

Set Body

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

setNewline()

Set Newline Character

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

setPriority()

Set Priority

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

setProtocol()

Set Protocol

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

setReplyTo()

Set Reply-to

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

setSubject()

Set Email Subject

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

setTo()

Set Recipients

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

setWordWrap()

Set Wordwrap

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

validateEmail()

Validate Email Address

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

wordWrap()

Word Wrap

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

Line-length limit

Return values
string

appendAttachments()

Prepares attachment string

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

Return values
void

attachmentsHaveMultipart()

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

buildHeaders()

Build final headers

protected buildHeaders() : mixed
Return values
mixed

buildMessage()

Build Final Body and attachments

protected buildMessage() : mixed
Return values
mixed

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()

Get content type (text/html/attachment)

protected getContentType() : string
Return values
string

getEncoding()

Get Mail Encoding

protected getEncoding() : string
Return values
string

getMessageID()

Get the Message ID

protected getMessageID() : string
Return values
string

getMimeMessage()

Mime message

protected getMimeMessage() : string
Return values
string

getProtocol()

Get Mail Protocol

protected getProtocol() : string
Return values
string

getSMTPData()

Get SMTP data

protected getSMTPData() : string
Return values
string

mimeTypes()

Mime Types

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

prepQEncoding()

Prep Q Encoding

protected prepQEncoding(string $str) : string

Performs "Q Encoding" on a string for use in email headers. It's related but not identical to quoted-printable, so it has its own method.

Parameters
$str : string
Return values
string

prepQuotedPrintable()

Prep Quoted Printable

protected prepQuotedPrintable(string $str) : string

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

Parameters
$str : string
Return values
string

removeNLCallback()

Strip line-breaks via callback

protected removeNLCallback(string $matches) : string
Parameters
$matches : string
Return values
string

sendCommand()

Send SMTP command

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

sendData()

Send SMTP data

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()

Set Message

protected setErrorMessage(string $msg) : mixed
Parameters
$msg : string
Return values
mixed

SMTPAuthenticate()

SMTP Authenticate

protected SMTPAuthenticate() : bool
Return values
bool

SMTPConnect()

SMTP Connect

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

SMTPEnd()

SMTP End

protected SMTPEnd() : mixed

Shortcut to send RSET or QUIT depending on keep-alive

Return values
mixed

spoolEmail()

Spool mail to the mail server

protected spoolEmail() : bool
Return values
bool

stringToArray()

Convert a String to an Array

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

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() : mixed
Return values
mixed

Search results