在过去,我设法用邮筒
附件。但我现在有一个客户要求通过Mailgun发送多个文件作为附件。
我使用附件[1]作为数组并传递它。我遇到的问题是,它没有发送消息,也没有特别为我提供任何错误消息或响应消息。
我正在使用PHP和CURL发送电子邮件。
$curl_post_data = array
(
'from' => $from,
'to' => $recipient,
'subject' => $subject,
'html' => $message
);
// Deal with the file(s)...
$x = 1;
foreach( $files as $file )
{
$curl_post_data = array(
"attachment[$x]" => curl_file_create( @$file['tempname'], $file['filetype'], $file['filename'])
);
$x ++;
}
echo "<pre>";
print_r($curl_post_data);
echo "</pre>";
$service_url = 'https://api.mailgun.net/v3/sendmsg/messages';
$curl = curl_init($service_url);
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($curl, CURLOPT_USERPWD, "api:key-12322222");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: multipart/form-data'));
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $curl_post_data);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$curl_response = curl_exec($curl);
$response = json_decode($curl_response);
curl_close($curl);
var_dump($curl_response);
到达此函数的文件数组如下所示:
array(1) {
[0]=>
array(4) {
["filename"]=>
string(8) "Paul.png"
["filetype"]=>
string(9) "image/png"
["filepath"]=>
string(14) "files/Paul.png"
["tempname"]=>
string(24) "C:\xampp\tmp\php975D.tmp"
}
}
有人能看到什么特别的,可能导致这个不发送的问题吗?
谢谢您