AZ Fertility: Newsletter Sign Up

Documentation:

HTML:

<!-- Newsletter Sign Up --> <div class="container"> <div class="row"> <div id="newsletter-sign-up"> <div class="col-sm-5"> <h3>Sign Up For Our Newsletter <i class="fa fa-angle-double-right"></i></h3> </div> <div class="col-sm-7"><div id="newsletter-footer-wrapper"><input id="newsletter-footer" type="text" placeholder="Your Email Address"><button onclick="newsletter_signup()" id="newsletter-footer-submit">Submit</button></div></div> </div> </div> </div>

CSS:

/* Newsletter Sign Up */ #newsletter-sign-up { padding: 40px 0 60px 0; border-bottom: 2px solid #e2c367; float: left; width: 100%; margin-bottom: 40px; h3 { margin-top: 10px; } } #newsletter-footer-wrapper { float: left; width: 100%; height: 40px; > * { display: inline-block; } } #newsletter-footer { padding-left: 10px; width: 80%; height: 100%; color: #545453; &::-webkit-input-placeholder { /* Chrome/Opera/Safari */ font-family: $header-font-stack; font-style: italic; } &::-moz-placeholder { /* Firefox 19+ */ font-family: $header-font-stack; font-style: italic; } &:-ms-input-placeholder { /* IE 10+ */ font-family: $header-font-stack; font-style: italic; } &:-moz-placeholder { /* Firefox 18- */ font-family: $header-font-stack; font-style: italic; } } #newsletter-footer-submit { text-transform: uppercase; letter-spacing: 1px; width: 20%; height: 100%; vertical-align: top; border: none; background-color: #c9e0e7; color: #545453; font-weight: 600; } #footer-contact-info { h4 { text-transform: none; } p { font-weight: 500; font-size: 16px; } }

JS:

function newsletter_signup() { var email = jQuery('#newsletter-footer').val(); jQuery.post( ajaxurl, { 'action': 'newsletter_signup_submit', 'email': email, }, function(data){ alert('Thank you! Your newsletter signup was successful.') jQuery('#newsletter-footer').val(''); } ); }

PHP:

// Newsletter Sign Up function newsletter_signup_submit() { // AJAX data $email = $_POST['email']; // Setting up Email $website_name = get_option( 'blogname' ); $admin_email = get_option( 'admin_email' ); $website_url = $_SERVER['SERVER_NAME']; $website_url = str_replace("www.","", $website_url); $from = $website_name . ' <wordpress@' . $website_url . '>'; $message="Newsletter Sign Up:\r\n \r\nE-Mail: " .$email. "\r\n"; mail($admin_email, "Newsletter Sign Up", $message, "From:".$from); wp_die(); } add_action('wp_ajax_nopriv_newsletter_signup_submit', 'newsletter_signup_submit', 999); add_action('wp_ajax_newsletter_signup_submit', 'newsletter_signup_submit', 999);