这可能是一个愚蠢的问题,但我正在使用 Laravel 4.2。我正在使用 Laravel 发送电子邮件,并且我知道 Laravel 附带 SwiftMailer。如果我像下面的代码那样调用 Mail::send,我是调用 SwiftMailer 的 Mail 库还是调用 PHP 的 Mail 库?那么,两者有什么区别呢?
应用程序/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',
应用程序/routes.php
namespace MyMail;
use Mail;
Mail::send('mail_template1', array('name' => 'Laravel'), function($message) use ($arr_index)
{
$message->to('<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="87e9e6eae2c7e2eae6eeeba9e4e8ea" rel="noreferrer noopener nofollow">[email protected]</a>', 'name')
->from('<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="04606d62626176616a705b6169656d68446369656d682a676b69" rel="noreferrer noopener nofollow">[email protected]</a>', 'Another name')
->subject('Laravel Email Test 1');
});
最佳答案
Laravel provides a clean, simple API over the popular SwiftMailer library.
关于 php 邮件:
If you wish to use the PHP mail function to send mail, you may change the driver to mail in the configuration file.
Mail::send 只是 swift mailer 的 laravel 包装器,因此在执行该调用时您将调用 swift mailer,除非您将 'driver' => 'smtp'
更改为 'driver ' => 'mail'
,这样才会使用PHP的邮件。
关于php - Laravel Mail 与 swiftmailer 之间的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25563724/