语法 | Parameters | Returns | Return Type |
from($from[, $name = ''[, $return_path = NULL]]) |
$from (
string)-"发件人"电子邮件地址
$name (
string) − "发件人"显示名称
$return_path (
string) − 可选电子邮件地址,用于重定向未送达的电子邮箱邮寄到
|
CI_Email 实例(方法链) | CI_Email |
reply_to($replyto[, $name = '']) |
$replyto (
string)-回复的电子邮件地址
$name (
string)-回复电子邮件地址的显示名称
|
CI_Email 实例(方法链) | CI_Email |
to($to) |
$to (
mixed)-逗号分隔的字符串或电子邮件地址数组
|
CI_Email 实例(方法链) | CI_Email |
cc($cc) |
$cc (
mixed)-逗号分隔的字符串或电子邮件地址数组
|
CI_Email 实例(方法链) | CI_Email |
bcc($bcc[, $limit = '']) |
$bcc (
mixed)-逗号分隔的字符串或电子邮件地址数组
$limit (
int)-每批发送的最大电子邮件数量
|
CI_Email 实例(方法链) | CI_Email |
subject($subject) |
$subject (
string)-电子邮件主题行
|
CI_Email 实例(方法链) | CI_Email |
message($body) |
$body (
string) − 电子邮件正文
|
CI_Email 实例(方法链) | CI_Email |
set_alt_message($str) |
$str (
string)-替代电子邮件正文
|
CI_Email 实例(方法链) | CI_Email |
set_header($header, $value) |
$header (
string) − 标题名称
$value (
string)-标题值
|
CI_Email 实例(方法链) | CI_Email |
clear([$clear_attachments = FALSE]) |
$clear_attachments (
bool) – 是否清除附件
|
CI_Email 实例(方法链) | CI_Email |
send([$auto_clear = TRUE]) |
$auto_clear (
bool) − 是否自动清除消息数据
|
CI_Email 实例(方法链) | CI_Email |
attach($filename[, $disposition = ''[, $newname = NULL[, $mime = '']]]) |
$filename (
string) − 文件名
$disposition (
string)-附件的"处置"。无论此处使用的 MIME 规范如何,大多数电子邮件客户端都会做出自己的决定。 iana
$newname (
string)-在电子邮件中使用的自定义文件名
$mime (
string)-要使用的 MIME 类型(用于缓冲数据)
|
CI_Email 实例(方法链) | CI_Email |
attachment_cid($filename) |
$filename (
string) − 现有附件文件名
|
附件 Content-ID 或 FALSE(如果未找到) | 字符串 |
$this->load->library('email');
$this->email->from('your@example.com', 'Your Name'); $this->email->to('someone@example.com'); $this->email->subject('Email Test'); $this->email->message('Testing the email class.');
$this->email->send();
<?php class Email_controller extends CI_Controller { function __construct() { parent::__construct(); $this->load->library('session'); $this->load->helper('form'); } public function index() { $this->load->helper('form'); $this->load->view('email_form'); } public function send_mail() { $from_email = "your@example.com"; $to_email = $this->input->post('email'); //Load email library $this->load->library('email'); $this->email->from($from_email, 'Your Name'); $this->email->to($to_email); $this->email->subject('Email Test'); $this->email->message('Testing the email class.'); //Send mail if($this->email->send()) $this->session->set_flashdata("email_sent","Email sent successfully."); else $this->session->set_flashdata("email_sent","Error in sending Email."); $this->load->view('email_form'); } } ?>
<!DOCTYPE html> <html lang = "en"> <head> <meta charset = "utf-8"> <title>CodeIgniter Email Example</title> </head> <body> <?php echo $this->session->flashdata('email_sent'); echo form_open('/Email_controller/send_mail'); ?> <input type = "email" name = "email" required /> <input type = "submit" value = "SEND MAIL"> <?php echo form_close(); ?> </body> </html>
$route['email'] = 'Email_Controller';
http://yoursite.com/index.php/email