
[英]Smartsheet - How to attach a file to a row using Smartsheet API and PHP curl
[英]How to attach excel file in Mandrill using php curl
我正在嘗試將Excel文件(.xlsx)添加為通過Mandrill API發送的電子郵件的附件。 我在php文件中使用CURL發送電子郵件。 Excel文件名為Report.xlsx。
這是使用CURL的Mandrill API 的鏈接 。 這是另一個有關添加文件路徑的問題的鏈接 。
我收到以下錯誤消息:
PHP解析錯誤:語法錯誤,/ var / www / html / newFolder / EmailAlertSystem / mailchimp-mandrill-api-php / UsageReport.php中出現意外的“路徑”(T_STRING)
(****這是我的代碼目錄)
這是我的PHP代碼,用於通過Mandrill發送電子郵件:
$uri = 'https://mandrillapp.com/api/1.0/messages/send.json';
$api_key = 'APIKEY';
$content = 'all the content I want to add';
$content_text = strip_tags($content);
$from = 'FROM';
$fromName = 'FROMNAME';
$to = 'TO';
$toName = 'TONAME';
$subject = 'SUBJECT';
$fullName = "FIRSTNAME LASTNAME";
$attachment = file_get_contents('Report.xlsx');
$attachment_encoded = base64_encode($attachment);
$postString = '{
"key": "' . $api_key . '",
"message": {
"html": "' . $content . '",
"text": "' . $content_text . '",
"subject": "' . $subject . '",
"from_email": "' . $from . '",
"from_name": "' . $fromName . '",
"to": [
{
"email": "' . $to . '",
"name": "' . $fullName . '"
}
],
"track_opens": true,
"track_clicks": true,
"auto_text": true,
"url_strip_qs": true,
"preserve_recipients": true,
"attachments" : array(
array(
'path' => $attachment_encoded,
'type' => "application/xlsx",
'name' => 'Report.xlsx',
)
)
},
"async": false
}';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $uri);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postString);
//this is the executable curl statement that will actually send the email
$result = curl_exec($ch);
任何幫助將不勝感激!!! 請讓我知道我是否不清楚以及我在做什么錯。 先感謝您!
錯誤似乎是指這部分
"attachments" : array(
array(
'path' => $attachment_encoded,
'type' => "application/xlsx",
'name' => 'Report.xlsx',
)
)
在此,字符串在path
之前終止,然后重新啟動,這是語法錯誤。
就像是,
"attachments" : array(
array(
\'path\' => $attachment_encoded,
\'type\' => "application/xlsx",
\'name\' => \'Report.xlsx\',
)
)
即轉義引號應該解決它,但是...該字符串的其余部分看起來像JSON。 附件部分應該采用類似PHP的數組格式嗎? 可能要仔細檢查。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.