Reputation: 1883
I have been trying to set up a simple form on my website that sends an email to my inbox (not the website visitor's) with email address that the visitor enters into the form. It isn't very complicated, but as I am testing, I can't seem to get any email address to work. I don't get any error message either. I will paste the code below.
At the very least, I'd like to know if there could be a problem with the DNS or host configurations. This is my first time building a website, so I'm unsure if the problem is in the code, the HTML (a separate file not pasted here), or the server or host settings.
To make matters more difficult, I have once gotten an error message along the lines of something not configured properly, but I can't seem to get the error message anymore. I don't think I changed any code. That makes me suspect there may be something else going on server-side. Is that feasible?
Thanks in advance for taking a peek.
<?php
$to = "[email protected]";
$from = "[email protected]";
$headers = "From: " . $from . "\r\n";
$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 will be notified on <b> ' . $_POST['email'] . '</b> :)';
}
else
{
echo 'There was a problem with your e-mail (' . $_POST['email'] . ')';
}
}
else
{
echo 'There was a problem with your e-mail (' . $_POST['email'] . ')';
}
As far as the index.html is concerned, I have a single form next to a Send button. The form presumably takes the user information, filters nonsense out, and then the Send button calls the PHP script. Please find the relevant index.html code below:
<!-- SIGN UP SECTION ############################################### -->
<section id="signup">
<div class="row">
<!-- Title -->
<div class="seven columns centered">
<h2>Sign up to receive our newsletter!</h2>
<!-- Begin the Form -->
<form action="form_sender.php" method="post">
<!-- Input of E-Mail -->
<div class="eight columns">
<input name="email" class="email" type="text" placeholder="YOUR E-MAIL PLEASE ?">
</div>
<!-- Send Button -->
<div class="four columns">
<button name="send" type="submit" class="submit">SEND</button>
</div>
<!-- End of the Form -->
</form>
</div>
<!-- Text Promise we do not spam -->
<div class="twelve columns centered">
<p class="spam">We do not spam.</p>
</div>
</div>
</section>
Upvotes: 2
Views: 1814
Reputation: 2275
If you are getting your $_POST variables right, which you can check using "echo", i dont think there is any bug in your code i tried your code without the &_POST vars an it worked fine.
I presume you are using wamp or xampp and testing this on your local system. Upload the code on webserver and everything will be fine.
Upvotes: 1