大家好,我在 sendgrid 的发送多个收据电子邮件 api 问题中遇到问题 实际上 api 接受这个数组
<?php
$url = 'https://api.sendgrid.com/';
$user = 'abc';
$pass = 'xyx';
$params = array(
'api_user' => $user,
'api_key' => $pass,
'x-smtpapi' => json_encode($json_string),
'to' => "$to",
'subject' => "$subject",
'html' => "$messaget",
'from' => "site.com<contact@site.com>",
);
$request = $url.'api/mail.send.json';
// Generate curl request
$session = curl_init($request);
// Tell curl to use HTTP POST
curl_setopt ($session, CURLOPT_POST, true);
// Tell curl that this is the body of the POST
curl_setopt ($session, CURLOPT_POSTFIELDS, $params);
// Tell curl not to return headers, but do return the response
curl_setopt($session, CURLOPT_HEADER, false);
// Tell PHP not to use SSLv3 (instead opting for TLS)
curl_setopt($session, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
// obtain response
$response = curl_exec($session);
curl_close($session);
?>
问题就在这里
$json_string = array(
'to' => array(
"$emailfinallist"
),
'category' => 'test_category'
);
当我保留 json_string 时
$json_string = array(
'to' => array(
'email1','email2'
),
'category' => 'test_category'
);
它发送但问题是我正在通过 mysql 从我的数据库中获取电子邮件我如何将电子邮件直接放入数组我正在使用循环和 将获取的电子邮件存储到变量 $emailfinallist 中,并将该变量传递给 $json_string 数组,但 dosent 有效....
如何将电子邮件直接放入此数组
最佳答案
看起来您传递的是字符串,而不是“to”参数中的变量:
'to' => array("$emailfinallist")
应该
'to' => $emailfinallist
您也在为“主题”和“html”参数做同样的事情。
关于php - sendgrid 发送多个收据电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29446105/