PHP Class CI_Email, TastyIgniter

Permits email to be sent using Mail, Sendmail, or SMTP.
Datei anzeigen Open project: tastyigniter/tastyigniter Class Usage Examples

Public Properties

Property Type Description
$alt_message string Alternative message (for HTML messages only)
$bcc_batch_mode boolean Whether to send messages to BCC recipients in batches.
$bcc_batch_size integer BCC Batch max number size.
$charset string Character set (default: utf-8)
$crlf string 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.
$dsn boolean Whether to use Delivery Status Notification.
$mailpath string Path to the Sendmail binary.
$mailtype Message format.
$multipart Multipart message
$newline Use "\r\n" to comply with RFC 822.
$priority X-Priority header value.
$protocol Which method to use for sending e-mails.
$send_multipart boolean Yahoo! doesn't seem to like these.
$smtp_crypto SMTP Encryption
$smtp_host string STMP Server host
$smtp_keepalive boolean SMTP persistent connection
$smtp_pass string SMTP Password
$smtp_port integer SMTP Server port
$smtp_timeout integer SMTP connection timeout in seconds
$smtp_user string SMTP Username
$useragent string Used as the User-Agent and X-Mailer headers' value.
$validate boolean Whether to validate e-mail addresses.
$wordwrap boolean Whether to apply word-wrapping to the message body.
$wrapchars integer Number of characters to wrap at.

Protected Properties

Property Type Description
$_alt_boundary string multipart/alternative boundary
$_atc_boundary string Attachment boundary
$_attachments array Attachment data
$_base_charsets string[] Character sets valid for 7-bit encoding, excluding language suffix.
$_bcc_array string[] BCC Recipients
$_bit_depths string[] Valid mail encodings
$_body string Message body
$_cc_array string[] CC Recipients
$_debug_msg string Debug messages
$_encoding Mail encoding
$_finalbody string Final message body to be sent.
$_header_str string Final headers to send
$_headers string[] Message headers
$_priorities string[] Actual values to send with the X-Priority header
$_protocols string[] Valid $protocol values
$_recipients string[] Recipients
$_replyto_flag boolean Whether to send a Reply-To header
$_safe_mode boolean Whether PHP is running in safe mode. Initialized by the class constructor.
$_smtp_auth boolean Whether to perform SMTP authentication
$_smtp_connect resource SMTP Connection socket placeholder
$_subject string Subject header

Public Methods

Method Description
__construct ( array $config = [] ) : void Constructor - Sets Email Preferences
__destruct ( ) : void Destructor - Releases Resources
attach ( string $file, string $disposition = '', string $newname = NULL, string $mime = '' ) : CI_Email Assign file attachments
attachment_cid ( string $filename ) : string Set and return attachment Content-ID
batch_bcc_send ( ) : void Batch Bcc Send. Sends groups of BCCs in batches
bcc ( $bcc, $limit = '' ) : CI_Email Set BCC
cc ( $cc ) : CI_Email Set CC
clean_email ( $email ) : string Clean Extended Email Address: Joe Smith
clear ( $clear_attachments = FALSE ) : CI_Email Initialize the Email Data
from ( string $from, string $name = '', string $return_path = NULL ) : CI_Email Set FROM
initialize ( $config = [] ) : CI_Email Initialize preferences
message ( $body ) : CI_Email Set Body
print_debugger ( array $include = ['headers', 'subject', 'body'] ) : string Get Debug Message
reply_to ( $replyto, $name = '' ) : CI_Email Set Reply-to
send ( boolean $auto_clear = TRUE ) : boolean Send Email
set_alt_message ( $str ) : CI_Email Set Multipart Value
set_crlf ( $crlf = " " ) : CI_Email Set CRLF
set_header ( $header, $value ) : CI_Email Add a Header Item
set_mailtype ( $type = 'text' ) : CI_Email Set Mailtype
set_newline ( $newline = " " ) : CI_Email Set Newline Character
set_priority ( $n = 3 ) : CI_Email Set Priority
set_protocol ( $protocol = 'mail' ) : CI_Email Set Protocol
set_wordwrap ( $wordwrap = TRUE ) : CI_Email Set Wordwrap
subject ( $subject ) : CI_Email Set Email Subject
to ( $to ) : CI_Email Set Recipients
valid_email ( $email ) : boolean Email Validation
validate_email ( $email ) : boolean Validate Email Address
word_wrap ( $str, $charlim = NULL ) : string Word Wrap

