• <tfoot id='KZD5K'></tfoot>

    <legend id='KZD5K'><style id='KZD5K'><dir id='KZD5K'><q id='KZD5K'></q></dir></style></legend>

    <small id='KZD5K'></small><noframes id='KZD5K'>

    • <bdo id='KZD5K'></bdo><ul id='KZD5K'></ul>

    1. <i id='KZD5K'><tr id='KZD5K'><dt id='KZD5K'><q id='KZD5K'><span id='KZD5K'><b id='KZD5K'><form id='KZD5K'><ins id='KZD5K'></ins><ul id='KZD5K'></ul><sub id='KZD5K'></sub></form><legend id='KZD5K'></legend><bdo id='KZD5K'><pre id='KZD5K'><center id='KZD5K'></center></pre></bdo></b><th id='KZD5K'></th></span></q></dt></tr></i><div id='KZD5K'><tfoot id='KZD5K'></tfoot><dl id='KZD5K'><fieldset id='KZD5K'></fieldset></dl></div>

      1. 如何在 Yii2 中使用 swiftMailer

        时间:2023-08-18

        1. <small id='tLeRi'></small><noframes id='tLeRi'>

              <legend id='tLeRi'><style id='tLeRi'><dir id='tLeRi'><q id='tLeRi'></q></dir></style></legend><tfoot id='tLeRi'></tfoot>

                <i id='tLeRi'><tr id='tLeRi'><dt id='tLeRi'><q id='tLeRi'><span id='tLeRi'><b id='tLeRi'><form id='tLeRi'><ins id='tLeRi'></ins><ul id='tLeRi'></ul><sub id='tLeRi'></sub></form><legend id='tLeRi'></legend><bdo id='tLeRi'><pre id='tLeRi'><center id='tLeRi'></center></pre></bdo></b><th id='tLeRi'></th></span></q></dt></tr></i><div id='tLeRi'><tfoot id='tLeRi'></tfoot><dl id='tLeRi'><fieldset id='tLeRi'></fieldset></dl></div>
                  <tbody id='tLeRi'></tbody>
                • <bdo id='tLeRi'></bdo><ul id='tLeRi'></ul>

                  本文介绍了如何在 Yii2 中使用 swiftMailer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我终于无法理解如何在 Yii2 中使用 swiftMailer 扩展.就这个题目来看,我没有发现问题,任务是微不足道的,但到最后我还是看不懂.

                  I can't finally understand how to use the swiftMailer extension in Yii2. Judging by that on this subject I didn't find questions, the task is trivial, but up to the end I couldn't understand.

                  有些例子没有更详细地描述发送信件的所有周期,或者我不明白一些事情:(

                  There are examples which don't describe in more detail all cycle of sending the letter or I don't understand something :(

                  设置

                      return [
                      //....
                     'components' => [
                      ......
                      'mail' => [
                        'class' => 'yiiswiftmailerMailer',
                        'transport' => [
                          'class' => 'Swift_SmtpTransport',
                          'host' => 'localhost',
                          'username' => 'username',
                          'password' => 'password',
                          'port' => '587',
                          'encryption' => 'tls',
                        ],
                      ],
                    ]
                  ];
                  

                  发送

                  Yii::$app->mail->compose()
                  ->setTo($toEmail)
                  ->setFrom([$this->email => $this->name])
                  ->setSubject($this->subject)
                  ->setTextBody($this->body)
                  ->send();
                  

                  我希望收到一个具体的工作示例.谢谢.

                  附言我调整了域记录 MX、DKIM、SPF 添加.

                  P.S. I adjusted domain records MX, DKIM, SPF added.

                  UPD(一些答案):

                  在发件人"字段中传递的电子邮件,在该字段中默认放下的返回路径",必须是现有地址.一些供应商没有允许从不存在的电子邮件地址发送邮件.

                  E-mail which is passed in "From" field, it is put down by default in the field of "Return-path", has to be the existing address. Some providers don't allow sending mail from nonexistent email addresses.

                  推荐答案

                  确保您已在生产环境中初始化您的应用程序以从您的应用程序发送电子邮件,否则它将被写入邮件输出文件夹.或手动编辑配置文件如下.

                  Make sure you have initialised your application in production environment to send emails from your application,else it will be written in to the mailoutput folder.Or manually edit the config file like follows.

                  在你的 common/main-local.php 的组件部分

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

                  'mail' => [
                          'class' => 'yiiswiftmailerMailer',
                          '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',
                              ],
                      ],
                  

                  在你的控制器中

                      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!

                  这篇关于如何在 Yii2 中使用 swiftMailer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:Yii 框架:使用来自相关 Active Record 模型的数据进行搜索 下一篇:如何在 Yii 框架中删除 index.php

                  相关文章

                  1. <tfoot id='omPbr'></tfoot>

                    <small id='omPbr'></small><noframes id='omPbr'>

                  2. <legend id='omPbr'><style id='omPbr'><dir id='omPbr'><q id='omPbr'></q></dir></style></legend>
                    • <bdo id='omPbr'></bdo><ul id='omPbr'></ul>

                    <i id='omPbr'><tr id='omPbr'><dt id='omPbr'><q id='omPbr'><span id='omPbr'><b id='omPbr'><form id='omPbr'><ins id='omPbr'></ins><ul id='omPbr'></ul><sub id='omPbr'></sub></form><legend id='omPbr'></legend><bdo id='omPbr'><pre id='omPbr'><center id='omPbr'></center></pre></bdo></b><th id='omPbr'></th></span></q></dt></tr></i><div id='omPbr'><tfoot id='omPbr'></tfoot><dl id='omPbr'><fieldset id='omPbr'></fieldset></dl></div>