我正在使用mailgun api发送电子邮件。我的php版本是5.3
我必须附加不是multipart / form数据的文件。我的意思是我有绝对的文件路径,所以如何通过Curl php发送附件?
我看到了mailgun文件。我发现了这个:
文件附件。您可以发布多个附件值。重要提示:发送附件时必须使用multipart / form-data编码。
但我只有multipart/form data
的绝对路径。那么我现在该如何附加?
将标题添加为:
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-type: multipart/form-data"));
这是我通过mailgun API发送的输入数组:
阵列( [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 )
)
这是我的卷曲请求
$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);
邮件正在发送到我的邮件收件箱,但我没有收到附件。看着日志也说附件空了