Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save fernandovega/f7e435a01bbe9f40fc32a269c76bd272 to your computer and use it in GitHub Desktop.
Save fernandovega/f7e435a01bbe9f40fc32a269c76bd272 to your computer and use it in GitHub Desktop.
function mg_send($to, $subject, $message) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, 'api:'.MAILGUN_API);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$plain = strip_tags(br2nl($message));
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_URL, 'https://api.mailgun.net/v2/'.DOMAIN.'/messages');
curl_setopt($ch, CURLOPT_POSTFIELDS, array('from' => 'support@'.DOMAIN,
'to' => $to,
'subject' => $subject,
'html' => $message,
'text' => $plain));
$j = json_decode(curl_exec($ch));
$info = curl_getinfo($ch);
if($info['http_code'] != 200)
error("Fel 313: Vänligen meddela detta via E-post till support@".DOMAIN);
curl_close($ch);
return $j;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment