用户
 找回密码
 入住 CI 中国社区
搜索
查看: 5888|回复: 5
收起左侧

kohana让我欢喜让我忧

[复制链接]
发表于 2009-3-4 07:59:38 | 显示全部楼层 |阅读模式
看了kohana101,不错,用过CI的上手也容易一些。
它的Query Builder和CI的AR在php5的环境中使用方法相当类似。
它的View layou比CI方便多了。
它的controller和Model文件名可以重名了。

按kohana101的流程我一直写到最后,都是没问题的。但是,在发送mail时,居然需要PEAR。。。。。。。
吐血一公升。。。
昨晚实作的,现在还在抓狂啊。。。
发表于 2009-3-4 10:06:15 | 显示全部楼层
貌似的确需要一个什么SwiftMailer
发表于 2009-3-4 10:32:45 | 显示全部楼层
本帖最后由 doutu 于 2009-4-1 00:44 编辑

Email 辅助函数Email 辅助函数实际是运行在 Swift email 类的基础上。如果你想使得辅助函数正常工作必需有 Swiftmailer 库放置在 vendor 文件夹下面,此目录的结构必须有:
vendor  +- swift  |    +- Swift  |        |  ...  |        |  ...  |    -- Swift.php  |    -- EasySwift.php
配置配置 swiftmailer 类的配置文件存放在 application/config/email.php,如果没有请从 system/config 复制一份(详细请看级联系统):
// 可用驱动:native,sendmail,smtp $config['driver'] = 'native';  // Driver 选项: $config['options'] = NULL;
驱动config['driver'] 设置 SwiftMailer 驱动。可用驱动:
    native
    sendmail
  • smtp

驱动选项$config['options'] 包含驱动指定参数。
  • smtp: hostname(主机名),port(端口),username(用户名),password(密码),encryption(加密)
// 标准 smtp 连接$config['options'] = array('hostname'=>'yourhostname', 'port'=>'25', 'username'=>'yourusername', 'password'=>'yourpassword', 'encryption' => 'tls'); // 安全 SMTP 连接
  • sendmail: 指定路径或留空让 Swift 自动寻找 sendmail 路径
$config['options'] = '/path/to/sendmail';
用法实例
发生基本 Email发送基本 HTML 格式的 Email,可以参考下面的代码:
PHP复制代码
 
       $to = 'to@example.com';  // 地址也可以使用数组形:array('to@example.com', 'Name')
       $from    = 'from@example.com';
       $subject = 'This is an example subject';
       $message = 'This is an <strong>example</strong> message';
       email::send($to, $from, $subject, $message, TRUE);
 
复制代码

高级使用如果你想使用高级方式你需要使用 Swift mailer 方法。下面的代码功能实现了如何添加附件和多接收人发送:
PHP复制代码
 
$from = 'from@example.com';
$subject = 'Backup: ' . [url=http://www.php.net/date]date[/url]("d/m/Y");
$message = 'This is the <b>backup</b> for ' . [url=http://www.php.net/date]date[/url]("d/m/Y");
// 使用 connect() 方法在 email 配置文件使用参数设置来创建连接
$swift = email::connect(); // 构建接收人清单
$recipients = new Swift_RecipientList;
$recipients->addTo('to1@example.com');
$recipients->addTo('to2@example.com'); // 创建 HTML 格式信息$message = new Swift_Message($subject, $message, TRUE); // 附件$swiftfile = new Swift_File('/backups/dump-' . date("d-m-Y") . '.tar.gz');
$attachment = new Swift_Message_Attachment($swiftfile);
$message->attach($attachment);
if ($swift->send($message, $recipients, $from)){
 // 成功
}else{
 // 失败
}
 // 断开连接
$swift->disconnect();
 
复制代码

方法
connect()'connect' 创建 SwiftMailer 接口来驱动和设置配置文件中的参数。

send()'send' 使用指定信息发送 e-mail,其参数:
    [string/array] 接收人 Email(和姓名),或者数组方式填写接收人,抄送,密送地址
    [string/array] 发送人 Email(和姓名)
    [string] 信息标题
    [string] 信息内容
    [boolean] 是否为 HTML 格式发送(默认为 false)
  • 返回 [integer] 发送 Email 的数量
 楼主| 发表于 2009-3-4 10:40:36 | 显示全部楼层
谢谢楼上诸位回复,回头下载Swiftmailer 后试试
发表于 2009-6-26 01:15:57 | 显示全部楼层
下载Kohana的时候好像有一个可选Email类库的 是不是这个呢?
发表于 2009-7-9 17:12:14 | 显示全部楼层
kohana的email helper 确实比较无语
建议:
自己写个helper吧 简单又实用,够用就行XD

本版积分规则