我正在使用以下代码将电子邮件添加到 sendgrid 中的列表。但它返回插入的:0 响应
$request_url = "https://sendgrid.com/api/newsletter/lists/email/add.json";
$data = array("email"=>"testemail@test.com");
$params = array(
'api_user' => $sengrid_user,
'api_key' => $sendgrid_pass,
'list'=>"TestAlwin",
'data' =>json_encode($data)
);
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $request_url);
curl_setopt ($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_VERBOSE, true);
$resp = curl_exec($ch);
curl_close($ch);
这将返回插入的 :0 响应。它应该将 mailid 插入到我指定的列表中。
我使用以下内容作为参考:
curl -d 'api_user=your_sendgrid_username&api_key=your_sendgrid_password&list=my_list&data[]={"email":"address1@domain.com","name":"contactName1"}&data[]={"email":"address2@domain.com","name":"contactName2"}' https://sendgrid.com/api/newsletter/lists/email/add.json
这实际上是在他们的 api 中给出的:
http://sendgrid.com/docs/API_Reference/Marketing_Emails_API/emails.html
我在这里添加 curl vebrose:
* About to connect() to sendgrid.com port 80 (#0)
* Trying 1.1.1.1... * connected
* Connected to sendgrid.com (1.1.1.1) port 80 (#0)
> POST /api/newsletter/lists/email/add.json?list=TestAlwin HTTP/1.1
Host: sendgrid.com
Accept: */*
Content-Length: 395
Expect: 100-continue
Content-Type: multipart/form-data; boundary=----------------------------4435bfc2eb00
< HTTP/1.1 100 Continue
< HTTP/1.1 200 OK
< Server: nginx
< Date: Fri, 13 Sep 2013 07:04:42 GMT
< Content-Type: text/html
< Transfer-Encoding: chunked
< Connection: keep-alive
< Vary: Accept-Encoding
<
* Connection #0 to host sendgrid.com left intact
* Closing connection #0
这些 1.1.1.1 只是我在此处添加的测试 IP,而不是实际 IP。