Protected Methods

Method Description
_build_headers ( ) : string Build final headers
_build_message ( ) : boolean Build Final Body and attachments
_get_alt_message ( ) : string Build alternative plain text message
_get_content_type ( ) : string Get content type (text/html/attachment)
_get_encoding ( $return = TRUE ) : string Get Mail Encoding
_get_hostname ( ) : string Get Hostname
_get_message_id ( ) : string Get the Message ID
_get_mime_message ( ) : string Mime message
_get_protocol ( $return = TRUE ) : mixed Get Mail Protocol
_get_smtp_data ( ) : string Get SMTP data
_mime_types ( $ext = '' ) : string Mime Types
_prep_q_encoding ( $str ) : string Prep Q Encoding
_prep_quoted_printable ( $str ) : string Prep Quoted Printable
_remove_nl_callback ( string $matches ) : string Strip line-breaks via callback
_send_command ( $cmd, $data = '' ) : string Send SMTP command
_send_data ( string $data ) : boolean Send SMTP data
_send_with_mail ( ) : boolean Send using mail()
_send_with_sendmail ( ) : boolean Send using Sendmail
_send_with_smtp ( ) : boolean Send using SMTP
_set_boundaries ( ) : void Set Message Boundary
_set_date ( ) : string Set RFC 822 Date
_set_error_message ( string $msg, string $val = '' ) : void Set Message
_smtp_authenticate ( ) : boolean SMTP Authenticate
_smtp_connect ( ) : string SMTP Connect
_spool_email ( ) : boolean Spool mail to the mail server
_str_to_array ( $email ) : array Convert a String to an Array
_unwrap_specials ( ) : void Unwrap special elements
_write_headers ( ) : void Write Headers as a string

Method Details

__construct() public method

The constructor can be passed an array of config values
public __construct ( array $config = [] ) : void
$config array = array()
return void

__destruct() public method

Destructor - Releases Resources
public __destruct ( ) : void
return void

_build_headers() protected method

Build final headers
protected _build_headers ( ) : string
return string

_build_message() protected method

Build Final Body and attachments
protected _build_message ( ) : boolean
return boolean

_get_alt_message() protected method

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
protected _get_alt_message ( ) : string
return string

_get_content_type() protected method

Get content type (text/html/attachment)
protected _get_content_type ( ) : string
return string

_get_encoding() protected method

Get Mail Encoding
protected _get_encoding ( $return = TRUE ) : string
return string

_get_hostname() protected method

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 _get_hostname ( ) : string
return string

_get_message_id() protected method

Get the Message ID
protected _get_message_id ( ) : string
return string

_get_mime_message() protected method

Mime message
protected _get_mime_message ( ) : string
return string

_get_protocol() protected method

Get Mail Protocol
protected _get_protocol ( $return = TRUE ) : mixed
return mixed

_get_smtp_data() protected method

Get SMTP data
protected _get_smtp_data ( ) : string
return string

_mime_types() protected method

Mime Types
protected _mime_types ( $ext = '' ) : string
return string

_prep_q_encoding() protected method

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.
protected _prep_q_encoding ( $str ) : string
return string

_prep_quoted_printable() protected method

Prepares string for Quoted-Printable Content-Transfer-Encoding Refer to RFC 2045 http://www.ietf.org/rfc/rfc2045.txt
protected _prep_quoted_printable ( $str ) : string
return string

_remove_nl_callback() protected method

Strip line-breaks via callback
protected _remove_nl_callback ( string $matches ) : string
$matches string
return string

_send_command() protected method

Send SMTP command
protected _send_command ( $cmd, $data = '' ) : string
return string

_send_data() protected method

Send SMTP data
protected _send_data ( string $data ) : boolean
$data string
return boolean

_send_with_mail() protected method

Send using mail()
protected _send_with_mail ( ) : boolean
return boolean

_send_with_sendmail() protected method

Send using Sendmail
protected _send_with_sendmail ( ) : boolean
return boolean

_send_with_smtp() protected method

Send using SMTP
protected _send_with_smtp ( ) : boolean
return boolean

_set_boundaries() protected method

