2014-12-05 76 views
0

Sendgrid X-smtpapi錯誤,我已經設置了以下內容:與「失蹤目的地電子郵件」

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(
    '[email protected]','[email protected]','[email protected]' 
), 
    'category' => 'Test' 
); 

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

$params = array(
    'api_user' => $user, 
    'api_key' => $pass, 
    'x-smtpapi' => json_encode($to_emails), 
    //'to' => '[email protected]', 
    'subject' => 'Test email', 
    'html'  => '<p>Testing sendgrid mail</p>', 
    'text'  => 'sent', 
    'from'  => '[email protected]', 
    '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陣列和輸出「失蹤目的地它會輸出我傳入的電子郵件數組,但它仍然在尋找數組中的「to」值 - 我想知道爲什麼以及如何解決?我一直在關注Sendgrid文檔正如我所見 - https://sendgrid.com/docs/Code_Examples/php.html

如果我取消註釋'到'行它發送電子郵件到[email protected]就好了

回答

5

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

你鏈接到表演都tox-smtpapi參數存在並指出

的例子...電子郵件將外出都[email protected][email protected]。正常地址[email protected]不會收到電子郵件。

+2

感謝您的回答。這是我在我提供的鏈接上閱讀的內容,也是根據我的問題進行了嘗試。問題是,當我設置'to'和'x-smtpapi'時,它只會將它發送到'to'電子郵件地址,而不是發送給我想要發送給它的電子郵件數組。文檔說'to'被忽略,但實際上'x-smtpapi'是。 – TFK300 2014-12-05 14:07:29

+1

你能否用你的其他代碼更新你的問題? – eddiezane 2014-12-05 14:12:56