用CI实现Email功能
修改配置文件:D:\wamp\www\tuts\application\config下的config.php文件如下:$config['base_url'] = "http://localhost/tuts/index.php/";$config['server_root'] = $_SERVER['DOCUMENT_ROOT'];
在网站根目录下建立如下目录:D:\wamp\www\tuts\attachments存放附件
浏览器中输入:localhost/tuts/index.php/email/
控制器中的代码如下:
class Email extends Controller
{
function __construct()
{
parent::Controller();
}
function index()
{
$config=Array(
'protocol' => 'smtp',
'smtp_host'=>"smtp.qq.com", // SMTP Server.Example: mail.earthlink.net
'smtp_user'=>"*******@qq.com", // SMTP Username
'smtp_pass'=>"*******", // SMTP Password
'smtp_port'=>"25" // SMTP Port,default
);
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->from('*****@qq.com', 'yangli');
$this->email->to('******@163.com');
$this->email->subject('This is an email test2222!');
$this->email->message('It is working. Great!ok!');
$path = $this->config->item('server_root');
$file = $path . '/tuts/attachments/yourInfo.txt';
$this->email->attach($file);
if($this->email->send())
{
echo 'Your email was sent, fool.';
}
else
{
show_error($this->email->print_debugger());
}
}
}
页:
[1]