2015-04-04 99 views
1

打招呼sendgrid的所有我有问题发送多个收到电子邮件API问题 实际上是API接受这个数组sendgrid发送多个回执电子邮件

<?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<[email protected]>", 
); 


    $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' 
); 

它发送,但有问题m是我通过mysql从我的数据库中获取电子邮件如何将电子邮件直接放入数组中,我正在使用循环和 将获取的电子邮件存储到$ emailfinallist变量中,并将此变量传递给$ json_string数组,但那dosent工程....

怎么做我把邮件直接进入此阵

回答

2

它看起来像你传递一个字符串,而不是在“到” PARAM变量:

'to' => array("$emailfinallist") 应该是 'to' => $emailfinallist

你也在为'主题'和'html'参数做同样的事情。

相关问题