Skip to content

Instantly share code, notes, and snippets.

@ShuvoHabib
Last active August 6, 2017 05:21
Show Gist options
  • Save ShuvoHabib/f0ec6a0233bc9ec7b3fa916bfaa5323f to your computer and use it in GitHub Desktop.
Save ShuvoHabib/f0ec6a0233bc9ec7b3fa916bfaa5323f to your computer and use it in GitHub Desktop.
MailGun Subscription
var mailgunURL;
mailgunURL = window.location.protocol + "//" + window.location.hostname + '/ajax/mailgun.php';
$('#mailgun').on('submit', function (e) {
$(this).attr("disabled", true);
var dataString = $(".newsletter-content form").serialize()
$.ajax({
type: 'POST',
url: "subscribeform.php",
data: dataString,
success: function () {
$('.newsletter-content').html("<div id='message'></div>");
$('#message').html("<h2 style='color: white; margin-top: 20px;'>Congratulations, You're Subscribed!</h2>")
.append("<p style='color: white'>We will be in touch soon.</p>");
$('.newsletter-content form').hide();
},
error: function (data) {
console.log('Silent failure.');
}
});
return false;
});
<?php
require 'vendor/autoload.php';
use Mailgun\Mailgun;
# Instantiate the client.
$mgClient = new Mailgun('key-***');
$listAddress = 'users@email.xyz';
# Issue the call to the client.
$result = $mgClient->post("lists/$listAddress/members", array(
'address' => $_POST['email'],
'subscribed' => true,
));
?>
<form class="form-subscribe" id="mailgun" role="form" method="POST">
<div class="form-group">
<!--<input type="email" name="email" class="form-control" placeholder="Enter your email" required />-->
<input type="email" class="form-control" id="email" name="email"
placeholder="Enter your email" required>
<button type="submit" class="btn btn-blue mail-submit">Subscribe</button>
</div>
<div class="msg"></div>
</form> <!-- form-subscribe -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment