Send email using mailgun API without library


Apr 14, 2019

Mailgun is good service provider which is allows you to send bulk emails via Mailgun API. Mailgun assembled a MIME message. In short, SMTP is an open and established protocol with large ecosystem, while Mailgun API is better long term performance and maintenance wise. Mailgun service is an Email automation service. Inbuilt functions for sending, tracking or receiving emails.


  $ch = curl_init();
  curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
  curl_setopt($ch, CURLOPT_USERPWD, 'YOUR-API-KEY');
  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' => 'Significant Techno <test@example.com>',
                      'to' => 'User Name <user@example.com>',
                      'subject' => 'Hello',
                      'text' => 'Testing some Mailgun awesomeness!'));
  $result = curl_exec($ch);
  curl_close($ch);
  return $result;



Copyright 2018. All rights are reserved