Mailgun API 仅适用于一封电子邮件
Mailgun API works only with one email
我正在使用 PHP 和 Mailgun API 制作电子邮件订阅表格,但我只收到我在 mailgun.com 用于创建帐户的主要电子邮件地址的电子邮件。当我用该电子邮件填写表格时,我会收到确认信,但它不适用于其他电子邮件。为什么会这样?这是代码:
初始化文件:
<?php
require_once 'vendor/autoload.php';
define('MAILGUN_KEY', 'key-2ce40f5e23c90b0d666f3e....');
define('MAILGUN_PUBKEY', 'pubkey-8cf7125996....');
define('MAILGUN_DOMAIN', 'sandboxc03eaee7674c4a9094ffa8d61845ddf5.mailgun.org');
define('MAILING_LIST', 'audimas@sandboxc03eaee7674c4a9094ffa8d61845ddf5.mailgun.org');
define('MAILGUN_SECRET', '...');
$mailgun = new Mailgun\Mailgun(MAILGUN_KEY);
$mailgunValidate = new Mailgun\Mailgun(MAILGUN_PUBKEY);
$mailgunOptIn = $mailgun->OptInHandler();
?>
主 index.php 文件:
<?php
require_once 'init.php';
if(isset($_POST['name'], $_POST['email']))
{
$name = $_POST['name'];
$email = $_POST['email'];
$validate = $mailgunValidate->get('address/validate', [
'address' => $email
])->http_response_body;
if($validate->is_valid)
{
$hash = $mailgunOptIn->generateHash(MAILING_LIST, MAILGUN_SECRET, $email);
$mailgun->sendMessage(MAILGUN_DOMAIN, [
'from' => 'noreply@audimas.com',
'to' => $email,
'subject' => 'Please confirm your subscription to us',
'html' => "Hello {$name}<br><br>You signed up to our mailing list. Please confirm below"
]);
$mailgun->post('lists/' . MAILING_LIST . '/members', [
'name' => $name,
'address' => $email,
'subscribed' => 'no'
]);
header('Location: http://localhost:8888/exam/index.php');
}
}
?>
您正在使用 sandboxc03eaee7674c4a9094ffa8d61845ddf5.mailgun.org
沙盒子域发送电子邮件。
您应该会收到如下错误:
Error: Sandbox subdomains are for test purposes only. Please add your own domain or add the address to authorized recipients in Account Settings.
要发送多封电子邮件,您必须先创建自己的域。
您可以从 here
创建域
确保您的域是 verified.If 您的域未经验证然后您将收到如下错误:
Error: The domain is unverified and requires DNS configuration. Log in to your control panel to view required DNS records.
我正在使用 PHP 和 Mailgun API 制作电子邮件订阅表格,但我只收到我在 mailgun.com 用于创建帐户的主要电子邮件地址的电子邮件。当我用该电子邮件填写表格时,我会收到确认信,但它不适用于其他电子邮件。为什么会这样?这是代码:
初始化文件:
<?php
require_once 'vendor/autoload.php';
define('MAILGUN_KEY', 'key-2ce40f5e23c90b0d666f3e....');
define('MAILGUN_PUBKEY', 'pubkey-8cf7125996....');
define('MAILGUN_DOMAIN', 'sandboxc03eaee7674c4a9094ffa8d61845ddf5.mailgun.org');
define('MAILING_LIST', 'audimas@sandboxc03eaee7674c4a9094ffa8d61845ddf5.mailgun.org');
define('MAILGUN_SECRET', '...');
$mailgun = new Mailgun\Mailgun(MAILGUN_KEY);
$mailgunValidate = new Mailgun\Mailgun(MAILGUN_PUBKEY);
$mailgunOptIn = $mailgun->OptInHandler();
?>
主 index.php 文件:
<?php
require_once 'init.php';
if(isset($_POST['name'], $_POST['email']))
{
$name = $_POST['name'];
$email = $_POST['email'];
$validate = $mailgunValidate->get('address/validate', [
'address' => $email
])->http_response_body;
if($validate->is_valid)
{
$hash = $mailgunOptIn->generateHash(MAILING_LIST, MAILGUN_SECRET, $email);
$mailgun->sendMessage(MAILGUN_DOMAIN, [
'from' => 'noreply@audimas.com',
'to' => $email,
'subject' => 'Please confirm your subscription to us',
'html' => "Hello {$name}<br><br>You signed up to our mailing list. Please confirm below"
]);
$mailgun->post('lists/' . MAILING_LIST . '/members', [
'name' => $name,
'address' => $email,
'subscribed' => 'no'
]);
header('Location: http://localhost:8888/exam/index.php');
}
}
?>
您正在使用 sandboxc03eaee7674c4a9094ffa8d61845ddf5.mailgun.org
沙盒子域发送电子邮件。
您应该会收到如下错误:
Error: Sandbox subdomains are for test purposes only. Please add your own domain or add the address to authorized recipients in Account Settings.
要发送多封电子邮件,您必须先创建自己的域。 您可以从 here
创建域确保您的域是 verified.If 您的域未经验证然后您将收到如下错误:
Error: The domain is unverified and requires DNS configuration. Log in to your control panel to view required DNS records.