aselsan/codeigniter4-multi-smtp-config

CodeIgniter 多SMTP配置

v1.1.1 2024-09-01 10:33 UTC

This package is auto-updated.

Last update: 2024-09-04 06:19:41 UTC


README

为您的CodeIgniter 4应用程序提供的轻量级多SMTP配置助手。此包允许您同时使用不同的电子邮件账户。

CodeIgniter PHP Version Require

安装

composer require aselsan/codeigniter4-multi-smtp-config

发布文件配置

php spark smtpconfig:publish

之后,检查 app/Config/MultiEmail.php 文件,并使用您的电子邮件凭据进行设置。

.env 文件中配置SMTP

我们建议在 .env 文件中为每个SMTP电子邮件设置配置,而不是使用 app/Config/MultiEmail.php

例如,您可以按照以下步骤进行

#--------------------------------------------------------------------
# MULTI-SMTP CONFIGURATION SETTINGS
#--------------------------------------------------------------------

# email.default.fromName =
# email.default.fromEmail =
# email.default.protocol = smtp
# email.default.SMTPUser =
# email.default.SMTPPass =
# email.default.SMTPHost = smtp.gmail.com
# email.default.SMTPPort = 587

# email.outlook.fromName =
# email.outlook.fromEmail =
# email.outlook.protocol = smtp
# email.outlook.SMTPUser =
# email.outlook.SMTPPass =
# email.outlook.SMTPHost = smtp.office365.com
# email.outlook.SMTPPort = 587

用法

helper('multi_email');

$email = multi_email(['mailType' => 'html']);
$email->setTo('example@gmail.com');
$email->setSubject("Test Send Mail");
$email->setMessage('Hi, Bonjour');

if ($email->send(false) === false) {
       throw new Exception('Cannot send email:' . $email->printDebugger(['headers']));
}

// Clear the email
$email->clear();

您可以通过在第二个参数中提供组名来使用不同的邮件配置。

helper('multi_email');

$email = multi_email(['mailType' => 'html'], 'outlook');
$email->setTo('example@gmail.com');
$email->setSubject("Test Send Mail");
$email->setMessage('Hi, Bonjour');

if ($email->send(false) === false) {
       throw new Exception('Cannot send email:' . $email->printDebugger(['headers']));
}

// Clear the email
$email->clear();

许可证

本项目采用MIT许可证 - 有关详细信息,请参阅LICENSE 文件。