I am using PHP version 7.1.9 with mailgun. Right now I am attempting to build the email portion of my code and I am using the following:
function send_email($from, $to, $subject, $body) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, 'api:[api found under domains > sandbox > API Key]');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_URL, '[url found under domains > sandbox > API Base URL]');
curl_setopt($ch, CURLOPT_POSTFIELDS, array(
'from' => $from,
'to' => $to,
'subject' => $subject,
'text' => $body
));
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
Whenever I execute the code the send_email
function it returns the following String via the echo method:
Mailgun Magnificent API
Which to me, signifies that it successfully executed the function, however I never actually receive the email. Why would I get this echoed message, but not the email?
Some background information:
- Currently I am debugging locally via XAMPP v3.2.2 on my local host(127.0.0.1)
- As pointed out in the curl_setopt values, I am using the sandbox domain for testing purposes (I've masked them out in the code for obvious reasons)
- The email that I am sending to is verified in the Authorized Recipients section of the sandbox domain
- The Outgoing column under the sandbox domain confirms that 0 emails have been sent