php-使用Swiftmailer将唯一参数传递给SendGrid
作者:互联网
嗨,我正在使用php mailer Swiftmailer使用SMTP API通过SendGrid发送.我们可以将唯一的参数传递给SendGrid以帮助跟踪电子邮件.我已成功通过Swiftmailer传递了唯一的标头:
$headers = $message->getHeaders();
$headers->addTextHeader('AccountId', $accountId);
这些值已成功注入到已发送电子邮件的标头中,但它们并未被SendGrid传递回我的事件webhook或控制面板中.
我也尝试了一下,但是也没有用:
$headers = $message->getHeaders();
$args = ' {
"customerAccountNumber": "55555",
"activationAttempt": "1",
"New Argument 1": "New Value 1",
"New Argument 2": "New Value 2",
"New Argument 3": "New Value 3",
"New Argument 4": "New Value 4"
}';
$headers->addTextHeader('unique_args', $args);
这可能是SendGrid支持的一个问题,但是由于它与Swiftmailer有关,所以我想我会首先在这里尝试.谢谢!
解决方法:
SendGrid expects a JSON key/value structure in the X-SMTPAPI
header entry.
我有一个使用SwiftMailer 5.0.3的旧项目.这是我将类别值发送到SendGrid的方式:
$message->getHeaders()->addTextHeader('X-SMTPAPI', json_encode(array(
'category' => $category,
)));
将该模式应用于您的示例:
$headers = $message->getHeaders();
$args = array(
'unique_args' => array(
'AccountId' => $accountId,
"customerAccountNumber" => "55555",
"activationAttempt" => "1",
"New Argument 1" => "New Value 1",
"New Argument 2" => "New Value 2",
"New Argument 3" => "New Value 3",
"New Argument 4" => "New Value 4",
),
);
$headers->addTextHeader('X-SMTPAPI', json_encode($args));
标签:sendgrid,php,swiftmailer 来源: https://codeday.me/bug/20191026/1934764.html