Skip to content

CI_Email

Mathieu Nayrolles edited this page Jan 20, 2016 · 1 revision

CI_Email

CodeIgniter Email Class

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

  • Class name: CI_Email
  • Namespace:

Properties

$useragent

public string $useragent = 'CodeIgniter'

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

  • Visibility: public

$mailpath

public string $mailpath = '/usr/sbin/sendmail'

Path to the Sendmail binary.

  • Visibility: public

$protocol

public string $protocol = 'mail'

Which method to use for sending e-mails.

  • Visibility: public

$smtp_host

public string $smtp_host = ''

STMP Server host

  • Visibility: public

$smtp_user

public string $smtp_user = ''

SMTP Username

  • Visibility: public

$smtp_pass

public string $smtp_pass = ''

SMTP Password

  • Visibility: public

$smtp_port

public integer $smtp_port = 25

SMTP Server port

  • Visibility: public

$smtp_timeout

public integer $smtp_timeout = 5

SMTP connection timeout in seconds

  • Visibility: public

$smtp_keepalive

public boolean $smtp_keepalive = FALSE

SMTP persistent connection

  • Visibility: public

$smtp_crypto

public string $smtp_crypto = ''

SMTP Encryption

  • Visibility: public

$wordwrap

public boolean $wordwrap = TRUE

Whether to apply word-wrapping to the message body.

  • Visibility: public

$wrapchars

public integer $wrapchars = 76

Number of characters to wrap at.

  • Visibility: public

$mailtype

public string $mailtype = 'text'

Message format.

  • Visibility: public

$charset

public string $charset = 'utf-8'

Character set (default: utf-8)

  • Visibility: public

$multipart

public string $multipart = 'mixed'

Multipart message

  • Visibility: public

$alt_message

public string $alt_message = ''

Alternative message (for HTML messages only)

  • Visibility: public

$validate

public boolean $validate = FALSE

Whether to validate e-mail addresses.

  • Visibility: public

$priority

public integer $priority = 3

X-Priority header value.

  • Visibility: public

$newline

public string $newline = "\n"

Newline character sequence.

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

  • Visibility: public

$crlf

public string $crlf = "\n"

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.

  • Visibility: public

$dsn

public boolean $dsn = FALSE

Whether to use Delivery Status Notification.

  • Visibility: public

$send_multipart

public boolean $send_multipart = TRUE

Whether to send multipart alternatives.

Yahoo! doesn't seem to like these.

  • Visibility: public

$bcc_batch_mode

public boolean $bcc_batch_mode = FALSE

Whether to send messages to BCC recipients in batches.

  • Visibility: public

$bcc_batch_size

public integer $bcc_batch_size = 200

BCC Batch max number size.

  • Visibility: public

$_safe_mode

protected boolean $_safe_mode = FALSE

Whether PHP is running in safe mode. Initialized by the class constructor.

  • Visibility: protected

$_subject

protected string $_subject = ''

Subject header

  • Visibility: protected

$_body

protected string $_body = ''

Message body

  • Visibility: protected

$_finalbody

protected string $_finalbody = ''

Final message body to be sent.

  • Visibility: protected

$_alt_boundary

protected string $_alt_boundary = ''

multipart/alternative boundary

  • Visibility: protected

$_atc_boundary

protected string $_atc_boundary = ''

Attachment boundary

  • Visibility: protected

$_header_str

protected string $_header_str = ''

Final headers to send

  • Visibility: protected

$_smtp_connect

protected resource $_smtp_connect = ''

SMTP Connection socket placeholder

  • Visibility: protected

$_encoding

protected string $_encoding = '8bit'

Mail encoding

  • Visibility: protected

$_smtp_auth

protected boolean $_smtp_auth = FALSE

Whether to perform SMTP authentication

  • Visibility: protected

$_replyto_flag

protected boolean $_replyto_flag = FALSE

Whether to send a Reply-To header

  • Visibility: protected

$_debug_msg

protected string $_debug_msg = array()

Debug messages

  • Visibility: protected

$_recipients

protected array<mixed,string> $_recipients = array()

Recipients

  • Visibility: protected

$_cc_array

protected array<mixed,string> $_cc_array = array()

CC Recipients

  • Visibility: protected

$_bcc_array

protected array<mixed,string> $_bcc_array = array()

BCC Recipients

  • Visibility: protected

$_headers

protected array<mixed,string> $_headers = array()

Message headers

  • Visibility: protected

