【问题标题】:sendgrid send multiple receipts emailsendgrid 发送多个收据电子邮件
【发布时间】:2015-06-09 08:45:43
【问题描述】:

大家好,我在 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 数组,但该变量有效....

我如何将电子邮件直接放入这个数组中

【问题讨论】:

    标签: php mysql arrays email sendgrid


    【解决方案1】:

    看起来您传递的是字符串,而不是“to”参数中的变量:

    'to' =&gt; array("$emailfinallist") 应该 'to' =&gt; $emailfinallist

    您也在为“主题”和“html”参数做同样的事情。

    【讨论】:

      猜你喜欢
      • 2018-08-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多