Help With Notify Me Form
I'm trying to make a simple form like this http://birdboxx.com/, where the user can enter their email address to be notified when our site h开发者_Go百科as launched.
I've looked at the HTML their using and it all looks pretty simple, I'm just not sure on how to code the PHP part. Could someone maybe help me out?
Thanks in advance.
The form in the given example (the relevant parts):
<form name="form-email-submit" id="form-email-submit" action="add_email.php" method="POST">
<input type="text" id="input-email" name="input-email" value="Enter your email here"/>
<input type="submit" title="Notify Me" value="Notify Me">
</form>
In your PHP script:
//In the add_email.php
$notificationEmail = $_POST['input-email']; // from the name="input-email" in the form
So now you have the email submitted, you can do whatever you want with it. You can write it to a file, or save it to a database, or whatever.
Basic solution for the email saving part.
The HTML:
<form method="post" action="">
<input type="email" name="email" placeholder="Enter your email here" /> <input type="submit" name="send" value="Notify me" />
</form>
The PHP with MySQL for saving:
$dbhost = "your host";
$dbuser = "your username";
$dbpass = "your password";
$dbname = "database name";
$c = @mysql_pconnect($dbhost,$dbuser,$dbpass) or die();
@mysql_select_db($dbname,$c) or die();
//It isn't secure in this state: validation needed as it is an email?
if(isset($_POST['send'])){
$email = mysql_real_escape_string($_POST['email']);
mysql_query('INSERT INTO email (id,email) VALUES (NULL,'.$email.');');
}
For sending emails I recommend phpmailer or any other solution: http://phpmailer.worxware.com/
精彩评论