awanesia/sendgrid-4.0.4

此库允许您使用PHP快速轻松地通过SendGrid发送电子邮件。

4.0.5 2020-06-04 21:57 UTC

This package is not auto-updated.

Last update: 2024-09-21 17:29:25 UTC


README

编辑版本

SendGrid-PHP

此库允许您使用PHP快速轻松地通过SendGrid发送电子邮件。

警告:此模块最近从 2.2.x 升级到 3.X。各种方法名称发生了API破坏性更改。请参阅 使用说明 获取最新的方法名称。

请阅读此内容

TLDR:如果您升级而不适当地更改代码,则 将会出错

最显著的变化之一是 addTo() 的行为。我们现在使用我们的Web API参数而不是 X-SMTPAPI 标头。这意味着如果您为电子邮件多次调用 addTo(),则将发送 一个 电子邮件,每个电子邮件地址都可见于所有人。为了利用向每个收件人发送个性化电子邮件的原始行为,您现在必须使用 addSmtpapiTo()如果添加了多个“收件人”地址,则这将破坏替换。

Smtpapi地址方法不能与非Smtpapi地址方法混合。这意味着您目前不能与 addSmtpapiTo() 一起使用Cc和Bcc。

默认情况下,如果响应代码不是200,则 send() 方法现在将抛出 \SendGrid\Exception 并返回 \SendGrid\Response 实例。

重要:此库需要PHP 5.3或更高版本。

BuildStatus Latest Stable Version

$sendgrid = new SendGrid('YOUR_SENDGRID_APIKEY');
$email = new SendGrid\Email();
$email
    ->addTo('foo@bar.com')
    ->setFrom('me@bar.com')
    ->setSubject('Subject goes here')
    ->setText('Hello World!')
    ->setHtml('<strong>Hello World!</strong>')
;

$sendgrid->send($email);

// Or catch the error

try {
	$sendgrid->send($email);
} catch(\SendGrid\Exception $e) {
	echo $e->getCode();
	foreach($e->getErrors() as $er) {
		echo $er;
	}
}

公告

对于使用我们的 Web API v3端点 的用户,我们已经开始将v3端点集成到此库中。我们还在更新和增强核心库代码。

我们已实施了几个 v3端点,并希望得到您的反馈。

感谢您持续的支持!

安装

将SendGrid添加到您的 composer.json 文件中。如果您没有使用 Composer,您应该使用它。它是管理PHP应用程序中依赖关系的绝佳方式。

{  
  "require": {
    "sendgrid/sendgrid": "~4.0"
  }
}

然后在您的PHP脚本顶部引入自动加载器

require 'vendor/autoload.php';

替代方案:从zip安装

如果您没有使用Composer,只需下载并安装 库的最新打包版本作为zip

⬇︎ 下载打包库 ⬇︎

然后从包中引入库

require("path/to/sendgrid-php/sendgrid-php.php");

库的先前版本可在 版本索引 中找到。

示例应用程序

有一个 sendgrid-php-example应用程序 帮助您快速启动开发。

用法

要开始使用此库,请使用您的SendGrid API密钥 初始化SendGrid对象。要配置API密钥,请访问 https://app.sendgrid.com/settings/api_keys

$sendgrid = new SendGrid('YOUR_SENDGRID_APIKEY');

创建一个新的SendGrid电子邮件对象并添加您的消息详细信息。

$email = new SendGrid\Email();
$email
    ->addTo('foo@bar.com')
    //->addTo('bar@foo.com') //One of the most notable changes is how `addTo()` behaves. We are now using our Web API parameters instead of the X-SMTPAPI header. What this means is that if you call `addTo()` multiple times for an email, **ONE** email will be sent with each email address visible to everyone.
    ->setFrom('me@bar.com')
    ->setSubject('Subject goes here')
    ->setText('Hello World!')
    ->setHtml('<strong>Hello World!</strong>')
;

发送它。

