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

I need help with a simple PHP code

Discussion in 'PHP & Perl' started by paymymortgage4me, Feb 19, 2009.

  1. paymymortgage4me

    paymymortgage4me Junior Member

    Joined:
    Apr 5, 2008
    Messages:
    163
    Likes Received:
    308
    Location:
    I'm An Everywhere Man
    I'm trying to get build my mailing list. Currently on my website, I have an opt-in form. When people enter their name and email addy, I get an email with that information and they are then sent to another page that says thanks for signing up...

    How can I make it so if one or both fields are left blank, they can't hit the submit button? Or they just don't go to the thanks page.

    Here's the code I'm using:

    Code:
    <?php
      $name = $_REQUEST['name'] ;
      $email = $_REQUEST['email'] ;
    
      mail( "myemailaddress@gmail.com", "New Email Submit",
        $name, $email );
      header( "Location: http://www.mywebsite.com/main.html" );
    ?>
    I know almost nothing about PHP. I hope this is the right place.

    Thanks in advance.
     
    • Thanks Thanks x 1
  2. nonhacker

    nonhacker Regular Member

    Joined:
    Dec 26, 2008
    Messages:
    255
    Likes Received:
    64
    Occupation:
    Computer Tech/ Web Designer
    is this being done via Wordpress or just a normal php site..
    what is the opt-in form made from..
    is it thru aweber or something like that or is it some stand alone code.
    I would assume it is linked to some dbase as well eh..

    Need more details
     
  3. buileminh

    buileminh Newbie

    Joined:
    Feb 1, 2009
    Messages:
    3
    Likes Received:
    2
    Just a little improvement as you required:
    Code:
    <?php
    $name = $_REQUEST['name'] ;
    $email = $_REQUEST['email'] ;
    
    if($name=="" || $email=="") {
      echo "Both fields are required!";
    } else {
      mail( "myemailaddress@gmail .com", "New Email Submit", $name, $email );
      header( "Location: ht tp://www .my website .com /main.html" );
    }
    ?>
    
    For better improvement, please PM me!
     
    • Thanks Thanks x 2
  4. nonhacker

    nonhacker Regular Member

    Joined:
    Dec 26, 2008
    Messages:
    255
    Likes Received:
    64
    Occupation:
    Computer Tech/ Web Designer
    good on you buileminh

    eventually someone comes to the party and offers help....
     
  5. paymymortgage4me

    paymymortgage4me Junior Member

    Joined:
    Apr 5, 2008
    Messages:
    163
    Likes Received:
    308
    Location:
    I'm An Everywhere Man
    Thanks for the help buileminh. This seems to be do exactly what I was trying to do. You guys are great!
     
  6. benitomol

    benitomol Newbie

    Joined:
    Feb 13, 2009
    Messages:
    20
    Likes Received:
    0
    Location:
    Los Angeles,CA
    Thanks for the question and reply...I was gonna post a similar question. Hey paymymortgage4me, are you using a email service like aweber or having it submitted to a db?
     
  7. paymymortgage4me

    paymymortgage4me Junior Member

    Joined:
    Apr 5, 2008
    Messages:
    163
    Likes Received:
    308
    Location:
    I'm An Everywhere Man
    hey benitomol,

    With this site, I'm actually just storing the email addresses in a group in my gmail account. My list currently has 4 email addresses in it! no point in paying for aweber yet.