I am working on CodeIgniter, I am using Mailgun API to send the emails.But I am getting FORBIDDEN while echoing curl_exe() as shown in code:
<?php Class Email3 extends CI_Controller { function __construct() { parent::__construct(); } function index() { $ua = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.13 (KHTML, like Gecko) Chrome/0.A.B.C Safari/525.13'; $ch = curl_init(); curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_setopt($ch, CURLOPT_USERPWD, 'my-api-key'); curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_USERAGENT, $ua); 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' => 'mymail', 'to' => 'othermail', 'subject' => 'The Printer Caught Fire', 'text' => 'We have a problem.')); $result = curl_exec($ch); curl_close($ch); echo $result; } } ?>
I googled it as well searched over SO also but Unable to get solution.Please help me for this. Also email is not been send.