duanqiao2006 2019-06-24 06:40
浏览 96

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.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 MATLAB动图问题
    • ¥15 【提问】基于Invest的水源涵养
    • ¥20 微信网友居然可以通过vx号找到我绑的手机号
    • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
    • ¥15 解riccati方程组
    • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
    • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
    • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
    • ¥50 树莓派安卓APK系统签名
    • ¥65 汇编语言除法溢出问题