[CI]发送Email

1. 在config/目录下添加 email.php类
$config['protocol'] = 'smtp';
	$config['smtp_host'] = 'ssl://smtp.gmail.com';
	$config['charset'] = 'utf-8';
	$config['smtp_port'] = 465;
	$config['smtp_user'] = '[email protected]';
	$config['smtp_pass'] = '*************';
	$config['smtp_timeout'] = '5';
	$config['newline'] = "\r\n";
	$config['crlf'] = "\r\n";


2. 发email的方法:
public function sendMail(){
		
		$this->load->library('email');
		$this->email->set_newline('\r\n');
		
		$this->email->from('[email protected]', "yanglei");
		$this->email->to('[email protected]');
		$this->email->subject('just test.');
		$this->email->message('when you believe.');
		
		$path = $this->config->items('server_root'); // 注: 此处需在config.php中添加: $path = $this->config->items('server_root');
		$file = $path . '/ci/attachments/info.txt';
		
		if($this->email->send()){
			echo 'your email was sent, fool.';
		}else{
			show_error($this->email->print_debugger());
		}
	}

你可能感兴趣的:(PHP,email,CI,code igniter)