I am trying to integrate a ‘subscribe to newsletter’ feature on my wordpress blog
Users just need to enter their name and email address, hit subscribe. This is then supposed to send me an email and I add them to the mailing list.
I activated the WP SMTP Mail plugin and entered in the relevant email server information to enable WordPress to send emails, asked WordPress to send me a test message and this worked.
Now I want to receive an email whenever someone fills in their name & email and hit subscribe.
If I do this at the moment it just does nothing, it re-loads the page without sending an email.
I have attached my code below, can anyone help me out here?
Code for the signup form sidebar.php
– This is not a plugin.
<form action="newsletter_signup.php" method="post">
<p><input class="full" type="text" name="name" placeholder="Your name*"></p>
<p><input class="full" type="email" name="Email" placeholder="Your email address*"></p>
<p><input type="submit" class="sub-btn" value="Subscribe"></p>
</form>
The code in the newsletter_signup.php
file:
<?php
require_once('wp-load.php');
$name = $_POST['name'];
$Email = $_POST['Email'];
$to = 'me@myself.com';
wp_mail($to, $name, 'From: ' . $Email);
echo 'Your request Has Been Sent, Thank You. ';
?>