我在sendgrid邮件平台中找到了此选项,用于将多个电子邮件ID添加到列表中。就像是 :
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
Run Code Online (Sandbox Code Playgroud)
现在如何将其与PHP curl一起使用?
我在添加数据字段并在某处读取-d是POST的开关时有疑问。但是对于sendgrid来说,几乎所有的api请求都可以获取。
-d switch自动使用POST方法,因此,如果curl命令起作用,则可以使用POST。要设置发布数据,您可以执行以下操作:
curl_setopt($ch, CURLOPT_POSTFIELDS, 'api_user=your_sendgrid_username&...');
Run Code Online (Sandbox Code Playgroud)
或具有自动urlencoding,请使用数组
curl_setopt($ch, CURLOPT_POSTFIELDS, array('api_user' => 'your_sendgrid_username' ...));
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5711 次 |
| 最近记录: |