$sendgrid->send($email);

注意:总消息大小限制为20,480,000字节,或约19.5MB。这包括所有标题、正文和附件。 参考

异常

如果响应不是200 OK,则默认情况下将引发 SendGrid\Exception

要禁用异常,在创建 SendGrid\Client 时传入 raise_exceptions => false 选项。

$client = new SendGrid('YOUR_SENDGRID_APIKEY', array('raise_exceptions' => false));

选项

在初始化 SendGrid 对象时可以将选项传递给库。

$options = array(
    'turn_off_ssl_verification' => false,
    'protocol' => 'https',
    'host' => 'api.sendgrid.com',
    'endpoint' => '/api/mail.send.json',
    'port' => null,
    'url' => null,
    'raise_exceptions' => false
);
$sendgrid = new SendGrid('YOUR_SENDGRID_APIKEY', $options);

更改 URL

您可以通过向 options 提供各种参数来更改 sendgrid-php 用于发送电子邮件的 URL,所有参数都是可选的。

$sendgrid = new SendGrid(
    'YOUR_SENDGRID_APIKEY', 
    array(
        'protocol' => 'http', 
        'host' => 'sendgrid.org', 
        'endpoint' => '/send', 
        'port' => '80' 
    )
);

也可以提供完整的 URL。

$sendgrid = new SendGrid(
    'YOUR_SENDGRID_APIKEY', 
    array( 'url' => 'http://sendgrid.org:80/send')
);

忽略 SSL 证书验证

在使用 Web API 时,您可以选择忽略 SSL 证书验证。

$sendgrid = new SendGrid(
    'YOUR_SENDGRID_APIKEY', 
    array("turn_off_ssl_verification" => true)
);

响应

send() 方法返回 \SendGrid\Response 实例。

$email = new SendGrid\Email();
$email
    ->addTo('foo@bar.com')
    ->setFrom('me@bar.com')
    ->setSubject('Subject goes here')
    ->setText('Hello World!');
$res = $sendgrid->send($email);

var_dump($res);

// Output
object(SendGrid\Response)#31 (4) {
  ["code"]=>
  int(200)
  ["headers"]=>
  object(Guzzle\Http\Message\Header\HeaderCollection)#48 (1) {
    ["headers":protected]=>
    array(6) {
	...
      ["content-type"]=>
      object(Guzzle\Http\Message\Header)#41 (3) {
        ["values":protected]=>
        array(1) {
          [0]=>
          string(16) "application/json"
        }
        ["header":protected]=>
        string(12) "Content-Type"
        ["glue":protected]=>
        string(1) ","
      }
   ...
    }
  }
  ["raw_body"]=>
  string(21) "{"message":"success"}"
  ["body"]=>
  array(1) {
    ["message"]=>
    string(7) "success"
  }
}

getCode

返回响应的状态码。

$res = $sendgrid->send($email);
echo $res->getCode()

getHeaders

返回响应头作为 Guzzle\Http\Message\Header\HeaderCollection 对象

$res = $sendgrid->send($email);
$guzzle = $res->getHeaders();
echo var_dump($guzzle);

getRawBody

返回 SendGrid 的未解析 JSON 响应。

$res = $sendgrid->send($email);
echo $res->getRawBody()

getBody

返回 SendGrid 的解析 JSON。

$res = $sendgrid->send($email);
echo var_dump($res->getBody());

异常

如果响应代码不是 200,将引发 \SendGrid\Exception。捕获它是可选的,但强烈建议。

try {
    $sendgrid->send($email);
} catch(\SendGrid\Exception $e) {
    echo $e->getCode() . "\n";
    foreach($e->getErrors() as $er) {
        echo $er;
    }
}

// Output
400
Permission denied, wrong credentials

WEB API v3

APIKeys

列出属于认证用户的所有 API 密钥。 [GET]

