-
-
Save juque/c8aa97fa8d8401dfbdf9f5188e9ff101 to your computer and use it in GitHub Desktop.
Send mail with mailgun api by PHP CURL.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment