我试图建立为每次电子邮件独特的参数列表中,SMTP API的官方参考描述了这个功能相当简单,在这里.
我正在使用的SendGrid PHP库的API文档也没有多大帮助:
/**
* setUniqueArguments
* Set a list of unique arguments, to be used for tracking purposes
* @param array $key_value_pairs - list of unique arguments
*/
public function setUniqueArguments(array $key_value_pairs)
{
$this->header_list['unique_args'] = $key_value_pairs;
return $this;
}
/**
* addUniqueArgument
* Set a key/value pair of unique arguments, to be used for tracking purposes
* @param string $key - key
* @param string $value - value
*/
public function addUniqueArgument($key, $value)
{
$this->header_list['unique_args'][$key] = …Run Code Online (Sandbox Code Playgroud) 我在 Laravel 中集成了 sendgrid 并且我设法在电子邮件中发送了 sendgrid 的电子邮件模板,但我无法替换电子邮件模板中的内容。我正在使用 Sendgrid Web API V3。
我按照下面链接中给出的步骤操作,但它没有用我的动态数据替换模板中的变量。
链接:如何将动态数据传递到在 sendgrid webapp 上设计的电子邮件模板?:-| 发送网格
这是代码
$sg = new \SendGrid('API_KEY');
$request_body = json_decode('{
"personalizations":[
{
"to":[
{
"email":"example@example.com"
}
],
"subject":"Hello World from the SendGrid PHP Library!"
}
],
"from":{
"email":"from@example.com"
},
"content":[
{
"type":"text/html",
"value":"<html><body> -name- </body></html>"
}
],
"sub": {
"-name-": ["Alice"]
},
"template_id":"xxxxxx-xxx-xxxxxxxx"
}');
$mailresponse = $sg->client->mail()->send()->post($request_body);
echo $mailresponse->statusCode();
echo $mailresponse->body();
echo $mailresponse->headers();
Run Code Online (Sandbox Code Playgroud)
请帮忙。