Php sendgrid发送多个收据电子邮件
您好,我在sendgrid的发送多回执电子邮件api中遇到问题 实际上api接受这个数组Php sendgrid发送多个收据电子邮件,php,mysql,arrays,email,sendgrid,Php,Mysql,Arrays,Email,Sendgrid,您好,我在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'
<?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_字符串保持为
$json_string = array(
'to' => array(
'email1','email2'
),
'category' => 'test_category'
);
它发送邮件,但问题是我通过mysql从我的数据库中获取电子邮件。我如何将电子邮件直接放入使用循环和
将回迁的电子邮件存储到变量$emailfinallist中,并将该变量传递到$json_字符串数组,但该dosent有效
如何将电子邮件直接放入该数组中看起来您传递的是字符串,而不是“to”参数中的变量:
<?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);
?>
'to'=>数组($emailfinallist”)
应该是
'to'=>$emailfinallist
对于'subject'和'html'参数,您也在做同样的事情