MailGun测试邮件不会发送

Simply trying to send an email via MailGun's API. I gave up trying to install composer so instead I'm trying to do it via curl converted to PHP.

The email doesn't get sent and $results is null.

Ubuntu 18.04

Tried composer (tons of errors while installing), tried curl by itself (gives back 'Forbidden' message), and finally tried curl converted to PHP

<?php

define('MAILGUN_URL', 'https://api.mailgun.net/v3/sandbox123452358093MYMAILGUNSANDBOXDOMAIN.mailgun.org');
define('MAILGUN_KEY', '<MYMAILGUNAPIKEY>'); 

$array_data = array(
    'from'=> 'Ted' .'<'.'ted@hello.com'.'>',
    'to'=>'Bob'.'<'.'myemail@gmail.com'.'>',
    'subject'=>'Subject',
    'html'=>'HTML',
    'text'=>'Text',
    'o:tracking'=>'yes',
    'o:tracking-clicks'=>'yes',
    'o:tracking-opens'=>'yes',
    'o:tag'=>'tag',
    'h:Reply-To'=>'myemail@gmail.com'
);
$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);

echo "results: ";
var_dump($results);

Expecting it to simply send an email to myself. Email does not send/not received and $results dumped is NULL.

douyu1656
douyu1656 如果您使用普通卷曲从Mailgun收到错误,则可能表明您的帐户/密钥详细信息有问题,并且您将在PHP中遇到同样的问题。如果您在PHP中遇到curl问题,请使用curl_getinfo()进行调试。保持简单,直到你有工作-摆脱所有跟踪的东西,官方卷曲的例子表明你只需要一个来自,一个和一个主题。
一年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问