我正在使用SendGrid進行卷曲方法的客戶項目。SendGrid - 捲曲php外部文件附件損壞
所有工作正常,但我的電子郵件與SendGrid發送附加(ir)文件(s)被打破。
這裏是我的代碼:
$documentList = array(
"DOC1.php" => "http://www.customerdomain.com/my/path/where/my/attachment/file/is/myfile.pdf"
);
$params = array(
'api_user' => $user;
'api_key' => $pass,
'x-smtpapi' => json_encode($json_string),
'from' => $from,
'to' => $to,
'subject' => $subject,
'html' => $mailHtml,
'text' => $mailText
);
if(count($documentList)>0){
foreach($documentList as $fileName=>$documentPath){
$params['files['.$fileName.']'] = $documentPath;
}
}
$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);
當我沒有在我的陣列的關鍵擴展文件,我已經包含了相關值的文本文件。
我覺得我並不孤單有這個問題,好吧,如果你有任何想法解決這個問題,謝謝你的幫助!
'curl_file_create' working for me – Shahbaz 2016-11-06 19:19:14