sendgrid / sendgrid
此库允许您通过PHP轻松快速地通过Twilio SendGrid发送电子邮件。
Requires
- php: >=7.3
- ext-curl: *
- ext-json: *
- ext-mbstring: *
- ext-openssl: *
- sendgrid/php-http-client: ~4.1
- starkbank/ecdsa: 0.*
Requires (Dev)
- phpstan/phpstan: ^1.5
- phpunit/phpunit: ^9
- squizlabs/php_codesniffer: 3.*
- swaggest/json-diff: ^3.4
Replaces
- sendgrid/sendgrid-php: *
- dev-main
- 8.1.2
- 8.1.1
- 8.1.0
- 8.0.1
- 8.0.0
- 7.11.5
- 7.11.4
- 7.11.3
- 7.11.2
- 7.11.1
- 7.11.0
- 7.10.0
- 7.9.2
- 7.9.1
- 7.9.0
- 7.8.5
- 7.8.4
- 7.8.3
- 7.8.2
- 7.8.1
- 7.8.0
- 7.7.0
- 7.6.0
- 7.5.2
- 7.5.1
- 7.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
- dev-ecdsa-version-upgrade
- dev-krischoi07-patch-1
- dev-example-heroku-hello-email
- dev-inbound
- dev-mail
This package is auto-updated.
Last update: 2024-09-18 11:55:38 UTC
README
新功能
- 使用 Twilio 发送短信。
此库允许您通过PHP轻松快速地使用Twilio SendGrid Web API v3。
此库的7.X.X版本为所有Twilio SendGrid Web API v3端点提供全面支持,包括新的v3 /mail/send端点。
如果您需要使用SendGrid的支持,请检查Twilio SendGrid支持帮助中心。
请浏览此README的其余部分以获取更多详细信息。
感谢您的持续支持,谢谢!
目录
安装
先决条件
- PHP版本7.3,7.4,8.0或8.1
- 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
快速入门
根据您的安装方法,从以下内容中包含适当的行到每个示例的顶部
<?php // Uncomment the next line if you're using a dependency loader (such as Composer) (recommended) // require 'vendor/autoload.php'; // Uncomment the next line if you're not using a dependency loader (such as Composer), replacing <PATH TO> with the path to the sendgrid-php.php file // require_once '<PATH TO>/sendgrid-php.php';
你好,电子邮件
以下是最小需要发送电子邮件的代码。您可以在我们的USE_CASES文件中找到更多示例
$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 使用(使用流畅接口)
$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 使用(不使用流畅接口)
$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 已发布!请参阅 发布说明 了解详细信息。
如何贡献
我们鼓励为我们的库做出贡献(您甚至可能获得一些有趣的配饰),请参阅我们的 贡献指南 了解详细信息。
快速链接
故障排除
请参阅我们的 故障排除指南 了解常见的库问题。
关于
sendgrid-php 由 Twilio SendGrid,Inc 维护和资助。sendgrid-php 的名称和标志是 Twilio SendGrid,Inc 的商标。
支持
有关产品支持,请查看 Twilio SendGrid 支持帮助中心。