<?php
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'https://api.mailgun.net/v3/filebot.net/messages');
curl_setopt($curl, CURLOPT_RESOLVE, ['api.mailgun.net:443:34.149.236.64']);
curl_setopt($curl, CURLOPT_TIMEOUT, 10);
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($curl, CURLOPT_USERPWD, $key);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, [
'from' => $from,
'to' => $to,
'subject' => $subject,
'text' => $text,
'attachment' => new CURLStringFile($attachment, $filename)
]);
$response = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if ($status != 200) {
error_log('[MAILGUN] '.$status.' '.(curl_errno($curl) ? curl_error($curl) : $response));
}
curl_close($curl);
?>
Comments