Send mail with mailgun api by PHP CURL.
<?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 | |
} | |
?> |
This comment has been minimized.
This comment has been minimized.
For me, I got this and don't know why. |
This comment has been minimized.
This comment has been minimized.
You'll get the "Free accounts are for test purposes only" message, until you add a credit card to your account. |
This comment has been minimized.
This comment has been minimized.
please how can i identify the mailgun key |
This comment has been minimized.
This comment has been minimized.
|
This comment has been minimized.
This comment has been minimized.
Thanks for posting! |
This comment has been minimized.
This comment has been minimized.
Great code, thank you for sharing |
This comment has been minimized.
This comment has been minimized.
hi, I've got error : But if remove the string inside array, it works. any help? |
This comment has been minimized.
This comment has been minimized.
great code. but why email go to spam. please help |
This comment has been minimized.
This comment has been minimized.
Thanks. This saved my time |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
Hi Sir, thank you provide the great sample code.
But You have add the
;
on line 31.The variable $mailfromnane has been changed to $mailfromname on line 5.
Thanks.