\CodeIgniter\EmailEmail

CodeIgniter Email Class

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

Summary

Methods
Properties
Constants
setLogger()
__construct()
initialize()
clear()
setFrom()
setReplyTo()
setTo()
setCC()
setBCC()
setSubject()
setMessage()
attach()
setAttachmentCID()
setHeader()
setAltMessage()
setMailType()
setWordWrap()
setProtocol()
setPriority()
setNewline()
setCRLF()
validateEmail()
isValidEmail()
cleanEmail()
wordWrap()
send()
batchBCCSend()
printDebugger()
__destruct()
$fromEmail
$fromName
$userAgent
$mailPath
$protocol
$SMTPHost
$SMTPUser
$SMTPPass
$SMTPPort
$SMTPTimeout
$SMTPKeepAlive
$SMTPCrypto
$wordWrap
$wrapChars
$mailType
$charset
$altMessage
$validate
$priority
$newline
$CRLF
$DSN
$sendMultipart
$BCCBatchMode
$BCCBatchSize
No constants found
stringToArray()
getMessageID()
getProtocol()
getEncoding()
getContentType()
setDate()
getMimeMessage()
getAltMessage()
buildHeaders()
writeHeaders()
buildMessage()
attachmentsHaveMultipart()
appendAttachments()
prepQuotedPrintable()
prepQEncoding()
unwrapSpecials()
removeNLCallback()
spoolEmail()
validateEmailForShell()
sendWithMail()
sendWithSendmail()
sendWithSmtp()
SMTPEnd()
SMTPConnect()
sendCommand()
SMTPAuthenticate()
sendData()
getSMTPData()
getHostname()
setErrorMessage()
mimeTypes()
strlen()
substr()
$logger
$subject
$body
$finalBody
$headerStr
$SMTPConnect
$encoding
$SMTPAuth
$replyToFlag
$debugMessage
$recipients
$CCArray
$BCCArray
$headers
$attachments
$protocols
$baseCharsets
$bitDepths
$priorities
$func_overload
N/A
No private methods found
No private properties found
N/A

Properties

$fromEmail

$fromEmail : string

Type

string

$fromName

$fromName : string

Type

string

$userAgent

$userAgent : string

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

Type

string

$mailPath

$mailPath : string

Path to the Sendmail binary.

Type

string

$protocol

$protocol : string

Which method to use for sending e-mails.

Type

string — 'mail', 'sendmail' or 'smtp'

$SMTPHost

$SMTPHost : string

STMP Server host

Type

string

$SMTPUser

$SMTPUser : string

SMTP Username

Type

string

$SMTPPass

$SMTPPass : string

SMTP Password

Type

string

$SMTPPort

$SMTPPort : integer

SMTP Server port

Type

integer

$SMTPTimeout

$SMTPTimeout : integer

SMTP connection timeout in seconds

Type

integer

$SMTPKeepAlive

$SMTPKeepAlive : boolean

SMTP persistent connection

Type

boolean

$SMTPCrypto

$SMTPCrypto : string

SMTP Encryption

Type

string — Empty, 'tls' or 'ssl'

$wordWrap

$wordWrap : boolean

Whether to apply word-wrapping to the message body.

Type

boolean

$wrapChars

$wrapChars : integer

Number of characters to wrap at.

Type

integer

$mailType

$mailType : string

Message format.

Type

string — 'text' or 'html'

$charset

$charset : string

Character set (default: utf-8)

Type

string

$altMessage

$altMessage : string

Alternative message (for HTML messages only)

Type

string

$validate

$validate : boolean

Whether to validate e-mail addresses.

Type

boolean

$priority

$priority : integer

X-Priority header value.

Type

integer — 1-5

$newline

$newline : string

Newline character sequence.

Use "\r\n" to comply with RFC 822.

Type

string — "\r\n" or "\n"

$CRLF

$CRLF : string

CRLF character sequence

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.

Type

string

$DSN

$DSN : boolean

Whether to use Delivery Status Notification.

Type

boolean

$sendMultipart

$sendMultipart : boolean

Whether to send multipart alternatives.

Yahoo! doesn't seem to like these.

Type

boolean

$BCCBatchMode

$BCCBatchMode : boolean

Whether to send messages to BCC recipients in batches.

Type

boolean

$BCCBatchSize

$BCCBatchSize : integer

BCC Batch max number size.

Type

integer

$logger

$logger : \PSR\Log\LoggerInterface

Logger instance to record error messages and awarnings.

Type

\PSR\Log\LoggerInterface

$subject

$subject : string

Subject header

Type

string

$body

$body : string

Message body

Type

string

$finalBody

$finalBody : string

Final message body to be sent.

Type

string

$headerStr

$headerStr : string

Final headers to send

Type

string

$SMTPConnect

$SMTPConnect : resource

SMTP Connection socket placeholder

Type

resource

$encoding

$encoding : string

Mail encoding

Type

string — '8bit' or '7bit'

$SMTPAuth

$SMTPAuth : boolean

Whether to perform SMTP authentication

Type

boolean

$replyToFlag

$replyToFlag : boolean

Whether to send a Reply-To header

Type

boolean

$debugMessage

$debugMessage : array

Debug messages

Type

array

$recipients

$recipients : array

Recipients

Type

array

$CCArray

$CCArray : array

CC Recipients

Type

array

$BCCArray

$BCCArray : array

BCC Recipients

Type

array

$headers

$headers : array

Message headers

Type

array

$attachments

$attachments : array

Attachment data

Type

array

$protocols

$protocols : array

Valid $protocol values

Type

array

$baseCharsets

$baseCharsets : array

Base charsets

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

Type

array

$bitDepths

$bitDepths : array

Bit depths

Valid mail encodings

Type

array

$priorities

$priorities : array

$priority translations

Actual values to send with the X-Priority header

Type

array

$func_overload

$func_overload : boolean

mbstring.func_overload flag

Type

boolean

Methods

__construct()

__construct(array|null  $config = null) 

Constructor - Sets Email Preferences

The constructor can be passed an array of config values

Parameters

array|null $config

clear()

clear(boolean  $clearAttachments = false) : \CodeIgniter\Email\Email

Initialize the Email Data

Parameters

boolean $clearAttachments

Returns

\CodeIgniter\Email\Email

setFrom()

setFrom(string  $from, string  $name = '', string|null  $returnPath = null) : \CodeIgniter\Email\Email

Set FROM

Parameters

string $from
string $name
string|null $returnPath

Return-Path

Returns

\CodeIgniter\Email\Email

setReplyTo()

setReplyTo(string  $replyto, string  $name = '') : \CodeIgniter\Email\Email

Set Reply-to

Parameters

string $replyto
string $name

Returns

\CodeIgniter\Email\Email

setTo()

setTo(string  $to) : \CodeIgniter\Email\Email

Set Recipients

Parameters

string $to

Returns

\CodeIgniter\Email\Email

setBCC()

setBCC(string  $bcc, string  $limit = '') : \CodeIgniter\Email\Email

Set BCC

Parameters

string $bcc
string $limit

Returns

\CodeIgniter\Email\Email

setSubject()

setSubject(string  $subject) : \CodeIgniter\Email\Email

Set Email Subject

Parameters

string $subject

Returns

\CodeIgniter\Email\Email

setMessage()

setMessage(string  $body) : \CodeIgniter\Email\Email

Set Body

Parameters

string $body

Returns

\CodeIgniter\Email\Email

attach()

attach(string  $file, string  $disposition = '', string|null  $newname = null, string  $mime = '') : \CodeIgniter\Email\Email

Assign file attachments

Parameters

string $file

Can be local path, URL or buffered content

string $disposition

'attachment'

string|null $newname
string $mime

Returns

\CodeIgniter\Email\Email

setAttachmentCID()

setAttachmentCID(string  $filename) : string

Set and return attachment Content-ID

Useful for attached inline pictures

Parameters

string $filename

Returns

string

setHeader()

setHeader(string  $header, string  $value) : \CodeIgniter\Email\Email

Add a Header Item

Parameters

string $header
string $value

Returns

\CodeIgniter\Email\Email

setAltMessage()

setAltMessage(string  $str) : \CodeIgniter\Email\Email

Set Multipart Value

Parameters

string $str

Returns

\CodeIgniter\Email\Email

setMailType()

setMailType(string  $type = 'text') : \CodeIgniter\Email\Email

Set Mailtype

Parameters

string $type

Returns

\CodeIgniter\Email\Email

setWordWrap()

setWordWrap(boolean  $wordWrap = true) : \CodeIgniter\Email\Email

Set Wordwrap

Parameters

boolean $wordWrap

Returns

\CodeIgniter\Email\Email

setProtocol()

setProtocol(string  $protocol = 'mail') : \CodeIgniter\Email\Email

Set Protocol

Parameters

string $protocol

Returns

\CodeIgniter\Email\Email

setPriority()

setPriority(integer  $n = 3) : \CodeIgniter\Email\Email

Set Priority

Parameters

integer $n

Returns

\CodeIgniter\Email\Email

setNewline()

setNewline(string  $newline = "\n") : \CodeIgniter\Email\Email

Set Newline Character

Parameters

string $newline

Returns

