Skip to content

Instantly share code, notes, and snippets.

@slav123
Created March 11, 2016 10:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save slav123/197bee1c04be83f0f764 to your computer and use it in GitHub Desktop.
Save slav123/197bee1c04be83f0f764 to your computer and use it in GitHub Desktop.
send mail via mailgun no external libraries
<?php
function send_simple_message() {
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, 'api:key-example');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_URL,
'https://api.mailgun.net/v2/samples.mailgun.org/messages');
curl_setopt($ch, CURLOPT_POSTFIELDS,
array('from' => 'Dwight Schrute <dwight@example.com>',
'to' => 'Michael Scott <michael@example.com>',
'subject' => 'The Printer Caught Fire',
'text' => 'We have a problem.'));
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
echo send_simple_message();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment