View Full Version : Collect Email addresses from Visitors
Potter_gold
04-21-2007, 10:56 PM
Hi
Can i start by saying i am a novice. I have built a website which gets over 35k visitors a month (http://www.freepspwallpapers.co.uk) I want to try and gather as many email addresses from the visitors as possible - however, one slight snag....... I do not know where to start.
I understand i need to build a form, and i believe i can add something to my mysql database to capture the details, but have no idea on how to do this?
Is there anywhere that i can get a step by step guide to help me do this?
Many thanks in advance.
Peter Potter
GO ILLINI
04-22-2007, 01:02 AM
In the "action" of the form, you will want to send it to a php page where the mysql will be done. http://www.tizag.com/mysqlTutorial/mysqlinsert.php is a great place for beginners. You will end up with something like
mysql_query("INSERT INTO table (email) VALUES($_GET['email']) ") or die(mysql_error());
That will make a new line in a table with just the 'email' field filled in.
-Adam
Beams
04-22-2007, 06:14 AM
A quick solution whipped up between assignments:
<?php
include("connection.php");
//Page with your mysql connections
if (count($_POST['submit'])==0) {
?>
<form action = "thispage.php" method="post">
Your Email: <input type="text" name="email"> <input type="submit" name="submit" value="Join Mailing List!">
</form>
<?php
} else {
if (empty($_POST['email'])==TRUE) {
echo "Please enter an email address.";
} else {
@mysql_query("INSERT into `mailing_list` (email) values ('". trim($_POST['email']) ."')");
}
}
?>
That should work Ok, however you will definately need to add some sort of spam control and maybe email regular expressions to make sure the enter emails are real address. Other than that *should* work.
Don't forget to always sanitize user input, for example
$email = mysql_real_escape_string($_POST['email']);
Potter_gold
04-23-2007, 10:00 PM
Im struggling. I have inserted a page on teh site and copied your php.
www.freepspwallpapers.co.uk/email.php
What do i do now, i d not have a file called conections.php and do not know how to link with my database?
Peter
PappaJohn
04-23-2007, 10:14 PM
Here's a sample connections.php:
<?php
// database access information
$dbhost = 'YOUR_DB_HOSTNAME';
$dbname = 'YOUR_DATABASE NAME';
$dbuser = 'YOUR_DB_USERNAME';
$dbpass = 'YOUR_DB_PASSWORD';
// open database
mysql_connect($dbhost, $dbuser, $dbpass) or
die("<b>Critical error.</b> Could not connect to the database");
mysql_select_db($dbname);
?>
You'll have to replace the items in red with your info.
Len Whistler
04-24-2007, 01:17 AM
What do i do now, i d not have a file called conections.php and do not know how to link with my database?
I recommend you get yourself a book on PHP/MySQL otherwise you will be posting for help on every small problem you encounter.
GO ILLINI
04-25-2007, 03:33 AM
I've found that buying books about web development is a waste of money. You can get everything on the internet. Everything + live working examples. But if you learn better from books go ahead.
-Adam
Pennimus
04-25-2007, 12:47 PM
Also, not to add to your woes, but you should remember that email collection should really be a double opt-in process. That means they have to opt in by filling in your form, and you then need to send an email with a link they click to confirm they really wanted to sign up.
That's not too arduous though once you've got the other stuff down - but something to have in the back of your mind.
Potter_gold
04-25-2007, 07:28 PM
Hi Guys
Sorted this for now, but will look in to the double opt in. I need to organise the strucutre of the page and ensure that i am asking people to sign up for a real reason.
Cheers.
Peter
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.