使用cackPHP发送smtp邮件
2010-04-09 17:23
711 查看
读者要求:1.熟悉php、2.熟悉cackphp。
cackephp框架中已有组件email.php,具体位置:cakephp/cake/libs/controller/components。现在先讲一下此组件基本的参数
发送邮件的关键代码如下:
其他地方调用此处是请使用$this->sendNewUserMail();如果要循环发送邮件再发送下封邮件时要使用$this->Email->reset()重置。
代码中文件的位置app/views/elements/email/html/simple_message.ctp
cackephp框架中已有组件email.php,具体位置:cakephp/cake/libs/controller/components。现在先讲一下此组件基本的参数
to | 收件人地址(string) |
cc | 抄送人数组 |
bcc | 密件副本收件人数组(blind carbon copy) |
replyTo | 回信地址(string) |
from | 发送人地址(string) |
subject | 邮件标题(string) |
template | 邮件模板(保存于本地的app/views/elements/email/html/ 和 app/views/elements/email/text/) |
layout | 邮件使用的布局(保存于本地的app/views/layouts/email/html/ 和app/views/layouts/email/text/) |
lineLength | 自动换行长度, 默认为70。(integer) |
sendAs | 邮件发送格式 text, html 或者 both |
attachments | 附件路径(绝对或相对地址) |
delivery | 邮件发送方式(mail, smtp [需要下面的 smtpOptions设置] 和 debug) |
smtpOptions | smtp参数设置(port, host, timeout, username, password, client) |
var $components = array('Email'); function sendNewUserMail() { $this->Email->to = '<592938903@qq.com>'; //$this->Email->bcc = array('<592938903@qq.com>'); $this->Email->subject = 'Welcome to our really cool thing'; $this->Email->replyTo = '<592938903@qq.com>'; $this->Email->from = '<exp@myemailserver.com>'; $this->Email->template = 'simple_message'; // note no '.ctp' //Send as 'html', 'text' or 'both' (default is 'text') $this->Email->sendAs = 'html'; // because we like to send pretty mail //Set view variables as normal $this->Email->smtpOptions = array( 'port'=>'25', 'timeout'=>'30', 'host' => 'mailserver', 'username'=>'username', 'password'=>'pwd', 'client' => 'mailserver' ); //Do not pass any args to send() $this->Email->delivery = 'smtp'; $this->Email->send(); $err= $this->Email->smtpError; echo $err;//此次可查看错误,正式发布时要注销掉 }
其他地方调用此处是请使用$this->sendNewUserMail();如果要循环发送邮件再发送下封邮件时要使用$this->Email->reset()重置。
代码中文件的位置app/views/elements/email/html/simple_message.ctp
相关文章推荐
- php使用pear_smtp发送邮件
- php使用smtp发送支持附件的邮件示例
- 在PHP中使用Pear 的NetMail发送smtp邮件
- 在php中使用SMTP通过密抄批量发送邮件续:修正
- Wordpress无法发送邮件,基于插件“Contact Form 7”,修改class-phpmailer.php使用SMTP解决。
- php使用pear_smtp发送邮件
- php使用smtp发送邮件报错Error: Cannot connenct to relay host smtp.163.com Error: ()解决方法
- php使用smtp发送邮件报错Cannot connenct to relay host
- PHP使用SMTP发送邮件
- PHP 使用 SMTP发送邮件 gmail met problem
- 调试php没法使用smtp发送邮件的问题
- 使用PHP通过SMTP发送邮件新手指南
- php使用smtp服务发送邮件 第一
- PHP使用SMTP邮件服务器发送邮件示例
- php发送邮件二种方法 php使用smtp发送邮件
- php使用smtp发送支持附件的邮件示例
- 在PHP中使用Pear 的NetMail发送smtp邮件
- PHP使用socket方式发送邮件,无需SMTP服务
- 使用Pear和php socket来实现通过smtp验证发送邮件
- 在PHP中使用Pear 的NetMail发送smtp邮件