Email类的使用问题
1 需不需设置php.ini?在winodws下和linux下设置的内容有什么差别?不同的PHP版本有什么差别?我看了php.ini里面和邮件有关的设置如下:; For Win32 only.
; http://php.net/smtp
SMTP = smtp.exmail.qq.com
; http://php.net/smtp-port
smtp_port = 465
; For Win32 only.
; http://php.net/sendmail-from
sendmail_from = whb@blb.com.cn
; For Unix only.You may supply arguments as well (default: "sendmail -t -i").
; http://php.net/sendmail-path
; Force the addition of the specified parameters to be passed as extra parameters
; to the sendmail binary. These parameters will always replace the value of
; the 5th parameter to mail(), even in safe mode.
;mail.force_extra_parameters =
; Add X-PHP-Originating-Script: that will include uid of the script followed by the filename
mail.add_x_header = On
sendmail_path="C:\phpStudy\tools\sendmail\sendmail.exe -t"
; The path to a log file that will log all mail() calls. Log entries include
; the full path of the script, line number, To address and headers.
;mail.log =
; Log mail to syslog (Event Log on NT, not valid in Windows 95).
;mail.log = syslog
这里面的设置和Email类里面的设置有一样的,例如smtp_port、sendmail_from、SMTP在Email类中也可以通过
$config['smtp_host'] = "smtp.exmail.qq.com";
$config['smtp_user']= "whb@blb.com.cn";
$config['smtp_port'] = 465;
设置。这两个设置内容都是一样的。是不是都需要设置。
另外我还看了gocart系统里面是怎么使用的。
结果如下:
$this->load->library('email');
$config['mailtype'] = 'html';
$this->email->initialize($config);
$this->email->from($this->config->item('email'));
$this->email->to($save['to_email']);
$this->email->subject($row['subject']);
$this->email->message($row['content']);
$this->email->send();
在它的config文件夹下面没有看到email.php这个配置文件。
我在控制器中发送邮件。代码使用的是文档里面的
public function mail()
{
$this->load->library('email');
$this->email->from('whb@blb.com.cn', '小溪-FM');
$this->email->to('angel836@126.com');
$this->email->subject('Email Test');
$this->email->message('Testing the email class.');
$this->email->send();
echo $this->email->print_debugger();
}
我使用126的邮箱发送成功了。
之前的疑问也解答了。
不需要设置php.ini文件。
我的设置如下:
public function mail()
{
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'smtp.126.com';
$config['smtp_user'] = 'angel836@126.com';
$config['smtp_pass'] = '********';
$config['smtp_port'] = '25';
$config['charset'] = 'utf-8';
$config['mailtype'] = 'text';
$config['smtp_timeout'] = '5';
$config['newline'] = "\r\n";
$this->load->library ('email', $config);
$this->email->from ('angel836@126.com', 'dolphin');
$this->email->to ('416509859@qq.com', 'xiaoxi');
$this->email->subject ('Test subject');
$this->email->message ('The content');
$this->email->send ();
// echo $this->email->print_debugger();
}
页:
[1]