簡體   English   中英

Sendgrid x-smtpapi錯誤,“缺少目標電子郵件”

[英]Sendgrid x-smtpapi errors with 'missing destination email'

我設置了以下內容:

error_reporting(E_ALL | E_NOTICE);
ini_set('display_errors', '1');

$file = date('YmdHis');
$fp = fopen('/var/www/mydir/files/'.$file.'.csv', 'w');

$url = 'http://sendgrid.com/';
$user = 'myuser';
$pass = 'mypass';
$to_emails = array(
  'to' => array(
    '1@example.com','2@example.com','3@example.com'
  ),
  'category' => 'Test'
);

$fileName = $file;
$filePath = dirname(__FILE__);

$params = array(
    'api_user'  => $user,
    'api_key'   => $pass,
    'x-smtpapi' => json_encode($to_emails),
    //'to' => 'example@example.com',
    'subject'   => 'Test email',
    'html'      => '<p>Testing sendgrid mail</p>',
    'text'      => 'sent',
    'from'      => 'me@example.com',
    'files['.$file.'.csv]' => '@'.$filePath.'/files/'.$fileName.'.csv'
  );

print_r($params);

$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);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);

// obtain response
$response = curl_exec($session);
curl_close($session);

print_r($response);

//unlink('./files/'.$file.'.csv');

mysql_close($connect);

問題是它不會發送到$to_emails數組中的收件人並輸出“缺少目標電子郵件”。它確實輸出了我傳遞的電子郵件的數組,但仍在數組中尋找“收件人”值-我不知道為什么,我該怎么解決,我跟着Sendgrid文檔密切,據我可以看到- ? https://sendgrid.com/docs/Code_Examples/php.html

如果我取消注釋“收件人”行,它將電子郵件發送到example@example.com就好了。

即使始終使用SMTPAPI to當前始終也需要to參數。 我們建議將其設置為from地址。 如果存在SMTPAPI to ,則該API將忽略常規to參數。

你鏈接到同時顯示了例子tox-smtpapi參數和目前的狀態

...電子郵件將同時發送到example1@sendgrid.com和example2@sendgrid.com。 普通用戶example3@sendgrid.com將不會收到電子郵件。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM