laswitchtech/php-smtp 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

laswitchtech/php-smtp

最新稳定版本:v2.1.13

Composer 安装命令:

composer require laswitchtech/php-smtp

包简介

This PHP SMTP email library provides a simple and easy-to-use solution for sending emails using SMTP servers.

README 文档

README

GitHub repo logo

phpSMTP - [DEPRECATED] - Use coreSMTP instead

License GitHub repo size GitHub top language Version

Description

This library is a PHP implementation of the Simple Mail Transfer Protocol (SMTP) that allows sending emails using an SMTP server. The library provides a class called phpSMTP that encapsulates the functionality of establishing a connection with an SMTP server, authenticating the user, setting up the email message, and sending the email.

The class provides several methods to configure the email message, such as setting the sender, recipients, subject, body, and attachments. It also provides a method to load an email template and insert the message body into it.

Additionally, the class allows for debugging the SMTP session by logging the communication between the client and the server to a file. It also provides error handling and logging mechanisms to help identify and troubleshoot any issues that might occur during the sending process.

Features

  • Send emails using SMTP protocol
  • Supports TLS and SSL encryption
  • Authenticate SMTP connections with username and password
  • Support for HTML and plain text messages
  • Support for email attachments
  • Customizable email templates using placeholders
  • Option to send to multiple recipients
  • Option to add CC and BCC recipients
  • Option to specify a reply-to email address
  • Automatic email body conversion from HTML to plain text
  • Debug mode for troubleshooting SMTP connections
  • Log events to file
  • Composer package for easy installation and integration with other PHP projects

Why you might need it?

This PHP SMTP email library provides a simple and easy-to-use solution for sending emails using SMTP servers. It offers a range of features such as support for multiple recipients, attachments, and HTML emails. With this library, you can easily integrate email functionality into your PHP applications and streamline your email communication. It also includes error handling and logging to ensure that any issues are identified and resolved quickly. Overall, this library is a valuable tool for any PHP developer looking to incorporate email functionality into their projects.

Can I use this?

Sure!

License

This software is distributed under the GNU General Public License v3.0 license. Please read LICENSE for information on the software availability and distribution.

Requirements

PHP >= 5.5.0

Security

Please disclose any vulnerabilities found responsibly – report security issues to the maintainers privately.

Installation

Using Composer:

composer require laswitchtech/php-smtp

How do I use it?

Examples

Connecting to a SMTP Server

//Import SMTP class into the global namespace
//These must be at the top of your script, not inside a function
use LaswitchTech\SMTP\phpSMTP;

//Load Composer's autoloader
require 'vendor/autoload.php';

//Create an instance of phpSMTP
$phpSMTP = new phpSMTP();

//Connect to your server
$phpSMTP->connect("username@domain.com","*******************","mail.domain.com","465","ssl");

Authenticating a user against a SMTP server

//Import SMTP class into the global namespace
//These must be at the top of your script, not inside a function
use LaswitchTech\SMTP\phpSMTP;

//Load Composer's autoloader
require 'vendor/autoload.php';

//Create an instance of phpSMTP
$phpSMTP = new phpSMTP();

if($phpSMTP->login("username@domain.com","*******************","mail.domain.com","465","ssl")){
  echo "User Authenticated!\n";
}

Sending an email

//Import SMTP class into the global namespace
//These must be at the top of your script, not inside a function
use LaswitchTech\SMTP\phpSMTP;

//Load Composer's autoloader
require 'vendor/autoload.php';

//Create an instance of phpSMTP
$phpSMTP = new phpSMTP();

//Connect to your server
$phpSMTP->connect("username@domain.com","*******************","mail.domain.com","465","ssl");

if($phpSMTP->send([
  "to" => "username@domain.com",
  "subject" => "Lorem",
  "body" => "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.",
])){
  echo "Message Sent!\n";
}

Creating a template

You can create templates in HTML or PLAIN TEXT.

Here is a list of placeholders that can be used:

  • %FROM%
  • %REPLY-TO%
  • %TO% (first in the list)
  • %CC% (first in the list)
  • %BCC% (first in the list)
  • %SUBJECT%
  • %BODY%

Example in plain text:

phpSMTP
============================================================================================================

%SUBJECT%
------------------------------------------------------------------------------------------------------------
Hi %TO%,
%BODY%

Sincerely,
phpSMTP

Adding a template

//Import SMTP class into the global namespace
//These must be at the top of your script, not inside a function
use LaswitchTech\SMTP\phpSMTP;

//Load Composer's autoloader
require 'vendor/autoload.php';

//Create an instance of phpSMTP
$phpSMTP = new phpSMTP();

//Add your template
$phpSMTP->addTemplate('html','tmp/templates/default.html');

Selecting a template

//Import SMTP class into the global namespace
//These must be at the top of your script, not inside a function
use LaswitchTech\SMTP\phpSMTP;

//Load Composer's autoloader
require 'vendor/autoload.php';

//Create an instance of phpSMTP
$phpSMTP = new phpSMTP();

//Select your template
$phpSMTP->setTemplate('html');

laswitchtech/php-smtp 适用场景与选型建议

laswitchtech/php-smtp 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 132 次下载、GitHub Stars 达 0, 最近一次更新时间为 2022 年 10 月 26 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 laswitchtech/php-smtp 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 laswitchtech/php-smtp 我们能提供哪些服务?
定制开发 / 二次开发

基于 laswitchtech/php-smtp 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 132
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 11
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-3.0-only
  • 更新时间: 2022-10-26