I have an email input field and a submit button, which when pressed I want a text field to change telling the user that they are subscribed. For some reason the email field is not relaying to the php file what email was typed in. However I know the php is being executed because it just give me an subscription error every time. There was another question like this asked on here but the solution did not work.
I think it is an issue with the use of <form>
and <button>
in combination but I do not know the proper way to execute this, any ideas?
The html:
<html>
<head>
<link rel="stylesheet" href="mystyle.css">
<title>Community Sound</title>
</head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
$.ajax({url: "phEmail.php", success: function(result){
$("#div1").html(result);
}});
});
});
</script>
<body>
<!-- Subscription -->
<div class="container">
<div class="no-result vertical-align-outer">
<div class="vertical-align">
<form method="post" >
<input name="email" class="email glowing-border" type="email" placeholder="Enter your email address ...">
<button type="button" onclick="return getData()" class="emailbtn">Subscribe</button>
</form>
</div>
</div>
</div>
<div id="div1">Not Subscribed</div>
</body>
</head>
PHP:
<?php
$to = "garvernr@mail.uc.edu";
$from = "newsubscription@samplepackgenerator.com";
$headers = "From: " . $from . "
";
$subject = "New subscription";
$body = "New user subscription: " . $_POST['email'];
if( filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) )
{
if (mail($to, $subject, $body, $headers, "-f " . $from))
{
echo 'You have been added to our mailing list!';
}
else
{
echo 'There was a problem with your e-mail (' . $_POST['email'] . ')';
}
}
else
{
echo 'There was a problem with your e-mail (' . $_POST['email'] . ')';
}
?>