Set Message Boundary
protected _set_boundaries ( ) : void
return void

_set_date() protected method

Set RFC 822 Date
protected _set_date ( ) : string
return string

_set_error_message() protected method

Set Message
protected _set_error_message ( string $msg, string $val = '' ) : void
$msg string
$val string = ''
return void

_smtp_authenticate() protected method

SMTP Authenticate
protected _smtp_authenticate ( ) : boolean
return boolean

_smtp_connect() protected method

SMTP Connect
protected _smtp_connect ( ) : string
return string

_spool_email() protected method

Spool mail to the mail server
protected _spool_email ( ) : boolean
return boolean

_str_to_array() protected method

Convert a String to an Array
protected _str_to_array ( $email ) : array
return array

_unwrap_specials() protected method

Unwrap special elements
protected _unwrap_specials ( ) : void
return void

_write_headers() protected method

Write Headers as a string
protected _write_headers ( ) : void
return void

attach() public method

Assign file attachments
public attach ( string $file, string $disposition = '', string $newname = NULL, string $mime = '' ) : CI_Email
$file string Can be local path, URL or buffered content
$disposition string = 'attachment'
$newname string = NULL
$mime string = ''
return CI_Email

attachment_cid() public method

Useful for attached inline pictures
public attachment_cid ( string $filename ) : string
$filename string
return string

batch_bcc_send() public method

Batch Bcc Send. Sends groups of BCCs in batches
public batch_bcc_send ( ) : void
return void

bcc() public method

Set BCC
public bcc ( $bcc, $limit = '' ) : CI_Email
return CI_Email

cc() public method

Set CC
public cc ( $cc ) : CI_Email
return CI_Email

clean_email() public method

Clean Extended Email Address: Joe Smith
public clean_email ( $email ) : string
return string

clear() public method

Initialize the Email Data
public clear ( $clear_attachments = FALSE ) : CI_Email
return CI_Email

from() public method

Set FROM
public from ( string $from, string $name = '', string $return_path = NULL ) : CI_Email
$from string
$name string
$return_path string = NULL Return-Path
return CI_Email

initialize() public method

Initialize preferences
public initialize ( $config = [] ) : CI_Email
return CI_Email

message() public method

Set Body
public message ( $body ) : CI_Email
return CI_Email

print_debugger() public method

Get Debug Message
public print_debugger ( array $include = ['headers', 'subject', 'body'] ) : string
$include array List of raw data chunks to include in the output Valid options are: 'headers', 'subject', 'body'
return string

reply_to() public method

Set Reply-to
public reply_to ( $replyto, $name = '' ) : CI_Email
return CI_Email

send() public method

Send Email
public send ( boolean $auto_clear = TRUE ) : boolean
$auto_clear boolean = TRUE
return boolean

set_alt_message() public method

Set Multipart Value
public set_alt_message ( $str ) : CI_Email
return CI_Email

set_crlf() public method

Set CRLF
public set_crlf ( $crlf = " " ) : CI_Email
return CI_Email

set_header() public method

Add a Header Item
public set_header ( $header, $value ) : CI_Email
return CI_Email

set_mailtype() public method

Set Mailtype
public set_mailtype ( $type = 'text' ) : CI_Email
return CI_Email

set_newline() public method

Set Newline Character
public set_newline ( $newline = " " ) : CI_Email
return CI_Email

set_priority() public method

Set Priority
public set_priority ( $n = 3 ) : CI_Email
return CI_Email

set_protocol() public method

Set Protocol
public set_protocol ( $protocol = 'mail' ) : CI_Email
return CI_Email

set_wordwrap() public method

Set Wordwrap
public set_wordwrap ( $wordwrap = TRUE ) : CI_Email
return CI_Email

subject() public method

Set Email Subject
public subject ( $subject ) : CI_Email
return CI_Email

to() public method

Set Recipients
public to ( $to ) : CI_Email
return CI_Email

valid_email() public method

Email Validation
public valid_email ( $email ) : boolean
return boolean

validate_email() public method

Validate Email Address
public validate_email ( $email ) : boolean
return boolean

word_wrap() public method

Word Wrap
public word_wrap ( $str, $charlim = NULL ) : string
return string

Property Details

$_alt_boundary protected_oe property

