I am using mailgun api to send emails. My php version is 5.3
I have to attach files which is not multipart/form data. I mean I have absolute paths of files, so how can I send attachments through Curl php?
I saw mailgun document. I found this:
File attachment. You can post multiple attachment values. Important: You must use multipart/form-data encoding when sending attachments.
But I have only absolute paths not multipart/form data
. So how can I attach now?
Adding headers as:
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-type: multipart/form-data"));
Here is my input array sending through mailgun API:
Array ( [from] => xyz
[to] => abc@gmail.com [subject] => ryreyreyre [text] => yreyreyreyreyre<br /> <br />Sincerely,<br />xyz [html] => yreyreyreyreyre<br /> <br />Sincerely,<br />xyz [attachment] => Array ( [0] => @/var/www/vhosts/download/attachment/1418034032618discover.png [1] => @/var/www/vhosts/download/attachment/1418034032395master.png [2] => @/var/www/vhosts/download/attachment/1418034032208visa.png )
)
Here is my curl request
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, 'api:'.MAILGUN_APIKEY);
if(!empty($postArr['attachments']))
{
curl_setopt ($ch, CURLOPT_VERBOSE, 0);
curl_setopt ($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-type: multipart/form-data"));
}
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_URL, 'https://api.mailgun.net/v2/'.MAIL_VIA_DOMAIN.'/messages');
curl_setopt($ch, CURLOPT_POSTFIELDS, $postArr);
$http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$result = curl_exec($ch);
curl_close($ch);
mail is being sent to my mail inbox but i am not receiving attachments. looking at the logs also it says attachments empty