
脱离 laravel 后使用 illuminatemail 发送邮件
illuminate 作为 laravel 的重要组件之一,提供了强大的邮件发送功能。但是,有时我们需要在不使用 laravel 的情况下使用 illuminatemail。那么,如何实现这一操作呢?
解决方案
有两种方法可以在不使用 laravel 的情况下使用 illuminatemail:
- 直接使用底层的 symfony mail
symfony mail 是 illuminate mail 的基础组件。要直接使用它,你首先需要使用 composer 安装它:
composer require symfony/mailer
以下是如何使用 symfony mail 发送邮件的示例:
use symfony\component\mailer\transport;
use symfony\component\mailer\mailer;
use symfony\component\mime\email;
$transport = transport::fromdsn('smtp://smtp服务器');
$mailer = new mailer($transport);
$email = (new email())
->from('xx@x.com')
->to('xx@xxxxx.com')
->subject('test')
->text('test')
->html('test');
$mailer->send($email);- 安装额外的组件
illuminate mail 依赖于一些其他组件,包括视图组件。你需要额外安装这些组件:
composer require illuminate/view
安装完成后,你可以使用以下代码发送邮件:
$mailer = new Illuminate\Mail\Mailer('default', new Illuminate\Contracts\View($engine, $finder, new Illuminate\Events\Dispatcher), new Symfony\Component\Mailer\Transport\TransportInterface(), new Illuminate\Events\Dispatcher);
// 此时,你可以根据 Laravel 文档进行操作。










