sendgrid发送多个收据电子邮件

时间:2015-04-04 11:55:37

标签: 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'        => "$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数组,但该函数有效....

如何将电子邮件直接放入此数组

1 个答案:

答案 0 :(得分:2)

看起来你传递了一个字符串,而不是&#39;中的一个变量。 PARAM:

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

你也为“主题”做了同样的事情。和&#39; html&#39; PARAMS。