2012-12-03 52 views
1

我已经建立了梨,以前被困在:如何在YII中包含PEAR的邮件和SMTP功能?

require_once('Mail.php'); 

我设法通过固定在php.ini的路径来解决这个问题,但现在YII抱怨:

include(LOGIN.php) [<a href='function.include'>function.include</a>]: failed to open stream: No such file or directory 

我不不知道要安装哪个库来让PEAR拾取LOGIN.php,如果这是问题。也可能是YII不允许导入LOGIN.PHP,因为它可能有它自己的?尽管我在抓秸秆。有任何想法吗?

回答

1

YiiMail是availble的扩展带或不带SMTP发送邮件的想法,这是一个通过电子邮件发送扩展包SwiftMailer。该扩展还允许您从视图文件创建电子邮件。从here

在您的配置文件 下载这个,包括下面的代码在组件部分

'mail' => array(
       'class' => 'application.extensions.yii-mail.YiiMail', 
       'transportType'=>'smtp', 
       'transportOptions'=>array(
        'host'=>'smtp.googlemail.com', 
        'username'=>'[email protected]',// 
        'password'=>'passwd', 
        'port'=>'465', 
        'encryption'=>'ssl', 
       ), 
       'viewPath' => 'application.views.mail', 
       'logging' => true, 
       'dryRun' => false 
     ), 

并在控制器动作部分使用类似下面

$message = new YiiMailMessage; 
$message->view = 'registrationFollowup'; 

//userModel is passed to the view 
$message->setBody(array('userModel'=>$userModel), 'text/html'); 


$message->addTo($userModel->email); 
$message->addBcc('[email protected]'); 
$message->from = Yii::app()->params['adminEmail']; 
Yii::app()->mail->send($message); 

认为registrationFollowup驻留在邮件文件夹内部视图文件夹中,可以从配置文件中了解视图路径('viewPath' => 'application.views.mail'

3

这是因为Yii中的自动装弹机,它是设置到找到的Yii的类,它是从PEAR的STANDAR diferent,你需要做的,其注册PEAR的自动加载

可以在the guide

了解这个什么

您可以使用像这样的自动加载磁带机:

static function loadClass($className){ 
    include str_replace('_','/',$className).'.php'; 
    return class_exists($className, false) || interface_exists($className, false); 
    return false; 
} 

PEAR扩展应该已经在PHP的包括这条道路的工作

Zend Autoloader extension,获得如何实现这个

+0

是否可以在没有实际复制PEAR库的情况下添加PEAR?我问,因为它已经设置使用“梨安装”,所以我不想再包括库 – coderama

+0

我已经修改我的答案,以反映 – Asgaroth

+0

根本不管理。将继续尝试。代码应该去哪里? – coderama