Yii2 uses swiftmailer to send emails, yii2swiftmailer_PHP tutorial

WBOY
Release: 2016-07-12 08:53:05
Original
1138 people have browsed it

Yii2 uses swiftmailer to send emails, yii2swiftmailer

This article describes the example of Yii2 using swiftmailer to send emails. Share it with everyone for your reference, the details are as follows:

'mail' => [
    'class' => 'yii\swiftmailer\Mailer',
    'viewPath' => '@backend/mail',
    'useFileTransport' => false,//set this property to false to send mails to real email addresses
    //comment the following array to send mail using php's mail function
    'transport' => [
      'class' => 'Swift_SmtpTransport',
      'host' => 'smtp.gmail.com',
      'username' => 'username@gmail.com',
      'password' => 'password',
      'port' => '587',
      'encryption' => 'tls',
     ],
  ],
],

Copy after login

Controller:

Yii::$app->mail->compose('your_view', ['params' => $params])
 ->setFrom([\Yii::$app->params['supportEmail'] => 'Test Mail'])
 ->setTo('to_email@xx.com')
 ->setSubject('This is a test mail ' )
 ->send();

Copy after login

Readers who are interested in more Yii-related content can check out the special topics on this site: "Introduction to Yii Framework and Summary of Common Techniques", "Summary of Excellent PHP Development Framework", "Basic Tutorial for Getting Started with Smarty Templates", "php Date and Time" Usage Summary", "php object-oriented programming introductory tutorial", "php string (string) usage summary", "php mysql database operation introductory tutorial" and "php common database operation skills summary"

I hope this article will be helpful to everyone’s PHP program design based on the Yii framework.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1125239.htmlTechArticleYii2 uses swiftmailer to send emails, yii2swiftmailer This article describes the example of Yii2 using swiftmailer to send emails. Share it with everyone for your reference, the details are as follows: 'mai...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template