$_attachments

protected array $_attachments = array()

Attachment data

  • Visibility: protected

$_protocols

protected array<mixed,string> $_protocols = array('mail', 'sendmail', 'smtp')

Valid $protocol values

  • Visibility: protected

$_base_charsets

protected array<mixed,string> $_base_charsets = array('us-ascii', 'iso-2022-')

Base charsets

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

  • Visibility: protected

$_bit_depths

protected array<mixed,string> $_bit_depths = array('7bit', '8bit')

Bit depths

Valid mail encodings

  • Visibility: protected

$_priorities

protected array<mixed,string> $_priorities = array(1 => '1 (Highest)', 2 => '2 (High)', 3 => '3 (Normal)', 4 => '4 (Low)', 5 => '5 (Lowest)')

$priority translations

Actual values to send with the X-Priority header

  • Visibility: protected

Methods

__construct

void CI_Email::__construct(array $config)

Constructor - Sets Email Preferences

The constructor can be passed an array of config values

  • Visibility: public

Arguments

  • $config array - <p>= array()</p>

__destruct

void CI_Email::__destruct()

Destructor - Releases Resources

  • Visibility: public

initialize

\CI_Email CI_Email::initialize($config)

Initialize preferences

  • Visibility: public

Arguments

  • $config mixed

clear

\CI_Email CI_Email::clear($clear_attachments)

Initialize the Email Data

  • Visibility: public

Arguments

  • $clear_attachments mixed

from

\CI_Email CI_Email::from(string $from, string $name, string $return_path)

Set FROM

  • Visibility: public

Arguments

  • $from string
  • $name string
  • $return_path string - <p>= NULL Return-Path</p>

reply_to

\CI_Email CI_Email::reply_to($replyto, $name)

Set Reply-to

  • Visibility: public

Arguments

  • $replyto mixed
  • $name mixed

to

\CI_Email CI_Email::to($to)

Set Recipients

  • Visibility: public

Arguments

  • $to mixed

cc

\CI_Email CI_Email::cc($cc)

Set CC

  • Visibility: public

Arguments

  • $cc mixed

bcc

\CI_Email CI_Email::bcc($bcc, $limit)

Set BCC

  • Visibility: public

Arguments

  • $bcc mixed
  • $limit mixed

subject

\CI_Email CI_Email::subject($subject)

Set Email Subject

  • Visibility: public

Arguments

  • $subject mixed

message

\CI_Email CI_Email::message($body)

Set Body

  • Visibility: public

Arguments

  • $body mixed

attach

\CI_Email CI_Email::attach(string $file, string $disposition, string $newname, string $mime)

Assign file attachments

  • Visibility: public

Arguments

  • $file string - <p>Can be local path, URL or buffered content</p>
  • $disposition string - <p>= 'attachment'</p>
  • $newname string - <p>= NULL</p>
  • $mime string - <p>= ''</p>

attachment_cid

string CI_Email::attachment_cid(string $filename)

Set and return attachment Content-ID

Useful for attached inline pictures

  • Visibility: public

Arguments

  • $filename string

set_header

void CI_Email::set_header($header, $value)

Add a Header Item

  • Visibility: public

Arguments

  • $header mixed
  • $value mixed

_str_to_array

array CI_Email::_str_to_array($email)

Convert a String to an Array

  • Visibility: protected

Arguments

  • $email mixed

set_alt_message

\CI_Email CI_Email::set_alt_message($str)

Set Multipart Value

  • Visibility: public

Arguments

  • $str mixed

set_mailtype

\CI_Email CI_Email::set_mailtype($type)

Set Mailtype

  • Visibility: public

Arguments

  • $type mixed

set_wordwrap

\CI_Email CI_Email::set_wordwrap($wordwrap)

Set Wordwrap

  • Visibility: public

Arguments

  • $wordwrap mixed

set_protocol

\CI_Email CI_Email::set_protocol($protocol)

Set Protocol

  • Visibility: public

Arguments

  • $protocol mixed

set_priority

\CI_Email CI_Email::set_priority($n)

Set Priority

  • Visibility: public

Arguments

  • $n mixed

set_newline

\CI_Email CI_Email::set_newline($newline)

Set Newline Character

  • Visibility: public

Arguments

  • $newline mixed

set_crlf

\CI_Email CI_Email::set_crlf($crlf)

Set CRLF

  • Visibility: public

Arguments

  • $crlf mixed

_set_boundaries

