2016-11-12 02:12:23 3313次浏览 2条回答 0 悬赏 10 金钱

使用yii2发送邮件的时候,出现了这个问题,有知道解决办法或遇到过相同的情况的吗?求助。

补充于 2016-11-12 02:16

web.php

'components' => [
    'mailer' => [
        'class' => 'yii\swiftmailer\Mailer',
        // send all mails to a file by default. You have to set
        // 'useFileTransport' to false and configure a transport
        // for the mailer to send real emails.
        'useFileTransport' => false,
        'transport' => [
            'class' => 'Swift_SmtpTransport',
            'host' => 'smtp.163.com',
            'username' => 'xxx@163.com',
            'password' => 'xxxx',
            'port' => '465',
            'encryption' => 'ssl',
        ],
    ],
],

使用

$mailer = Yii::$app->mailer->compose();
$mailer->setFrom("15239114700@163.com");

只要使用就奇怪的找不到。

最佳答案

  • jackiegao 发布于 2016-11-12 22:14 举报

    是这样的吗?不应该是下面这样?
    $mailer = Yii::$app->mailer; $mailer->compose(); $mailer->setFrom("15239114700@163.com");

    6 条回复
    回复于 2016-11-16 20:59 回复

    我试了下,按照这种写法会报Calling unknown method: yii\swiftmailer\Mailer::setFrom()的错误。

    回复于 2016-11-16 21:30 回复

    看看/vendor/yiisoft/下有没有yii2-swiftmailer,你的config中配置的mailer需要这个,如果没有composer安装

    回复于 2016-11-16 21:56 回复

    本身是通过composer安装的,文件是存在的,这些应该都没问题,我安了几次了。

    回复于 2016-11-16 22:15 回复

    留下qq

    回复于 2016-11-16 23:46 回复

    1466989448

    回复于 2016-11-17 00:57 回复

    谢谢你,问题解决了。我下的版本不是官网的。它把index.php入口文件的引入自动加载器默认给关闭了,真心醉了。再次谢谢你。加个qq吧,下次遇到思路方面的问题,好向你请教。

    , 觉得很赞
  • 回答于 2016-11-16 20:32 举报

    vendor/swiftmailer 这个包在不在,不在安装之,在则检查一下你的composer的autoload,看看为啥没有自动加载..

您需要登录后才可以回答。登录 | 立即注册
玩个锤子
主管

玩个锤子

注册时间:2016-11-07
最后登录:2017-02-28
在线时长:13小时44分
  • 粉丝6
  • 金钱580
  • 威望10
  • 积分810

热门问题