manlikeangus/zeptomail
Composer 安装命令:
composer require manlikeangus/zeptomail
包简介
ZeptoMail Email Client Library for PHP
README 文档
README
Generic PHP API Client for Zoho's ZeptoMail service
This unofficial ZeptoMail PHP library allows you to easily send transactional email messages via the Zoho ZeptoMail API.
The ZeptoMail system is intended for transactional emails related to website and app interactions (receipts, password resets, 2FA notices, etc.), not bulk sending of emails like newsletters and announcements. Please see the ZeptoMail site for details about use cases and guidelines.
Installation
For most uses we recommend installing the manlikeangus/zeptomail package via Composer. If you have Composer installed already, you can add the latest version of the package with the following command:
composer require manlikeangus/zeptomail
Or if you're adding this library to an application, in your composer.json file
"require": {
"manlikeangus/zeptomail": "^1.0"
}
Alternately, you can simply clone this repository directly to include the source code in your project.
Settings
Before you can connect to the API, you'll need two settings from your ZeptoMail account: an authorization key and a bounce address
If you are using an environment file, you'll want to create settings with these setting:
zeptomailkey = "MyAPIkeyfromZeptoMail"
zeptobounceaddr = "bounce@bounce.mydomain.com"
If you aren't using environment variables in your application, you can omit this step and pass these settings directly to the mailer (see full example below).
To load the library in your page or app, you'll need to include the file:
// doing your own loading: include_once ("./zeptomail/ZeptoMailClient.php"); // or if using composer autoloading: include_once ('./vendor/autoload.php');
Note: Your ability to send messages also requires that the sender's domain is pre-verified in your ZeptoMail dashboard. Without that, you will see authentication errors.
Basic Mailing Example:
//create a new message object $msg = new \stdClass(); //required settings $msg->subject = "My message subject"; //SUBJECT $msg->textbody = "My text-only message"; //TEXT MSG, NULL IF sending HTML $msg->htmlbody = "<p>My HTML-formatted message</p>"; //HTML MSG, NULL if sending TEXT $msg->to = array('joe@customer.com','Joe Customer'); //TO $msg->from = array('support@site.com','XYZ Company'); //FROM //instantiate library and pass info $tmail = new \ZeptoMail\ZeptoMailClient($msg); //send the message $response = $tmail->send(); if ($response) { // success } else { // failure }
Note: You can pass all email addresses either as a string or as an array, like this:
$msg->to = 'joe@customer.com'; //or $msg->to = array('joe@customer.com','Joe Customer');
If using an array, the formatter will look for the email address in either the first or second element position. If it finds an address, it will use the remaining element as the text name. If additional elements are passed here they will be ignored.
Full Example
Below are ALL the possible options, including manually setting an authorization key and bounce address:
//create a new message object $msg = new \stdClass(); //required settings $msg->subject = "My message subject"; //SUBJECT $msg->textbody = "My text-only message"; //TEXT MSG, NULL IF sending HTML $msg->htmlbody = "<p>My HTML-formatted message</p>"; //HTML MSG, NULL if sending TEXT $msg->to = array('joe@customer.com','Joe Customer'); //TO $msg->from = array('support@site.com','XYZ Company'); //FROM //optional settings $msg->reply_to = array('address@site.com','XYZ Company'); //REPLY TO $msg->cc = array('address2@site.com','Someone'); //CC $msg->bcc = array('address3@site.com','Somebody Else'); //BCC $msg->track_clicks = TRUE; //TRACK CLICKS, TRUE by default $msg->track_opens = TRUE; //TRACK OPENS, TRUE by default $msg->client_reference = NULL; //CLIENT ID (string) $msg->mime_headers = NULL; //ADDITIONAL MIME HEADERS (array) $msg->attachments = NULL; //ATTACHMENTS (array) $msg->inline_images = NULL; //INLINE IMAGES (array) //instantiate library and pass all possible settings $tmail = new \ZeptoMail\ZeptoMailClient($msg, "myapikey", "mybounce@address.com", TRUE); //send the message $response = $tmail->send(); if ($response) { // success } else { // failure }
Error Handling
When you actually load the library, there is a 4th parameter that can be passed to turn on verbose error reporting. By default, this is off and the function returns TRUE (message sent) and FALSE (message not sent).
There are two main possible points of failure that can occur: The cURL request could fail, or the API request could fail. In both cases, the function will return a generic FALSE unless you have verbose errors turned on.
With Verbose Errors Turned On:
In the event of a cURL error, a string will be returned with the specific PHP error code.
In the event of API success or failure, a JSON object with the entire API response will be returned. Consult the ZeptoMail documentation for error codes and other details about these messages.
Security Note: These verbose messages could divulge sensitive info about your site or your ZeptoMail account, so errors should be captured or turned off in a production setting.
Additional Headers
Passing additional headers to the email server is possible. Simply create any name-value pairs you want as an array and pass that to the function
$headers = array(); $headers[] = array( "CustId" => "1234", "CustName" => "Bob Smith" );
Sending Attachments
Sending attachments means loading the file into PHP's memory, converting to a Base64-encoded stream and then passing that to the function. Since there are three parameters needed by ZeptoMail, it is generally advised to first set up the attachments as an array and then pass that to the function:
$attachments = array(); $file = "filename.jpg"; $path = "/path/to/" . $file; $filedata = file_get_contents($path); if ($filedata) { $base64 = base64_encode($filedata); $attachments[] = array( "content" => $base64, "mime_type" => mime_content_type($path), "name" => $file ); }
List of unsupported attachments
Zoho ZeptoMail API Documentation
NOTE: This library only sends messages through the ZeptoMail API system. If you are attempting to send via SMTP, please consult the documentation for your web or email server's mail program for SMTP relaying.
manlikeangus/zeptomail 适用场景与选型建议
manlikeangus/zeptomail 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 8 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 11 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「email」 「transactional」 「Zoho」 「zeptomail」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 manlikeangus/zeptomail 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 manlikeangus/zeptomail 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 manlikeangus/zeptomail 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
An updated fork (psr-0 to psr-4) from the original library "Mandrill/Mandrill" (https://bitbucket.org/mailchimp/mandrill-api-php)
This package contains code to help you copy ZohoCRM records directly into your database.
Sendernet transactional email php API client
Extensible library for building notifications and sending them via different delivery channels.
Zoho Sign v1 API PHP Wrapper - PHP 7.4 Ready
Email+ extends Kirby's email capabilities by adding support for multiple email services using the same Kirby email API.
统计信息
- 总下载量: 8
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 24
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-11-04