require 'vendor/autoload.php';
Dotenv::load(__DIR__);
$sendgrid_apikey = getenv('SG_KEY');
$sendgrid = new Client($sendgrid_apikey);
$response = $sendgrid->api_keys->get();
print("Status Code: " . $response->getStatusCode() . "\n");
print("Body: " . $response->getBody() . "\n");

为认证用户生成新的 API 密钥。 [POST]

Dotenv::load(__DIR__);
$sendgrid_apikey = getenv('SG_KEY');
$sendgrid = new Client($sendgrid_apikey);
$api_key = "My API Key";
$scopes = array("mail.send", "alerts.create", "alerts.read"); // optional
$response = $sendgrid->api_keys->post($api_key, $scopes);
print("Status Code: " . $response->getStatusCode() . "\n");
print("Body: " . $response->getBody() . "\n");

更新现有 API 密钥的名称 [PATCH]

require 'vendor/autoload.php';
Dotenv::load(__DIR__);
$sendgrid_apikey = getenv('SG_KEY');
$sendgrid = new Client($sendgrid_apikey);
$api_key_id = "Q5xdErWiSO6b8fYUgtYY8g";
$response = $sendgrid->api_keys->patch($api_key_id, "Updated API Key Name");
print("Status Code: " . $response->getStatusCode() . "\n");
print("Body: " . $response->getBody() . "\n");

更新 API 密钥的名称和作用域 [PUT]

require 'vendor/autoload.php';
Dotenv::load(__DIR__);
$sendgrid_apikey = getenv('SG_KEY');
$sendgrid = new Client($sendgrid_apikey);
$api_key_id = "Q5xdErWiSO6b8fYUgtYY8g";
$name = "Updated API Key Name";
$scopes = array("user.profile.read", "user.profile.update");
$response = $sendgrid->api_keys->put($api_key_id, $name, $scopes);
print("Status Code: " . $response->getStatusCode() . "\n");
print("Body: " . $response->getBody() . "\n");
```php

Revoke an existing API Key [DELETE]

```php
require 'vendor/autoload.php';
Dotenv::load(__DIR__);
$sendgrid_apikey = getenv('SG_KEY');
$sendgrid = new Client($sendgrid_apikey);
$api_key_id = "Q5xdErWiSO6b8fYUgtYY8g";
$response = $sendgrid->api_keys->delete($api_key_id);
print("Status Code: " . $response->getStatusCode() . "\n");
print("Body: " . $response->getBody() . "\n");