multipart/alternative boundary
protected string $_alt_boundary
return string

$_atc_boundary protected_oe property

Attachment boundary
protected string $_atc_boundary
return string

$_attachments protected_oe property

Attachment data
protected array $_attachments
return array

$_base_charsets protected_oe property

Character sets valid for 7-bit encoding, excluding language suffix.
protected string[] $_base_charsets
return string[]

$_bcc_array protected_oe property

BCC Recipients
protected string[] $_bcc_array
return string[]

$_bit_depths protected_oe property

Valid mail encodings
See also: CI_Email::$_encoding
protected string[] $_bit_depths
return string[]

$_body protected_oe property

Message body
protected string $_body
return string

$_cc_array protected_oe property

CC Recipients
protected string[] $_cc_array
return string[]

$_debug_msg protected_oe property

Debug messages
See also: CI_Email::print_debugger()
protected string $_debug_msg
return string

$_encoding protected_oe property

Mail encoding
protected $_encoding

$_finalbody protected_oe property

Final message body to be sent.
protected string $_finalbody
return string

$_header_str protected_oe property

Final headers to send
protected string $_header_str
return string

$_headers protected_oe property

Message headers
protected string[] $_headers
return string[]

$_priorities protected_oe property

Actual values to send with the X-Priority header
protected string[] $_priorities
return string[]

$_protocols protected_oe property

Valid $protocol values
See also: CI_Email::$protocol
protected string[] $_protocols
return string[]

$_recipients protected_oe property

Recipients
protected string[] $_recipients
return string[]

$_replyto_flag protected_oe property

Whether to send a Reply-To header
protected bool $_replyto_flag
return boolean

$_safe_mode protected_oe property

Whether PHP is running in safe mode. Initialized by the class constructor.
protected bool $_safe_mode
return boolean

$_smtp_auth protected_oe property

Whether to perform SMTP authentication
protected bool $_smtp_auth
return boolean

$_smtp_connect protected_oe property

SMTP Connection socket placeholder
protected resource $_smtp_connect
return resource

$_subject protected_oe property

Subject header
protected string $_subject
return string

$alt_message public_oe property

Alternative message (for HTML messages only)
public string $alt_message
return string

$bcc_batch_mode public_oe property

Whether to send messages to BCC recipients in batches.
public bool $bcc_batch_mode
return boolean

$bcc_batch_size public_oe property

BCC Batch max number size.
See also: CI_Email::$bcc_batch_mode
public int $bcc_batch_size
return integer

$charset public_oe property

Character set (default: utf-8)
public string $charset
return string

$crlf public_oe property

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.
public string $crlf
return string

$dsn public_oe property

Whether to use Delivery Status Notification.
public bool $dsn
return boolean

$mailpath public_oe property

Path to the Sendmail binary.
public string $mailpath
return string

$mailtype public_oe property

Message format.
public $mailtype

$multipart public_oe property

Multipart message
public $multipart

$newline public_oe property

Use "\r\n" to comply with RFC 822.
public $newline

$priority public_oe property

X-Priority header value.
public $priority

$protocol public_oe property

Which method to use for sending e-mails.
public $protocol

$send_multipart public_oe property

Yahoo! doesn't seem to like these.
public bool $send_multipart
return boolean

$smtp_crypto public_oe property

SMTP Encryption
public $smtp_crypto

$smtp_host public_oe property

STMP Server host
public string $smtp_host
return string

$smtp_keepalive public_oe property

SMTP persistent connection
public bool $smtp_keepalive
return boolean

$smtp_pass public_oe property

SMTP Password
public string $smtp_pass
return string

$smtp_port public_oe property

SMTP Server port
public int $smtp_port
return integer

$smtp_timeout public_oe property

SMTP connection timeout in seconds
public int $smtp_timeout
return integer

$smtp_user public_oe property

SMTP Username
public string $smtp_user
return string

$useragent public_oe property

Used as the User-Agent and X-Mailer headers' value.
public string $useragent
return string

$validate public_oe property

Whether to validate e-mail addresses.
public bool $validate
return boolean

$wordwrap public_oe property

Whether to apply word-wrapping to the message body.
public bool $wordwrap
return boolean

$wrapchars public_oe property

Number of characters to wrap at.
See also: CI_Email::$wordwrap
public int $wrapchars
return integer