1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Email submit to database

Discussion in 'PHP & Perl' started by jamesyboy, Jun 3, 2011.

  1. jamesyboy

    jamesyboy Regular Member

    Joined:
    Apr 4, 2011
    Messages:
    213
    Likes Received:
    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.
     
  2. jamesyboy

    jamesyboy Regular Member

    Joined:
    Apr 4, 2011
    Messages:
    213
    Likes Received:
    21
    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.
     
  3. jamesyboy

    jamesyboy Regular Member

    Joined:
    Apr 4, 2011
    Messages:
    213
    Likes Received:
    21
    Forgot to say that I can't reply to PM's yet cos I'm pretty new.
     
  4. buddha

    buddha Newbie

    Joined:
    Apr 26, 2011
    Messages:
    17
    Likes Received:
    7
    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
     
    • Thanks Thanks x 1
    Last edited: Jun 5, 2011
  5. jamesyboy

    jamesyboy Regular Member

    Joined:
    Apr 4, 2011
    Messages:
    213
    Likes Received:
    21
    Thanks Buddha. I'm grateful for your time.
     
  6. buddha

    buddha Newbie

    Joined:
    Apr 26, 2011
    Messages:
    17
    Likes Received:
    7
    No problem ;) Good luck with this snippet, hope u know what to do with it!
     
  7. VIC SEO

    VIC SEO Elite Member

    Joined:
    Feb 19, 2010
    Messages:
    2,156
    Likes Received:
    363
    Gender:
    Male
    Occupation:
    SEO Specialist
    Location:
    iSynergyMedia
    Home Page:
    For correct email syntax verification, you can use regular expression verification. Just google for tutorials
     
  8. RootShellvb

    RootShellvb Junior Member

    Joined:
    Jan 29, 2009
    Messages:
    188
    Likes Received:
    211
    Occupation:
    CEO
    Location:
    Casablanca, Morocco
    Home Page:
    Yup, use JS
    string.match() to be sure that the text submitted is an email ;)
     
  9. ealexnet

    ealexnet Newbie

    Joined:
    Aug 3, 2010
    Messages:
    34
    Likes Received:
    6
    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.
     
  10. goaman

    goaman Newbie

    Joined:
    Jun 29, 2011
    Messages:
    1
    Likes Received:
    0
    del del
     
  11. seeplusplus

    seeplusplus Power Member

    Joined:
    Aug 18, 2008
    Messages:
    511
    Likes Received:
    163
    Make sure you filter what the user inputs a great deal, very dangerous without.