Email
in package
CodeIgniter Email Class
Permits email to be sent using Mail, Sendmail, or SMTP.
Tags
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 : " "|"n"
- 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.
- $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<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<int, string>
- Bit depths
- $body : string
- Message body
- $CCArray : array<string|int, mixed>
- CC Recipients
- $debugMessage : array<string|int, mixed>
- 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|int, mixed>
- Message headers
- $headerStr : string
- Final headers to send
- $priorities : array<int, string>
- $priority translations
- $protocols : array<int, string>
- 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() : $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
- 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<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
- 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
$BCCBatchSize
BCC Batch max number size.
public
int|string
$BCCBatchSize
= 200
Tags
$charset
Character set (default: utf-8)
public
string
$charset
= 'UTF-8'
$CRLF
CRLF character sequence
public
"
"|"n"
$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
$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'
$newline
Newline character sequence.
public
"
"|"n"
$newline
= "\r\n"
Use "\r\n" to comply with RFC 822.
Tags
$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'
$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 serverssl
- 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
$wrapChars
Number of characters to wrap at.
public
int
$wrapChars
= 76
Tags
$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<int, string>
$bitDepths
= ['7bit', '8bit']
Valid mail encodings
Tags
$body
Message body
protected
string
$body
= ''
$CCArray
CC Recipients
protected
array<string|int, mixed>
$CCArray
= []
$debugMessage
Debug messages
protected
array<string|int, mixed>
$debugMessage
= []
Tags
$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|int, mixed>
$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
$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|EmailbatchBCCSend()
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>|stringclear()
public
clear([bool $clearAttachments = false ]) : $this
Parameters
- $clearAttachments : bool = false
Return values
$thisinitialize()
Initialize preferences
public
initialize(array<string|int, mixed>|Email|null $config) : $this
Parameters
- $config : array<string|int, mixed>|Email|null
Return values
$thisisValidEmail()
public
isValidEmail(string $email) : bool
Parameters
- $email : string
Return values
boolprintDebugger()
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
stringsend()
public
send([bool $autoClear = true ]) : bool
Parameters
- $autoClear : bool = true
Return values
boolsetAltMessage()
public
setAltMessage(string $str) : $this
Parameters
- $str : string
Return values
$thissetAttachmentCID()
Set and return attachment Content-ID Useful for attached inline pictures
public
setAttachmentCID(string $filename) : bool|string
Parameters
- $filename : string
Return values
bool|stringsetBCC()
public
setBCC(string $bcc[, string $limit = '' ]) : $this
Parameters
- $bcc : string
- $limit : string = ''
Return values
$thissetCC()
public
setCC(string $cc) : $this
Parameters
- $cc : string
Return values
$thissetCRLF()
public
setCRLF([string $CRLF = "
" ]) : $this
Parameters
- $CRLF : string = " "
Return values
$thissetFrom()
public
setFrom(string $from[, string $name = '' ][, string|null $returnPath = null ]) : $this
Parameters
- $from : string
- $name : string = ''
- $returnPath : string|null = null
Return values
$thissetHeader()
public
setHeader(string $header, string $value) : $this
Parameters
- $header : string
- $value : string
Return values
$thissetMailType()
public
setMailType([string $type = 'text' ]) : $this
Parameters
- $type : string = 'text'
Return values
$thissetMessage()
public
setMessage(string $body) : $this
Parameters
- $body : string
Return values
$thissetNewline()
public
setNewline([string $newline = "
" ]) : $this
Parameters
- $newline : string = " "
Return values
$thissetPriority()
public
setPriority([int $n = 3 ]) : $this
Parameters
- $n : int = 3
Return values
$thissetProtocol()
public
setProtocol([string $protocol = 'mail' ]) : $this
Parameters
- $protocol : string = 'mail'
Return values
$thissetReplyTo()
public
setReplyTo(string $replyto[, string $name = '' ]) : $this
Parameters
- $replyto : string
- $name : string = ''
Return values
$thissetSubject()
public
setSubject(string $subject) : $this
Parameters
- $subject : string
Return values
$thissetTo()
public
setTo(array<string|int, mixed>|string $to) : $this
Parameters
- $to : array<string|int, mixed>|string
Return values
$thissetWordWrap()
public
setWordWrap([bool $wordWrap = true ]) : $this
Parameters
- $wordWrap : bool = true
Return values
$thisvalidateEmail()
public
validateEmail(array<string|int, mixed>|string $email) : bool
Parameters
- $email : array<string|int, mixed>|string
Return values
boolwordWrap()
public
wordWrap(string $str[, int|null $charlim = null ]) : string
Parameters
- $str : string
- $charlim : int|null = null
-
Line-length limit
Return values
stringappendAttachments()
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
boolbuildHeaders()
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
stringgetContentType()
protected
getContentType() : string
Return values
stringgetEncoding()
protected
getEncoding() : string
Return values
stringgetHostname()
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]").
protected
getHostname() : string
Tags
Return values
stringgetMessageID()
protected
getMessageID() : string
Return values
stringgetMimeMessage()
protected
getMimeMessage() : string
Return values
stringgetProtocol()
protected
getProtocol() : string
Return values
stringgetSMTPData()
protected
getSMTPData() : string
Return values
stringmimeTypes()
Mime Types
protected
mimeTypes([string $ext = '' ]) : string
Parameters
- $ext : string = ''
Return values
stringprepQEncoding()
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
stringprepQuotedPrintable()
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
stringremoveNLCallback()
Strip line-breaks via callback
protected
removeNLCallback(array<int, string> $matches) : string
Parameters
- $matches : array<int, string>
Tags
Return values
stringsendCommand()
protected
sendCommand(string $cmd[, string $data = '' ]) : bool
Parameters
- $cmd : string
- $data : string = ''
Return values
boolsendData()
protected
sendData(string $data) : bool
Parameters
- $data : string
Return values
boolsendWithMail()
Send using mail()
protected
sendWithMail() : bool
Return values
boolsendWithSendmail()
Send using Sendmail
protected
sendWithSendmail() : bool
Return values
boolsendWithSmtp()
Send using SMTP
protected
sendWithSmtp() : bool
Return values
boolsetArchiveValues()
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
stringsetErrorMessage()
protected
setErrorMessage(string $msg) : void
Parameters
- $msg : string
SMTPAuthenticate()
protected
SMTPAuthenticate() : bool
Return values
boolSMTPConnect()
protected
SMTPConnect() : bool|string
Return values
bool|stringSMTPEnd()
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
boolstringToArray()
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
intsubstr()
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
stringunwrapSpecials()
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
Return values
boolwriteHeaders()
Write Headers as a string
protected
writeHeaders() : void
printDebuggerRaw()
Returns raw debug messages
private
printDebuggerRaw() : string