【问题标题】:Difference between Laravel Mail vs swiftmailerLaravel Mail 与 swiftmailer 的区别
【发布时间】:2014-08-29 07:41:21
【问题描述】:

这可能是一个愚蠢的问题,但我使用的是 Laravel 4.2。我正在使用 Laravel 发送电子邮件,我知道 Laravel 带有 SwiftMailer。如果我像下面的代码一样调用 Mail::send,我是在调用 SwiftMailer 的邮件库还是在调用 PHP 的邮件库?那么,这两者有什么区别呢?

app/config/mail.php

return array(
    'driver' => 'smtp',
    'host' => 'smtp.gmail.com',
    'port' => 465,
    'from' => array('address' => 'my_gmail_username.gmail.com', 'name' => 'Test Email'),
    'encryption' => 'ssl',
    'username' => 'my_gmail_username',
    'password' => 'my_gmail_password',
    'sendmail' => '/usr/sbin/sendmail -bs',

app/routes.php

namespace MyMail;    
use Mail;

Mail::send('mail_template1', array('name' => 'Laravel'), function($message) use ($arr_index)
            {
                $message->to('name@email.com', 'name')
                        ->from('different_email@gmail.com', 'Another name')
                        ->subject('Laravel Email Test 1');  
            });

【问题讨论】:

  • Mail::send 只是 swift mailer 的 laravel 包装器,所以你在调用时调用了 swift mailer

标签: php email laravel-4 swiftmailer


【解决方案1】:

Laravel 在流行的 SwiftMailer 库上提供了一个干净、简单的 API。

关于 php 邮件:

如果你想使用PHP的邮件功能发送邮件,你可以在配置文件中将驱动改成mail。

Mail::send 只是 swift mailer 的 laravel 包装器,因此在调用时调用 swift mailer 除非你将 'driver' => 'smtp' 更改为 'driver' => 'mail',只有这样它才会使用 PHP 的邮件。

参考:Laravel Mail Documentation

【讨论】:

  • 非常感谢您的解释。我看到有些人使用 $message = Swift_Message::newInstance()。所以我想我是在调用 PHP 的邮件库,除非我这样声明。
猜你喜欢
  • 1970-01-01
  • 2019-11-24
  • 1970-01-01
  • 2016-07-03
  • 1970-01-01
  • 2017-03-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多