iamserjo / sendgrid-php
此库允许您使用PHP快速轻松地通过Twilio SendGrid发送电子邮件。
Requires
- php: >=5.6
- ext-curl: *
- ext-json: *
- ext-mbstring: *
- ext-openssl: *
- iamserjo/php-http-client: ~3.10
Replaces
- sendgrid/sendgrid-php: *
- dev-master
- v7.5.0
- 7.4.6
- 7.4.5
- 7.4.4
- 7.4.3
- 7.4.2
- 7.4.1
- 7.4.0
- 7.3.0
- 7.2.1
- 7.2.0
- 7.1.1
- 7.1.0
- 7.0.0
- 6.2.0
- 6.1.0
- 6.0.0
- 5.6.2
- 5.6.1
- 5.6
- 5.5.1
- 5.5.0
- 5.4.2
- 5.4.1
- 5.4.0
- 5.3.0
- 5.2.3
- 5.2.2
- 5.2.1
- 5.2.0
- 5.1.2
- 5.1.1
- 5.1.0
- 5.0.9
- 5.0.8
- 5.0.7
- 5.0.6
- 5.0.4
- 5.0.3
- 5.0.1
- 5.0.0
- 4.0.4
- 4.0.2
- 4.0.1
- 4.0.0
- 3.2.0
- 3.1.0
- 3.0.0
- 2.2.1
- 2.2.0
- 2.1.1
- 2.1.0
- 2.0.6
- 2.0.5
- 2.0.4
- 2.0.3
- 2.0.2
- 2.0.1
- 1.1.7
- 1.1.6
- 1.1.5
- 1.1.4
- 1.1.3
- 1.1.2
- 1.1.1
- 1.1.0
- 1.0.9
- 1.0.8
- 1.0.7
- 1.0.6
- 1.0.5
- 1.0.4
- 1.0.3
- 1.0.2
- 1.0.1
- 1.0.0
This package is auto-updated.
Last update: 2024-09-06 08:03:48 UTC
README
NEW
此库允许您通过PHP快速轻松地使用Twilio SendGrid Web API v3。
此库的7.X.X版本提供了对所有Twilio SendGrid Web API v3端点的全面支持,包括新的v3 /mail/send。
我们希望这个库是由社区驱动并由Twilio SendGrid领导的。您的帮助对于实现这一目标至关重要。为了确保我们按照正确的顺序构建正确的事情,我们要求您创建问题和pull请求,或者简单地对现有的问题或pull请求进行投票或评论。
请浏览此README的其他部分以获取更多详细信息。
我们感谢您的持续支持,谢谢!
目录
安装
先决条件
- PHP版本5.6,7.0,7.1,7.2,7.3或7.4
- Twilio SendGrid服务,起始级别为免费,在前30天内可发送多达40,000封电子邮件,然后每天免费发送100封电子邮件,或者查看我们的定价。
- 对于短信消息,您需要一个免费的Twilio账户。
设置环境变量
使用您的 SENDGRID_API_KEY 更新开发环境,例如
- 将示例env文件复制到新文件
.env
cp .env.sample .env
- 编辑
.env
文件以包含您的SENDGRID_API_KEY
- 源
.env
文件
source ./.env
安装包
将Twilio SendGrid添加到您的composer.json
文件。如果您没有使用Composer,我们强烈推荐它。它是管理PHP应用程序依赖项的绝佳方式。
{ "require": { "sendgrid/sendgrid": "~7" } }
替代方案:从zip文件安装包
如果您没有使用Composer,只需下载并安装库的最新打包版本(作为zip文件)。
库的先前版本可以在版本索引中找到,或者直接从GitHub下载。
依赖关系
- Twilio SendGrid服务,从免费级别开始免费版
- 无依赖的php-http-client
快速开始
Hello Email
以下是将电子邮件发送所需的最低代码。您可以在我们的USE_CASES文件中找到更多示例
<?php require 'vendor/autoload.php'; // If you're using Composer (recommended) // Comment out the above line if not using Composer // require("<PATH TO>/sendgrid-php.php"); // If not using Composer, uncomment the above line and // download sendgrid-php.zip from the latest release here, // replacing <PATH TO> with the path to the sendgrid-php.php file, // which is included in the download: // https://github.com/sendgrid/sendgrid-php/releases $email = new \SendGrid\Mail\Mail(); $email->setFrom("test@example.com", "Example User"); $email->setSubject("Sending with Twilio SendGrid is Fun"); $email->addTo("test@example.com", "Example User"); $email->addContent("text/plain", "and easy to do anywhere, even with PHP"); $email->addContent( "text/html", "<strong>and easy to do anywhere, even with PHP</strong>" ); $sendgrid = new \SendGrid(getenv('SENDGRID_API_KEY')); try { $response = $sendgrid->send($email); print $response->statusCode() . "\n"; print_r($response->headers()); print $response->body() . "\n"; } catch (Exception $e) { echo 'Caught exception: '. $e->getMessage() ."\n"; }
SendGrid\Mail
构造函数为您创建了一个个性化对象。这里是一个如何向其中添加内容的示例。
通用v3 Web API使用(使用流畅接口)
<?php require 'vendor/autoload.php'; // If you're using Composer (recommended) // Comment out the above line if not using Composer // Comment out the above line if not using Composer // require("<PATH TO>/sendgrid-php.php"); // If not using Composer, uncomment the above line and // download sendgrid-php.zip from the latest release here, // replacing <PATH TO> with the path to the sendgrid-php.php file, // which is included in the download: // https://github.com/sendgrid/sendgrid-php/releases $apiKey = getenv('SENDGRID_API_KEY'); $sg = new \SendGrid($apiKey); try { $response = $sg->client->suppression()->bounces()->get(); print $response->statusCode() . "\n"; print_r($response->headers()); print $response->body() . "\n"; } catch (Exception $e) { echo 'Caught exception: '. $e->getMessage(). "\n"; }
通用v3 Web API使用(不使用流畅接口)
<?php require 'vendor/autoload.php'; // If you're using Composer (recommended) // Comment out the above line if not using Composer // Comment out the above line if not using Composer // require("<PATH TO>/sendgrid-php.php"); // If not using Composer, uncomment the above line and // download sendgrid-php.zip from the latest release here, // replacing <PATH TO> with the path to the sendgrid-php.php file, // which is included in the download: // https://github.com/sendgrid/sendgrid-php/releases $apiKey = getenv('SENDGRID_API_KEY'); $sg = new \SendGrid($apiKey); try { $response = $sg->client->_("suppression/bounces")->get(); print $response->statusCode() . "\n"; print_r($response->headers()); print $response->body() . "\n"; } catch (Exception $e) { echo 'Caught exception: '. $e->getMessage(). "\n"; }
用例
常见API用例示例,例如如何使用事务性模板发送电子邮件。
用法
公告
v7已发布!请查看发布说明以获取详细信息。
该库的所有更新都在我们的CHANGELOG和发布中记录。您还可以订阅发布通知以获取发布和重大更改。
路线图
如果您对该项目的未来方向感兴趣,请查看我们的公开问题和拉取请求。我们非常乐意听取您的反馈。
如何贡献
我们鼓励为我们的库做出贡献(您甚至可能获得一些酷炫的赠品),请参阅我们的CONTRIBUTING指南以获取详细信息。
快速链接
故障排除
请参阅我们的故障排除指南以了解常见的库问题。
关于
sendgrid-php由Twilio SendGrid,Inc维护和资助。sendgrid-php的名称和标志是Twilio SendGrid,Inc的商标。
如果您需要安装或使用库的帮助,请检查Twilio SendGrid支持帮助中心。
如果您在库中发现了错误或想添加新功能,请继续为此仓库打开问题或拉取请求!