Yii how to use PHPMailer to send emails
As a common component:
In this example, use SMTP as the sending method to create a component in the controller:
| 12345678910111213 |
Host = ; $ Mailer-> IsSMTP (); $ mailer-> From = 'Wei @ example.com '; $ mailer-> AddReplyTo ('Wei @ example.com '); $ mailer-> AddAddress ('Qiang @ example.com '); $ 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 ):
| 123456789 |
Array ('mailer' => array ('class' => 'application. extensions. mailer. EMailer ', 'pathviews' => 'application. views. email ', 'pathlayouts' => 'application. views. email. layouts '),//...} |
Controller code:
| 1234567891011 |
Mailer-> Host = 'smtp .yiiframework.com '; Yii: app ()-> mailer-> IsSMTP (); Yii: app () -> mailer-> From = 'Wei @ pradosoft.com '; Yii: app ()-> mailer-> FromName = 'Wei'; Yii: app () -> mailer-> AddReplyTo ('Wei @ pradosoft.com '); Yii: app ()-> mailer-> AddAddress ('Qian @ yiiframework.com'); Yii: app () -> mailer-> Subject = 'yii rulez! '; Yii: app ()-> mailer-> Body = $ message; Yii: app ()-> mailer-> Send (); |