[ASMGroups](https://sendgrid.com/docs/API_Reference/Web_API_v3/Suppression_Management/groups.html)

Retrieve all suppression groups associated with the user.

```php
require 'vendor/autoload.php';
Dotenv::load(__DIR__);
$sendgrid_apikey = getenv('SG_KEY');
$sendgrid = new Client($sendgrid_apikey);
$response = $sendgrid->asm_groups->get();
print("Status Code: " . $response->getStatusCode() . "\n");
print("Body: " . $response->getBody() . "\n");

ASMSuppressions

获取给定组的受抑制地址。

require 'vendor/autoload.php';
Dotenv::load(__DIR__);
$sendgrid_apikey = getenv('SG_KEY');
$sendgrid = new Client($sendgrid_apikey);
$group_id = 70;
$response = $sendgrid->asm_suppressions->get($group_id);
print("Status Code: " . $response->getStatusCode() . "\n");
print("Body: " . $response->getBody() . "\n");

将收件人地址添加到给定组的受抑制列表中。

$group_id = 70;
$email = 'elmer.thomas+test1@gmail.com';
$response = $sendgrid->asm_suppressions->post($group_id, $email);
print("Status Code: " . $response->getStatusCode() . "\n");
print("Body: " . $response->getBody() . "\n");

$email = array('elmer.thomas+test5@gmail.com', 'elmer.thomas+test6@gmail.com');
$response = $sendgrid->asm_suppressions->post($group_id, $email);
print("Status Code: " . $response->getStatusCode() . "\n");
print("Body: " . $response->getBody() . "\n");

从组的受抑制列表中删除收件人电子邮件。

$group_id = 70;
$email = 'elmer.thomas+test1@gmail.com';
$response = $sendgrid->asm_suppressions->delete($group_id, $email);
print("Status Code: " . $response->getStatusCode() . "\n");
print("Body: " . $response->getBody() . "\n");

SMTPAPI

此库使用 sendgrid/smtpapi-php 处理与 X-SMTPAPI Header 相关的所有内容。

库方法

addTo

您可以使用 addTo 添加一个或多个 TO 地址,并可选地添加 TO 名称。注意:如果使用 TO 名称,每个地址都需要一个名称。

$email = new SendGrid\Email();
$email
    ->addTo('foo@bar.com')
    ->addTo('another@another.com')
;
$sendgrid->send($email);

// With names
$email = new SendGrid\Email();
$email
	->addTo('foo@bar.com', 'Frank Foo')
	->addTo('another@another.com', 'Joe Bar')
;
$sendgrid->send($email);

// As an array
$email = new SendGrid\Email();
$email
    ->addTo(array('foo@bar.com', 'bar@example'), array('Frank Foo', 'Brian Bar'))
;
$sendgrid->send($email);

addSmtpapiTo

将 TO 地址添加到 smtpapi 标头中,并可选地添加名称。

$email = new SendGrid\Email();
$email
    ->addSmtpapiTo('foo@bar.com')
    ->addSmtpapiTo('another@another.com', 'Mike Bar')
;
$sendgrid->send($email);

setTos

如果您愿意,您可以使用 setTos 方法添加多个 TO 地址作为数组。这将取消设置之前附加的任何 addTo

$email = new SendGrid\Email();
$emails = array("foo@bar.com", "another@another.com", "other@other.com");
$email->setTos($emails);
$sendgrid->send($email);

setSmtpapiTos

$email = new SendGrid\Email();
$emails = array("foo@bar.com", "Brian Bar <bar@example.com>", "other@example.com");
$email->setSmtpapiTos($emails);
$sendgrid->send($email);

setFrom

$email = new SendGrid\Email();
$email->setFrom('foo@bar.com');
$sendgrid->send($email);

setFromName

$email = new SendGrid\Email();
$email
    ->setFrom('foo@bar.com')
    ->setFromName('Foo Bar')
;
$sendgrid->send($email);

setReplyTo

$email = new SendGrid\Email();
$email
    ->addTo('foo@bar.com')
    ->setReplyTo('someone.else@example.com')
    ->setFromName('John Doe')
   ...
;

Cc

addCc

$email = new SendGrid\Email();
$email->addCc('foo@bar.com');
$sendgrid->send($email);

setCc

$email = new SendGrid\Email();
$email->setCc('foo@bar.com');
$sendgrid->send($email);

setCcs

$email = new SendGrid\Email();
$emails = array("foo@bar.com", "another@another.com", "other@other.com");
$email->setCcs($emails);
$sendgrid->send($email);

removeCc

$email->removeCc('foo@bar.com');

Bcc

使用多个 addSmtpapiTo 是比 setBcc 更好的替代方案。

$email = new SendGrid\Email();
$email
    ->addSmtpapiTo('foo@bar.com')
    ->addSmtpapiTo('someotheraddress@bar.com')
    ->addSmtpapiTo('another@another.com')
   ...
;

但是,如果您仍然需要 Bcc,您可以这样做:

addBcc

$email = new SendGrid\Email();
$email->addTo('bar@example.com');
$email->addBcc('foo@bar.com');
$sendgrid->send($email);

setBcc

$email = new SendGrid\Email();
$email->setBcc('foo@bar.com');
$sendgrid->send($email);

setBccs

$email = new SendGrid\Email();
$emails = array("foo@bar.com", "another@another.com", "other@other.com");
$email->setBccs($emails);
$sendgrid->send($email);

removeBcc

$email->removeBcc('foo@bar.com');

重要注意:在可能的情况下,建议使用多个 addSmtpapiTo 而不是 bcc。每个用户都会收到带有该设置的个性化电子邮件,并且只能看到自己的电子邮件。

标准的 setBcc 会隐藏电子邮件的收件人。如果您使用多个 addSmtpapiTo's,每个用户都会收到一个个性化的电子邮件,只显示 他们的电子邮件。这更友好,也更个性化。

setSubject

$email = new SendGrid\Email();
$email->setSubject('This is a subject');
$sendgrid->send($email);

setText

$email = new SendGrid\Email();
$email->setText('This is some text');
$sendgrid->send($email);

setHtml

$email = new SendGrid\Email();
$email->setHtml('<h1>This is an html email</h1>');
$sendgrid->send($email);

setDate

$email = new SendGrid\Email();
$email->setDate('Wed, 17 Dec 2014 19:21:16 +0000');
$sendgrid->send($email);

setSendAt

$email = new SendGrid\Email();
$email->setSendAt(1409348513);
$sendgrid->send($email);

setSendEachAt

$email = new SendGrid\Email();
$email->setSendEachAt(array(1409348513, 1409348514, 1409348515));
$sendgrid->send($email);

addSendEachAt

$email = new SendGrid\Email();
$email
    ->addSendEachAt(1409348513)
    ->addSendEachAt(1409348514)
    ->addSendEachAt(1409348515)
;
$sendgrid->send($email);

分类

分类用于对 SendGrid 提供的电子邮件统计信息进行分组。

要使用分类,只需设置分类名称即可。注意:每封电子邮件最多可以有 10 个分类。

addCategory

$email = new SendGrid\Email();
$email
    ->addTo('foo@bar.com')
    ...
    ->addCategory("Category 1")
    ->addCategory("Category 2")
;

setCategory

$email = new SendGrid\Email();
$email
    ->addTo('foo@bar.com')
    ...
    ->setCategory("Category 1")
;

setCategories

$email = new SendGrid\Email();
$categories = array("Category 1", "Category 2", "Category 3");
$email->setCategories($categories);

removeCategory

$email = new SendGrid\Email();
$email
    ->addTo('foo@bar.com')
    ...
    ->removeCategory("Category 1")
;

附件

附件目前仅基于文件,计划未来实现内存中实现。

文件附件的大小限制为每文件 7 MB。

addAttachment

$email = new SendGrid\Email();
$email
    ->addTo('foo@bar.com')
    ...
    ->addAttachment("../path/to/file.txt")
;

设置附件

$email = new SendGrid\Email();
$email
    ->addTo('foo@bar.com')
    ...
    ->setAttachment("../path/to/file.txt")
;

设置附件列表

$email = new SendGrid\Email();
$attachments = array("../path/to/file1.txt", "../path/to/file2.txt");
$email
    ->addTo('foo@bar.com')
    ...
    ->setAttachments($attachments)
;

移除附件

$email = new SendGrid\Email();
$email
    ->addTo('foo@bar.com')
    ...
    ->addAttachment("../path/to/file.txt")
    ->removeAttachment("../path/to/file.txt")
;

您可以标记文件作为内联HTML内容。它将使用指定的"cid"标记文件进行内联处理。

$email = new SendGrid\Email();
$email
    ->addTo('foo@bar.com')
    ->setHtml('<div>Our logo:<img src="cid:file-cid"></div>')
    ->addAttachment("../path/to/file.png", "super_file.png", "file-cid")
;

替换

替换可用于定制多收件人电子邮件,并为用户量身定制。

除非您只向一个收件人发送邮件,否则请确保使用addSmtpapiTo()

添加替换

$email = new SendGrid\Email();
$email
    ->addSmtpapiTo('john@somewhere.com')
    ->addSmtpapiTo('harry@somewhere.com')
    ->addSmtpapiTo('Bob@somewhere.com')
       ...
    ->setHtml("Hey %name%, we've seen that you've been gone for a while")
    ->addSubstitution('%name%', array('John', 'Harry', 'Bob'))
;

替换也可用于定制多收件人主题。

$email = new SendGrid\Email();
$email
    ->addSmtpapiTo(array('john@somewhere.com', 'harry@somewhere.com', 'bob@somewhere.com'))
    ->setSubject('%subject%')
    ->addSubstitution(
        '%subject%',
        array('Subject to John', 'Subject to Harry', 'Subject to Bob')
    )
    ...
;

设置替换

$email = new SendGrid\Email();
$email
    ->addSmtpapiTo(array('john@somewhere.com', 'harry@somewhere.com', 'bob@somewhere.com'))
    ->setSubject('%subject%')
    ->setSubstitutions(array(
        '%name%' => array('John', 'Harry', 'Bob'), 
        '%subject%' => array('Subject to John', 'Subject to Harry', 'Subject to Bob')
    ))
    ...
;

部分

部分可用于进一步定制面向最终用户的消息。部分仅在结合替换值时才有用。

添加部分

$email = new SendGrid\Email();
$email
    ->addSmtpapiTo('john@somewhere.com')
    ->addSmtpapiTo("harry@somewhere.com")
    ->addSmtpapiTo("Bob@somewhere.com")
    ...
    ->setHtml("Hey %name%, you work at %place%")
    ->addSubstitution("%name%", array("John", "Harry", "Bob"))
    ->addSubstitution("%place%", array("%office%", "%office%", "%home%"))
    ->addSection("%office%", "an office")
    ->addSection("%home%", "your house")
;

设置部分

$email = new SendGrid\Email();
$email
    ->addSmtpapiTo('john@somewhere.com')
    ->addSmtpapiTo("harry@somewhere.com")
    ->addSmtpapiTo("Bob@somewhere.com")
    ...
    ->setHtml("Hey %name%, you work at %place%")
    ->addSubstitution("%name%", array("John", "Harry", "Bob"))
    ->addSubstitution("%place%", array("%office%", "%office%", "%home%"))
    ->setSections(array("%office%" => "an office", "%home%" => "your house"))
;

唯一参数

唯一参数用于跟踪目的。

注意:虽然您可以向邮件附加无限数量的唯一参数,但字节数的上限为10,000字节。在将邮件传递给send函数之前,您应该执行以下操作

if (mb_strlen($myEmail->smtpapi->jsonString(), 'UTF-8') > 10000) {
    // throw Exception
}

添加唯一参数 / 添加唯一参数

$email = new SendGrid\Email();
$email
    ->addTo('foo@bar.com')
    ...
    ->addUniqueArg("Customer", "Someone")
    ->addUniqueArg("location", "Somewhere")
;

设置唯一参数 / 设置唯一参数

$email = new SendGrid\Email();
$email
    ->addTo('foo@bar.com')
    ...
    ->setUniqueArgs(array('cow' => 'chicken'))
;

过滤器设置

过滤器设置用于启用和禁用应用程序,并向这些应用程序传递参数。

添加过滤器 / 添加过滤器设置

$email = new SendGrid\Email();
$email
    ->addTo('foo@bar.com')
    ...
    addFilter("gravatar", "enable", 1)
    ->addFilter("footer", "enable", 1)
    ->addFilter("footer", "text/plain", "Here is a plain text footer")
    ->addFilter(
        "footer", 
        "text/html", 
        "<p style='color:red;'>Here is an HTML footer</p>"
    )
;

设置过滤器 / 设置过滤器设置

$email = new SendGrid\Email();
$email
    ->addTo('foo@bar.com')
    ...
    setFilters(array("gravatar" => array("settings" => array("enable" => 1))))
;

模板

您可以通过应用过滤器轻松使用SendGrid的模板引擎

设置模板ID

$email = new SendGrid\Email();
$email
    ->addTo('someone@example.com')
    ->setFrom('support@example.com')
    ->setFromName('Support')
    ->setSubject('Subject goes here')
    // set html or text to an empty space (see http://git.io/hCNy)
    ->setHtml(' ') // <-- triggers the html version of the template
    // AND / OR
    ->setText(' ') // <-- triggers the plaintext version of the template
    ->setTemplateId($templateId);

这是一个方便的方法

$email = new SendGrid\Email();
$email
    ->addFilter('templates', 'enabled', 1)
    ->addFilter('templates', 'template_id', $templateId)
;

高级抑制管理器

ASM用于处理抑制组。

设置ASM组ID

$email = new SendGrid\Email();
$email->setAsmGroupId('my_group_id');

头部

您可以根据需要添加标准电子邮件消息头部。

添加头部

$email = new SendGrid\Email();
$email
    ->addTo('foo@bar.com')
    ...
    ->addHeader('X-Sent-Using', 'SendGrid-API')
    ->addHeader('X-Transport', 'web')
;

设置头部

$email = new SendGrid\Email();
$email
    ->addTo('foo@bar.com')
    ...
    ->setHeaders(array('X-Sent-Using' => 'SendGrid-API', 'X-Transport' => 'web'))
;

移除头部

$email = new SendGrid\Email();
$email
    ->addTo('foo@bar.com')
    ...
    ->addHeader('X-Sent-Using', 'SendGrid-API')
    ->addHeader('X-Transport', 'web')
;
$email->removeHeader('X-Transport');

批量发送数千封电子邮件

有时您可能希望在一次请求中发送数千封电子邮件。您可以这样做。建议您将每个批次分成1000个增量。所以如果您需要向5000封电子邮件发送,那么您应该将其分成每次1000封的循环。

$sendgrid = new SendGrid('YOUR_SENDGRID_APIKEY');
$email = new SendGrid\Email();

$recipients = array(
    "alpha@mailinator.com", 
    "beta@mailinator.com", 
    "zeta@mailinator.com"
);
$names = array("Alpha", "Beta", "Zeta");

$email
    ->setFrom("from@mailinator.com")
    ->setSubject('[sendgrid-php-batch-email]')
    ->setSmtpapiTos($recipients)
    ->addSubstitution("%name%", $names)
    ->setText("Hey %name%, we have an email for you")
    ->setHtml("<h1>Hey %name%, we have an email for you</h1>")
;

$result = $sendgrid->send($email);

贡献

  1. 分支
  2. 创建您的功能分支(git checkout -b my-new-feature
  3. 提交您的更改(git commit -am '添加了一些功能'
  4. 将更改推送到分支(git push origin my-new-feature
  5. 创建新的拉取请求

运行测试

可以使用以下命令使用PHPUnit运行位于test目录中的现有测试

composer update --dev
./vendor/bin/phpunit --bootstrap test/unit/bootstrap.php --filter test* test/unit
```

or if you already have PHPUnit installed globally.

```bash
phpunit --bootstrap test/unit/bootstrap.php --filter test* test/unit
```

## Releasing

To release a new version of this library, update the version in all locations, tag the version, and then push the tag up. Packagist.org takes care of the rest.

1. Confirm tests pass
2. Bump the version in composer.json, lib/Client.php, lib/SendGrid.php, test/unit/SendGridTest.php
3. Update CHANGELOG.md
4. Confirm tests pass
5. Commit Version bump vX.X.X
6. Push changes to GitHub
7. Release tag on GitHub vX.X.X
8. Packagist.org takes care of the rest

#### Testing uploading to Amazon S3

If you want to test uploading the zipped file to Amazon S3 (SendGrid employees only), do the following.

```
export S3_SIGNATURE="secret_signature"
export S3_POLICY="secret_policy"
export S3_BUCKET="sendgrid-open-source"
export S3_ACCESS_KEY="secret_access_key"
./scripts/s3upload.sh
```