swarletta / swiftmailer
该包最新版本(1.0)的许可信息不可用。
1.0
2021-02-14 16:25 UTC
Requires
- swiftmailer/swiftmailer: ^6.0
- vlucas/phpdotenv: ^5.3
This package is not auto-updated.
Last update: 2024-09-24 07:57:44 UTC
README
从您的网站发送电子邮件。基于 swiftmailer/swiftmailer。
## 使用 Composer 安装 composer require swarletta/swiftmailer
## 初始化 首先,您需要引入一个帮助您处理 .env 文件的库
然后创建一个 MailTransport 实例。您将需要这些参数
对于 SMTP 服务器:smtp.gmail.com
– SMTP 用户: vashemail@gmail.com
– SMTP 密码: 您的 Gmail 账户的密码
– SMTP 端口: 465
– TLS/SSL: 需要。
以下是一个 Swiftmailer 调用的示例
<?php require 'vendor/autoload.php'; use App\MailTransport\MailTransport; use App\MailTransport\Message; use App\Render\Render; $dotenv = Dotenv\Dotenv::createUnsafeImmutable(__DIR__); $dotenv->load(); $mailTransport = new MailTransport( getenv('HOST'), (int) getenv('PORT'), getenv('USER_EMAIL'), getenv('USER_PASSWORD'), 'ssl' ); $templateName = 'auth'; $message = 'You have been successufuly authorization'; $templateMessage = (new Render())->build_email_template($templateName, $message); $mailTransport->send( new Message('Welcome', $templateMessage, getenv('EMAIL_TO')));