Email submit to database

jamesyboy

Regular Member
Joined
Apr 4, 2011
Messages
215
Reaction score
21
I'm needing a simple script that will save an email address to a database and then redirect the user to an external URL. Classic CPA landing page.
 
OK, so I've worked out this can be done using a couple of Wordpress plugins - Contact Form 7, etc. But I still need a little script hack to send the PHP.
 
Forgot to say that I can't reply to PM's yet cos I'm pretty new.
 
Just a snippet u can worked with:
PHP:
<?php
 
    if(isset($_POST['mail'])) {
       
       mysql_connect('<YOUR HOST>', '<YOUR DB-USER>', '<YOUR DB-PASS>') or die ('Connection Error');
       mysql_select_db('<YOUR DB-NAME')                                 or die ('Couldnt select DB'); 
       
       $mail  = mysql_escape_string($_POST['mail']);

       $query = "INSERT INTO mail (id, mail) VALUES (NULL, '$mail')";  
       mysql_query($query); 
       header('Location: <YOUR THANK-YOU-PAGE>.php');  
    } else {
        echo '<p>Please insert your email.</p>';
    }

?>
HTML:
<form action="" method="post" name="formular">  
       <fieldset><label>Enter Mail</label><input type="text" maxlength="25" name="mail" value="" /></fieldset>      
       <input type="submit" name="send" value="Submit email" /> 
</form>

You can put everything in one .php-file, just copy & paste it.
It doesn't check if someone posts a valid email adress so don't use it on a live-system!

Greetz
 
Last edited:
Thanks Buddha. I'm grateful for your time.
 
For correct email syntax verification, you can use regular expression verification. Just google for tutorials
 
Yup, use JS
string.match() to be sure that the text submitted is an email ;)
 
Email verification is a special issue. Also, JS data validation is outdated and has never been reliable. If you need to filter out invalid emails you better use server side email checker script.
 
Make sure you filter what the user inputs a great deal, very dangerous without.
 
Back
Top