【问题标题】:Laravel Class Swift_Mailer not found未找到 Laravel 类 Swift_Mailer
【发布时间】:2014-07-31 07:53:33
【问题描述】:

我正在尝试使用 laravel 4.2.1 + gmail 发送电子邮件,但出现以下错误

Symfony \ Component \ Debug \ Exception \ FatalErrorException
Class 'Swift_Mailer' not found

这是我的邮件配置文件

'driver' => 'smtp',
'host' => 'smtp.gmail.com',
'port' => 587,
'from' => array('address' => 'mygmail@gmail.com', 'name' => 'Admin'),
'encryption' => 'tls',
'username' => 'mygmail@gmail.com',
'password' => 'mypassword',
'sendmail' => '/usr/sbin/sendmail -bs',
'pretend' => false,

这里是发送电子邮件的代码

 $data = [
            'activationLink'=>$activationCode
        ];    
Mail::send('emails.register.activation', $data, function($message)
        {
            $message->to('email@outlook.com')
                    ->subject('Activate Your Account');
        });

有什么想法吗? 谢谢

【问题讨论】:

  • 你用的是什么用户名和密码……?
  • 我的 gmail 用户名和密码。我不能在这里发布,这就是为什么我为用户名和密码放置一个占位符
  • 恭喜。你通过了测试;)

标签: php symfony laravel-4


【解决方案1】:

检查你的 autoload.php 中是否有这些行

 // Swiftmailer needs a special autoloader to allow
 // the lazy loading of the init file (which is expensive)
 require_once __DIR__.'/../vendor/swiftmailer/lib/classes/Swift.php';
 Swift::registerAutoload(__DIR__.'/../vendor/swiftmailer/lib/swift_init.php');

【讨论】:

  • 谢谢你。你让我走向了正确的方向。我去了 vendor/sswiftmailer/swiftmailer/lib/classes/ 并且出于某种原因文件夹 Swift 被重命名为 Swift (1) 我更改了名称,一切都很好;)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-05-03
  • 2017-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多