Method of use
As a normal Component:
Using this example, create a component in the controller using SMTP as the sending method:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
$message=’Hello World! ‘; $mailer= Yii::createComponent(‘application.extensions.mailer.EMailer’); $mailer->Host = ; $mailer->IsSMTP(); $mailer->From =’[email protected]’; $mailer->AddReplyTo(‘[email protected]’); $mailer->AddAddress(‘[email protected]’); $mailer->FromName =’Wei Yard’; $mailer->CharSet =’UTF-8′; $mailer->Subject = Yii::t(‘demo’,’Yii rulez! ‘); $mailer->Body =$message; $mailer->Send(); |
As application Component: configuration file code (note the pathViews and pathLayouts parameters):
1 2 3 4 5 6 7 8 9 |
‘components’=>array( ‘mailer’=>array( ‘class’=>’application.extensions.mailer.EMailer’, ‘pathViews’=>’application.views.email’, ‘pathLayouts’=>’application.views.email.layouts’ ), // … } |
Controller code:
1 2 3 4 5 6 7 8 9 10 11 |
$message=’Hello World! ‘; Yii::app()->mailer->Host =’smtp.yiiframework.com’; Yii::app()->mailer->IsSMTP(); Yii::app()->mailer->From =’[email protected]’; Yii::app()->mailer->FromName =’Wei’; Yii::app()->mailer->AddReplyTo(‘[email protected]’); Yii::app()->mailer->AddAddress(‘[email protected]’); Yii::app()->mailer->Subject =’Yii rulez! ‘; Yii::app()->mailer->Body =$message; Yii::app()->mailer->Send(); |