Posted on March 10th, 2007
4031 views
In this tutorial we are going to create an email collecter. I get spam mail from other design sites where the CC has been used instead off BCC. And I like to grab these email addresses so i can advertise my site to these people. So i developed this script to do it. I do this using the explode function built into php.
To begin with you need to create the database where we will store the information
And then create a new file. We will start with the database connection information
Thats just the basic connection info, you can stick it in another file and include it if you want. Now for the fun parts. Here is the rest of the code.
As you can see there is the form has been put in the else part of the script. So when the button is pressed we got to this part
This is the part where we store the individual email addresses from the text area.
the explode function is quite simple. explode('seperator', 'string, '**Max items** ') ** if you leave max items empty it will collect them all The count function counts how many array values are inside the array. Using this allows us to determine how many times we need to loop. $i = 0; I'm using the while function to do my loop, many people would use the for function however i prefer the while function for this. So when $i, our counting varible, is larger than $max the script finishes. $i also gets the record from the array $email = trim($abc[$i]); Now then you may be wondering how the script stops email duplication seems as i did say that it wouldn't. Well you may have noticed that there is one field in the table we created at the start and its a primary key. This means that its individual and no it isn't case senstive. If the letters are in the same order it won't go in. Arutha |