installing yii-mail in an existing web application

2019-06-02 04:46发布

I just downloaded yii-mail and would like to use it in my yii application but i dont know where to but the files. I tried going to the documentation on the link provided on the yii-mail page but it doesnt help. Where should i put the files and is there some line of code i need to add to the application so I can use the mail function?

2条回答
啃猪蹄的小仙女
2楼-- · 2019-06-02 04:50

Follow this steps:

  1. Download the PHPMailer extension for Yii Framework from this link.
  2. Create ‘extensions‘ directory under ‘protected‘ directory. (Optional if you have created it before)
  3. Extract the compressed files into extensions directory.
  4. Now created a new controller and make a function actionSendEmail().
  5. Put the codes into the actionSendMail() body.
  6. Call the action request to your controller and wait until your web server finish processing your request.
  7. If the your mail sent successfully it will display result ‘Message sent successfully!‘ either it will display ‘Fail to send your message!‘

Code:

<php
public function actionSendEmail() {
     $mailer = Yii::createComponent('application.extensions.mailer.EMailer');
     $mailer->IsSMTP();
     $mailer->IsHTML(true);
     $mailer->SMTPAuth = true;
     $mailer->SMTPSecure = "ssl";
     $mailer->Host = "smtp.gmail.com";
     $mailer->Port = 465;
     $mailer->Username = "test@aslingga.com";
     $mailer->Password = "testpasswdxxx";
     $mailer->From = "test@aslingga.com";
     $mailer->FromName = "Test";
     $mailer->AddAddress("user@example.com");
     $mailer->Subject = "Someone sent you an email.";
     $mailer->Body = "Hi, This is just a test email using PHP Mailer and Yii Framework.";
     if($mailer->Send()) {
          echo "Message sent successfully!";
     }
     else {
          echo "Fail to send your message!";
     }
}
?>
查看更多
SAY GOODBYE
3楼-- · 2019-06-02 04:55

Yii-mail is an extension for the yii framework (obvious), so when you download the files associated with that extension you'll put them in the extensions directory under your "protected" directory within you're yii project. Specifically you're extensions directory should have subdirectories each with the name of an extension.

In addition you will probably also have to go into /protected/config/main.php and add some code to allow the use of the extension. There is likely a "how to, copy/paste" of how to do this on the page for the extension itself. Specifically though, you will be adding code to the "components" array in main.php, which is just a big array itself.

查看更多
登录 后发表回答