void CI_Email::_set_boundaries()

Set Message Boundary

  • Visibility: protected

_get_message_id

string CI_Email::_get_message_id()

Get the Message ID

  • Visibility: protected

_get_protocol

mixed CI_Email::_get_protocol($return)

Get Mail Protocol

  • Visibility: protected

Arguments

  • $return mixed

_get_encoding

string CI_Email::_get_encoding($return)

Get Mail Encoding

  • Visibility: protected

Arguments

  • $return mixed

_get_content_type

string CI_Email::_get_content_type()

Get content type (text/html/attachment)

  • Visibility: protected

_set_date

string CI_Email::_set_date()

Set RFC 822 Date

  • Visibility: protected

_get_mime_message

string CI_Email::_get_mime_message()

Mime message

  • Visibility: protected

validate_email

boolean CI_Email::validate_email($email)

Validate Email Address

  • Visibility: public

Arguments

  • $email mixed

valid_email

boolean CI_Email::valid_email($email)

Email Validation

  • Visibility: public

Arguments

  • $email mixed

clean_email

string CI_Email::clean_email($email)

Clean Extended Email Address: Joe Smith [email protected]

  • Visibility: public

Arguments

  • $email mixed

_get_alt_message

string CI_Email::_get_alt_message()

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

  • Visibility: protected

word_wrap

string CI_Email::word_wrap($str, $charlim)

Word Wrap

  • Visibility: public

Arguments

  • $str mixed
  • $charlim mixed

_build_headers

string CI_Email::_build_headers()

Build final headers

  • Visibility: protected

_write_headers

void CI_Email::_write_headers()

Write Headers as a string

  • Visibility: protected

_build_message

boolean CI_Email::_build_message()

Build Final Body and attachments

  • Visibility: protected

_prep_quoted_printable

string CI_Email::_prep_quoted_printable($str)

Prep Quoted Printable

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

  • Visibility: protected

Arguments

  • $str mixed

_prep_q_encoding

string CI_Email::_prep_q_encoding($str)

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.

  • Visibility: protected

Arguments

  • $str mixed

send

boolean CI_Email::send(boolean $auto_clear)

Send Email

  • Visibility: public

Arguments

  • $auto_clear boolean - <p>= TRUE</p>

batch_bcc_send

void CI_Email::batch_bcc_send()

Batch Bcc Send. Sends groups of BCCs in batches

  • Visibility: public

_unwrap_specials

void CI_Email::_unwrap_specials()

Unwrap special elements

  • Visibility: protected

_remove_nl_callback

string CI_Email::_remove_nl_callback(string $matches)

Strip line-breaks via callback

  • Visibility: protected

Arguments

  • $matches string

_spool_email

boolean CI_Email::_spool_email()

Spool mail to the mail server

  • Visibility: protected

_send_with_mail

boolean CI_Email::_send_with_mail()

Send using mail()

  • Visibility: protected

_send_with_sendmail

boolean CI_Email::_send_with_sendmail()

Send using Sendmail

  • Visibility: protected

_send_with_smtp

boolean CI_Email::_send_with_smtp()

Send using SMTP

  • Visibility: protected

_smtp_connect

string CI_Email::_smtp_connect()

SMTP Connect

  • Visibility: protected

_send_command

string CI_Email::_send_command($cmd, $data)

Send SMTP command

  • Visibility: protected

Arguments

  • $cmd mixed
  • $data mixed

_smtp_authenticate

boolean CI_Email::_smtp_authenticate()

SMTP Authenticate

  • Visibility: protected

_send_data

boolean CI_Email::_send_data(string $data)

Send SMTP data

  • Visibility: protected

Arguments

  • $data string

_get_smtp_data

string CI_Email::_get_smtp_data()

Get SMTP data

  • Visibility: protected

_get_hostname

string CI_Email::_get_hostname()

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

  • Visibility: protected

print_debugger

string CI_Email::print_debugger(array $include)

Get Debug Message

  • Visibility: public

Arguments

  • $include array - <p>List of raw data chunks to include in the output Valid options are: 'headers', 'subject', 'body'</p>

_set_error_message

void CI_Email::_set_error_message(string $msg, string $val)

Set Message

  • Visibility: protected

Arguments

  • $msg string
  • $val string - <p>= ''</p>

_mime_types

string CI_Email::_mime_types($ext)

Mime Types

  • Visibility: protected

Arguments

  • $ext mixed
Clone this wiki locally