我尝试使用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');
});
有什么想法吗? 谢谢
答案 0 :(得分: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');