-
I'm very new to PHP, but I want to use it to handle a one entry form I have on a site I'm making.
The action for the submit is this to access this php file:
PHP Code:
<?php
$address=$_REQUEST['email'];
$message="Email Address: $address";
$subject="Newsletter Request";
if (isset($_REQUEST['email']))
//if "email" is filled out, send email
{
//send mail
mail ( "myemail@mydomain.com", "Subject: $subject", $message);
echo "Thank you, you will receive our next issue.";
}
else
{
echo "<form type='input' action='newsletter.php' method='post' enctype='text/plain'>Interested in receiving our newletter? Email:<input type='text' name='email' /><input type='submit' value='Submit' /></form>";
?>
Here is my form HTML:
HTML Code:
<form type="input" action="newsletter.php" method="post" enctype="text/plain">
Interested in receiving our newletter? Email:
<input type="text" name="email" />
<input type="submit" value="Submit" />
</form>
Any help would be greatly appreciated, thanks.
Jake
-
I don't see anything immediately wrong with it, although I've also never seen the enctype used for anything other than upload forms (multipart form data).
What's the problem you're having?
-
When I insert the email address and click submit, I just get a white page. That means there's an error right, the server didn't parse it or whatever.
-
It worked for me when I removed the "enctype" ...
else
{
echo "<form type='input' action='newsletter.php' method='post'>Interested in receiving our newletter? Email:<input type='text' name='email' /><input type='submit' value='Submit' /></form>";
}
?>
But once it displays "Thank You", if you refresh the screen, it sends it again,
because isset is isset. It might be better to redirect to another page in order
to get out of that script. Also, this form is wide open for spammers. A little
captcha, or answering a "human only" question might help.
-
Thank you for your help guys. Whether it was the enctype, and or the fact that the else didn't have a closing }, it's fixed now thanks.
As for security what do you recommend? I just want the input of the email is there anything else I can do to keep the same look?
Again, thanks for the help.
Jake
-
D'oh, the } was definitely the problem. Why PHP didn't report a simple parse error, I don't know. Try adding:
PHP Code:
error_reporting(E_ALL);
...to the beginning of the script.
You at least something like a CAPTCHA (read this image and type its contents sort of thing).
-
Jake ...
Keeping it simple with the same look and only the email field?
Not much you can do about spammers. Perhaps it won't be
a problem ... it all depends on how popular the site is, and how
many visits you get.