Skip to content

Instantly share code, notes, and snippets.

@aorborc
Forked from YugalXD/function.php
Created December 4, 2019 07:00
Show Gist options
  • Select an option

  • Save aorborc/af23de70cceec7531e36c34d989941f0 to your computer and use it in GitHub Desktop.

Select an option

Save aorborc/af23de70cceec7531e36c34d989941f0 to your computer and use it in GitHub Desktop.

Revisions

  1. @YugalXD YugalXD created this gist Apr 26, 2016.
    35 changes: 35 additions & 0 deletions function.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,35 @@
    <?php
    define('MAILGUN_URL', 'https://api.mailgun.net/v3/DOMAIN_NAME');
    define('MAILGUN_KEY', 'KEY');

    function sendmailbymailgun($to,$toname,$mailfromnane,$mailfrom,$subject,$html,$text,$tag,$replyto){
    $array_data = array(
    'from'=> $mailfromname .'<'.$mailfrom.'>',
    'to'=>$toname.'<'.$to.'>',
    'subject'=>$subject,
    'html'=>$html,
    'text'=>$text,
    'o:tracking'=>'yes',
    'o:tracking-clicks'=>'yes',
    'o:tracking-opens'=>'yes',
    'o:tag'=>$tag,
    'h:Reply-To'=>$replyto
    );

    $session = curl_init(MAILGUN_URL.'/messages');
    curl_setopt($session, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
    curl_setopt($session, CURLOPT_USERPWD, 'api:'.MAILGUN_KEY);
    curl_setopt($session, CURLOPT_POST, true);
    curl_setopt($session, CURLOPT_POSTFIELDS, $array_data);
    curl_setopt($session, CURLOPT_HEADER, false);
    curl_setopt($session, CURLOPT_ENCODING, 'UTF-8');
    curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($session, CURLOPT_SSL_VERIFYPEER, false);
    $response = curl_exec($session);
    curl_close($session);
    $results = json_decode($response, true);
    return $results
    }


    ?>