Documentation

EMail
in package

AbstractYes

Email sending utility class.

Provides email sending functionality using CodeIgniter's email library with support for HTML/text emails, attachments, and CC/BCC recipients.

Table of Contents

Properties

$defaultConfig  : array{wordwrap: bool, mailtype: "text"|"html", charset: string, priority: int, crlf: string, newline: string}
Email default settings.

Methods

attach()  : string
Add a file attachment.
attachmentCid()  : string|false
Get the Content-ID for an inline attachment.
bcc()  : string
Set BCC recipient address.
from()  : string
Set the sender address.
initialize()  : string
Initialize the email library with custom settings.
message()  : string
Set the email body text.
messageFromTemplate()  : string
Set the email body from a Twig template.
messageFromXml()  : string
Set subject and body from an XML template.
send()  : bool
Send the email.
setMailType()  : string
Set the email content type.
subject()  : string
Set the email subject line.
to()  : string
Set the recipient address.
email()  : CI_Email
Get or create singleton CI_Email instance.
template()  : Template
Get Template instance.

Properties

$defaultConfig

Email default settings.

private static array{wordwrap: bool, mailtype: "text"|"html", charset: string, priority: int, crlf: string, newline: string} $defaultConfig = [ // 'useragent' => 'CodeIgniter', // 'protocol' => 'mail', // 'mailpath' => '/usr/sbin/sendmail', // 'smtp_host' => null, // 'smtp_user' => null, // 'smtp_pass' => null, // 'smtp_port' => 25, // 'smtp_timeout' => 5, // 'smtp_keepalive' => false, // 'smtp_crypto' => null, 'wordwrap' => false, // 'wrapchars' => 76, 'mailtype' => 'text', 'charset' => 'utf-8', // 'validate' => false, 'priority' => 1, 'crlf' => "\r\n", 'newline' => "\r\n", ]

Methods

attach()

Add a file attachment.

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

File path or buffered data.

$disposition : string = ''

Content-Disposition ("attachment" or "inline").

$newname : string|null = null

Custom filename in the email.

$mime : string = ''

MIME type (required for buffered data).

Return values
string

This class name for static method chaining.

attachmentCid()

Get the Content-ID for an inline attachment.

public static attachmentCid(string $filename) : string|false

Useful for embedding images in HTML emails.

Parameters
$filename : string

Existing attachment filename.

Return values
string|false

Content-ID string, or false if attachment not found.

bcc()

Set BCC recipient address.

public static bcc(string|array<string|int, string> $bcc[, string $limit = '' ]) : string
Parameters
$bcc : string|array<string|int, string>

BCC email address or array of addresses.

$limit : string = ''

BCC batch max size. Default is blank.

Return values
string

This class name for static method chaining.

from()

Set the sender address.

public static from(string $from[, string $fromName = '' ][, string|null $returnPath = null ]) : string
Parameters
$from : string

Sender's email address.

$fromName : string = ''

Display name for the sender.

$returnPath : string|null = null

Return-Path header value.

Return values
string

This class name for static method chaining.

initialize()

Initialize the email library with custom settings.

public static initialize([array<string|int, mixed> $config = array() ]) : string
Parameters
$config : array<string|int, mixed> = array()

Email configuration (merges with defaults).

Return values
string

This class name for static method chaining.

message()

Set the email body text.

public static message(string $body) : string
Parameters
$body : string

Email body content.

Return values
string

This class name for static method chaining.

messageFromTemplate()

Set the email body from a Twig template.

public static messageFromTemplate(string $templatePath[, array<string|int, mixed> $params = [] ]) : string
Parameters
$templatePath : string

Template path relative to application/views/.

$params : array<string|int, mixed> = []

Template variables for interpolation.

Return values
string

This class name for static method chaining.

messageFromXml()

Set subject and body from an XML template.

public static messageFromXml(string $xmlPath[, array<string|int, mixed> $params = [] ]) : string

The XML file should contain <subject> and <message> elements.

Parameters
$xmlPath : string

XML template path relative to application/views/.

$params : array<string|int, mixed> = []

Template variables for interpolation.

Return values
string

This class name for static method chaining.

send()

Send the email.

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

Clear recipients and message data after sending. Default is true.

Return values
bool

True on success.

setMailType()

Set the email content type.

public static setMailType(["text"|"html" $type = 'text' ]) : string
Parameters
$type : "text"|"html" = 'text'

Mail content type. Default is "text".

Return values
string

This class name for static method chaining.

subject()

Set the email subject line.

public static subject(string $subject) : string
Parameters
$subject : string

Subject text.

Return values
string

This class name for static method chaining.

to()

Set the recipient address.

public static to(string|array<string|int, string> $to) : string
Parameters
$to : string|array<string|int, string>

Recipient email address or array of addresses.

Return values
string

This class name for static method chaining.

email()

Get or create singleton CI_Email instance.

private static email() : CI_Email
Return values
CI_Email

Cached email library instance.

template()

Get Template instance.

private static template() : Template
Return values
Template

Template instance.


        
On this page

Search results