If you're interested, here's my code that sends to mailgun
It assumes some existing variables (like $subject and $message) and constants like MAILGUN_API_Key and MAILGUN_Base_URL that I set elsewhere, plus it is set up to accepts attachemets as well but you can leave that out.
$mail_array = array('from' => 'someone@mysite.com,
'to' => array("to"=> 'someone@somewhere.com',"bcc"=>"someoneelse@somewhere.com"),
'subject' => $subject,
//'text' => 'plain text message';
'html' => '<html>'.$message.'</html>');
if (count($attachments) > 0) {
$i = 1;
foreach ($attachments as $attachment) {
$mail_array['attachment[' . $i . ']'] = curl_file_create($attachment);
$i++;
}
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, 'api:'.MAILGUN_API_Key);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_URL, rtrim(MAILGUN_Base_URL,"/").'/messages');
curl_setopt($ch, CURLOPT_ENCODING, 'multipart/form-data');
curl_setopt($ch, CURLOPT_POSTFIELDS, $mail_array);
$result = json_decode(curl_exec($ch));
curl_close($ch);