\CodeIgniter\Email\Email

setCRLF()

setCRLF(string  $CRLF = "\n") : \CodeIgniter\Email\Email

Set CRLF

Parameters

string $CRLF

Returns

\CodeIgniter\Email\Email

validateEmail()

validateEmail(string  $email) : boolean

Validate Email Address

Parameters

string $email

Returns

boolean

isValidEmail()

isValidEmail(string  $email) : boolean

Email Validation

Parameters

string $email

Returns

boolean

cleanEmail()

cleanEmail(string  $email) : string

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

Parameters

string $email

Returns

string

wordWrap()

wordWrap(string  $str, integer|null  $charlim = null) : string

Word Wrap

Parameters

string $str
integer|null $charlim

Line-length limit

Returns

string

send()

send(boolean  $autoClear = true) : boolean

Send Email

Parameters

boolean $autoClear

Returns

boolean

batchBCCSend()

batchBCCSend() 

Batch Bcc Send. Sends groups of BCCs in batches

printDebugger()

printDebugger(array  $include = array('headers', 'subject', 'body')) : string

Get Debug Message

Parameters

array $include

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

Returns

string

__destruct()

__destruct() 

Destructor

stringToArray()

stringToArray(string  $email) : array

Convert a String to an Array

Parameters

string $email

Returns

array

getMessageID()

getMessageID() : string

Get the Message ID

Returns

string

getProtocol()

getProtocol() : string

Get Mail Protocol

Returns

string

getEncoding()

getEncoding() : string

Get Mail Encoding

Returns

string

getContentType()

getContentType() : string

Get content type (text/html/attachment)

Returns

string

setDate()

setDate() : string

Set RFC 822 Date

Returns

string

getMimeMessage()

getMimeMessage() : string

Mime message

Returns

string

getAltMessage()

getAltMessage() : string

Build alternative plain text message

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

Returns

string

buildHeaders()

buildHeaders() 

Build final headers

writeHeaders()

writeHeaders() 

Write Headers as a string

buildMessage()

buildMessage() 

Build Final Body and attachments

attachmentsHaveMultipart()

attachmentsHaveMultipart(  $type) 

Parameters

$type

appendAttachments()

appendAttachments(  $body, string  $boundary, string|null  $multipart = null) : string

Prepares attachment string

Parameters

$body
string $boundary

Multipart boundary

string|null $multipart

When provided, only attachments of this type will be processed

Returns

string

prepQuotedPrintable()

prepQuotedPrintable(string  $str) : string

Prep Quoted Printable

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

Parameters

string $str

Returns

string

prepQEncoding()

prepQEncoding(string  $str) : string

Prep Q Encoding

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

string $str

Returns

string

unwrapSpecials()

unwrapSpecials() 

Unwrap special elements

removeNLCallback()

removeNLCallback(string  $matches) : string

Strip line-breaks via callback

Parameters

string $matches

Returns

string

spoolEmail()

spoolEmail() : boolean

Spool mail to the mail server

Returns

boolean

validateEmailForShell()

validateEmailForShell(  $email) : boolean

Validate email for shell

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

Parameters

$email

Returns

boolean

sendWithMail()

sendWithMail() : boolean

Send using mail()

Returns

boolean

sendWithSendmail()

sendWithSendmail() : boolean

Send using Sendmail

Returns

boolean

sendWithSmtp()

sendWithSmtp() : boolean

Send using SMTP

Returns

boolean

SMTPEnd()

SMTPEnd() 

SMTP End

Shortcut to send RSET or QUIT depending on keep-alive

SMTPConnect()

SMTPConnect() : string

SMTP Connect

Returns

string

sendCommand()

sendCommand(string  $cmd, string  $data = '') : boolean

Send SMTP command

Parameters

string $cmd
string $data

Returns

boolean

SMTPAuthenticate()

SMTPAuthenticate() : boolean

SMTP Authenticate

Returns

boolean

sendData()

sendData(string  $data) : boolean

Send SMTP data

Parameters

string $data

Returns

boolean

getSMTPData()

getSMTPData() : string

Get SMTP data

Returns

string

getHostname()

getHostname() : string

Get Hostname

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]").

Returns

string

setErrorMessage()

setErrorMessage(string  $msg) 

Set Message

Parameters

string $msg

mimeTypes()

mimeTypes(string  $ext = '') : string

Mime Types

Parameters

string $ext

Returns

string

strlen()

strlen(string  $str) : integer

Byte-safe strlen()

Parameters

string $str

Returns

integer

substr()

substr(string  $str, integer  $start, integer|null  $length = null) : string

Byte-safe substr()

Parameters

string $str
integer $start
integer|null $length

Returns

string