dongmeiran609914 2014-07-02 17:24
浏览 59

从Yii2和wampserver 2.5发送电子邮件

I am using Yii2 in conjunction with wampserver 2.5 for my project. What I am trying to do is rather basic: I just need to be able to send emails from my local machine.

I have tried various tutorials and how-to's from across the internet and none have worked so far. I am trying to use swiftmailer, which is included in Yii2 with smtp.gmail.com.

I would really appreciate if someone using this combination (Yii2 and wampserver 2.5) could help me here.

  • 写回答

1条回答 默认 最新

  • douzhaiyuan1731 2014-07-03 04:13
    关注

    I use xampp server with yii2 and swiftmailer extension.I configured my swiftmailer to use my gmail as smtp to send mails.Following is my code.

    In the components's section of your common/main-local.php

    'mail' => [
            'class' => 'yii\swiftmailer\Mailer',
            'viewPath' => '@backend/mail',
            'useFileTransport' => false,//to send mails to real email addresses else will get stored in your mail/runtime folder
            //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',
                            ],
        ],
        ],
    

    In your 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();
    

    This should work! Hope this will help you!

    评论

报告相同问题?

悬赏问题

  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序