问题描述
我正在使用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','[email protected]');
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'=>'[email protected]',
'to'=&$ $ email,
'subject'=>'请确认您订阅我们',
'html'=>您好{$ name}< br>< br>您已经注册到我们的邮件列表。请在下面确认
);
$ mailgun-> post('lists /'。MAILING_LIST。'/ members',[
'name'=> $ name,
'address'=> ; $ email,
'subscribed'=>'no'
]);
header('Location:http:// localhost:8888 / exam / index.php');
}
}
?>
您正在使用 sandboxc03eaee7674c4a9094ffa8d61845ddf5。 mailgun.org
发送电子邮件的沙箱子域名。
您应该会收到以下错误:
错误:Sandbox子域仅用于测试目的。请添加您自己的域名或在帐户设置中将地址添加到授权收件人。
要发送多个电子邮件,您必须创建自己的域第一。
您可以从创建域
确保您的域名已被验证。如果您的域名未经验证,那么您将收到以下错误:
错误:域名未经验证,需要DNS配置。登录到控制面板查看所需的DNS记录。
I'm making email subscription form with PHP and Mailgun API, but I only get email to my main email address which I used for account creation at mailgun.com. When I fill the form with that email, I get the confirmation letter, but it doesn't work with other emails. Why is so? This is the code:
Init file:
<?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', '[email protected]');
define('MAILGUN_SECRET', '...');
$mailgun = new Mailgun\Mailgun(MAILGUN_KEY);
$mailgunValidate = new Mailgun\Mailgun(MAILGUN_PUBKEY);
$mailgunOptIn = $mailgun->OptInHandler();
?>
Main index.php file:
<?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' => '[email protected]',
'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');
}
}
?>
You are using sandboxc03eaee7674c4a9094ffa8d61845ddf5.mailgun.org
Sandbox subdomain for sending an email.
You should get an error like:
Error: Sandbox subdomains are for test purposes only. Please add your own domain or add the address to authorized recipients in Account Settings.
To send multiple emails, you have to create your own domain first.You can create domain from here
Make sure your domain is verified.If your domain is unverified then you will get an error like:
Error: The domain is unverified and requires DNS configuration. Log in to your control panel to view required DNS records.
这篇关于Mailgun API只能使用一个电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!