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', 'audimas@sandboxc03eaee7674c4a9094ffa8d61845ddf5.mailgun.org');
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' => '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');
}
}
?>