I am trying to add an excel file (.xlsx) as an attachment to the email I am sending out through the Mandrill API. I am using CURL in a php file to send the email. The excel file is named Report.xlsx.
Here is a link to Mandrill API to use CURL. Here is a link an other question going over adding file paths.
I receive the following error message:
PHP Parse error: syntax error, unexpected 'path' (T_STRING) in /var/www/html/newFolder/EmailAlertSystem/mailchimp-mandrill-api-php/UsageReport.php
(****Which is my directory of my code)
This is my php code to send out the email via 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);
Any help would be greatly appreciated!!! Please let me know if I was unclear and what I am doing wrong. Thank you in advance!