07-11-2016, 04:21 PM
For the life of me I could not get the SMTP from either my host (bluehost.com) or to MailGun's SMTP working. So I ended up modifying the users/helpers/helper.php email function to use phpCurl into MailGun. It took another DBTable (as I did not want to force changes on the email table) but all seems to be working now. I'm sure more testing is needed.
function email($to,$subject,$body){
$db = DB::getInstance();
$query = $db->query("SELECT * FROM MYmailgun");
$results = $query->first();
$config = array();
$config['api_key'] = $results->apikey;
$config['api_url'] = $results->apiurl;
$message = array();
$message['from'] = $results->from_email;
$message['to'] = $to;
$message['h:Reply-To'] = $results->from_email;
$message['subject'] = $subject;
$message['html'] = $body;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $config['api_url']);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, "api:{$config['api_key']}");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS,$message);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
function email($to,$subject,$body){
$db = DB::getInstance();
$query = $db->query("SELECT * FROM MYmailgun");
$results = $query->first();
$config = array();
$config['api_key'] = $results->apikey;
$config['api_url'] = $results->apiurl;
$message = array();
$message['from'] = $results->from_email;
$message['to'] = $to;
$message['h:Reply-To'] = $results->from_email;
$message['subject'] = $subject;
$message['html'] = $body;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $config['api_url']);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, "api:{$config['api_key']}");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS,$message);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}