Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 26
  1. #1
    New Coder
    Join Date
    Jul 2007
    Posts
    56
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Question PHP Mail Form Incorrect

    Here's the code for my form...

    PHP Code:
    <form method="POST" action="contactmail.php">

    <
    font size="2" face="arial"
    <p><b>*Username:</b><br>
    <
    input type="text" name="Username">
    <
    p><b>*Email Address:</b><br>
    <
    input type="text" name="EmailAddress">
    <
    p><b>Gender:</b><br><input type="radio" name="gender" value="Male">Male
    <br><input type="radio" name="gender" value="Female">Female
    <p><b>Browsers:</b><br>
    <
    input type="checkbox" name="browsers" value="Firefox" />Firefox<br>
     <
    input type="checkbox" name="browsers" value="Internet Explorer/Netscape" 

    />IE/Netscape<br>
    <
    input type="checkbox" name="browsers" value="Other" />Other<p>
    <
    b>*Desired Position:</b><br>
    <
    select name="Position">
    <
    OPTION VALUE="Admin" NAME="Admin">Administrator</option>
    <
    OPTION VALUE="Mod" NAME="Mod">Moderator</option>
    <
    OPTION VALUE="Design" NAME="Design">Designer</option>
    <
    OPTION VALUE="Other" NAME="Other">Other</option>
    </
    select><p>
    <
    b>Summary/Other Position Request:</b><br>
    <
    textarea name="summary" rows="6" cols="20"></textarea>
    <
    p><font size="1">*Required</font></p>
    <
    p><input type="submit" name="submit" value="Submit"></font>

    </
    form
    Here's the code for the php that it redirects to to send to our email system.

    PHP Code:
    <?php
      
    // get posted data into local variables
    $EmailFrom "--------------";
    $EmailTo "---------------";
    $Subject "Contact Form Submission";
    $Username Trim(stripslashes($_POST['Username'])); 
    $EmailAddress Trim(stripslashes($_POST['EmailAddress'])); 
    $gender Trim(stripslashes($_POST['gender'])); 
    $browsers Trim(stripslashes($_POST['browsers'])); 
    $position Trim(stripslashes($_POST['position'])); 
    $summary Trim(stripslashes($_POST['summary']));

    // validation
    $validationOK=true;
    if (!
    $validationOK) {
      print 
    "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
      exit;
    }

    // prepare email body text
    $Body "";
    $Body .= "Username: ";
    $Body .= $Username;
    $Body .= "\n";
    $Body .= "EmailAddress: ";
    $Body .= $EmailAddress;
    $Body .= "\n";
    $Body .= "gender: ";
    $Body .= $gender;
    $Body .= "\n";
    $Body .= "gender: ";
    $Body .= $gender;
    $Body .= "\n";
    $Body .= "browsers: ";
    $Body .= $browsers;
    $Body .= "\n";
    $Body .= "position: ";
    $Body .= $position;
    $Body .= "\n";
    $Body .= "summary: ";
    $Body .= $summary;
    $Body .= "\n";




    // send email 
    $success mail($EmailTo$Subject$Body"From: <$EmailFrom>");

    // redirect to success page 
    if ($success){
      print 
    "<meta http-equiv=\"refresh\" content=\"0;URL=index.php\">";
    }
    else{
      print 
    "<meta http-equiv=\"refresh\" content=\"0;URL=error.php\">";
    }
    ?>
    The problem is that the drop down selection menu doesn't show up in the email, and gender shows up twice. If someone could tell me how to correct this and possibly make it so that it obtains the users IP and sends it via email aswell. That would be magnificent.

  • #2
    New Coder
    Join Date
    Jul 2007
    Posts
    56
    Thanks
    8
    Thanked 0 Times in 0 Posts
    Well, I'm not sure if bumping a topic is aloud on this forum even though it's not in the rules, So I decided to give it a shot.

  • #3
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    Code:
    <select name="Position">
    <OPTION VALUE="Admin">Administrator</option>
    <OPTION VALUE="Mod">Moderator</option>
    <OPTION VALUE="Design">Designer</option>
    <OPTION VALUE="Other">Other</option>
    </select>
    Options don't have names.

  • #4
    New Coder
    Join Date
    Jul 2007
    Posts
    56
    Thanks
    8
    Thanked 0 Times in 0 Posts
    Uh, What do you mean? How would it show up in an email if it didn't have a name?

    Disregard this thread, I'm getting help from a friend. XD
    Last edited by Notre; 08-26-2007 at 02:44 AM.

  • #5
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    You get it from the value. Call it by $position.

  • #6
    New Coder
    Join Date
    Jun 2005
    Posts
    40
    Thanks
    0
    Thanked 2 Times in 2 Posts
    Notre, see W3C - Forms.

  • #7
    New Coder
    Join Date
    Jul 2007
    Posts
    56
    Thanks
    8
    Thanked 0 Times in 0 Posts
    Ok, I fixed the HTML and PHP so they would actually work together, Now is it possible to get the IP from the person who submits a form on the HTML page without them knowing, and then have it entered into a hidden section on the form and sent through the php to the email address?

  • #8
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    You would get it when the form is submitted with $_SERVER['REMOTE_ADDR'].

  • Users who have thanked Inigoesdr for this post:

    Notre (08-26-2007)

  • #9
    New Coder
    Join Date
    Jul 2007
    Posts
    56
    Thanks
    8
    Thanked 0 Times in 0 Posts
    Yes, but the HTML would have to send the form and data to the php for processing right? So I would need it to embed in the form or something and send it to the php, wouldn't I?

  • #10
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    No you don't need to

  • Users who have thanked Nightfire for this post:

    Notre (08-26-2007)

  • #11
    New Coder
    Join Date
    Jul 2007
    Posts
    56
    Thanks
    8
    Thanked 0 Times in 0 Posts
    Aha, It worked but now how could I get it to actually require stuff? I keep getting blank emails.
    Last edited by Notre; 08-26-2007 at 10:01 PM.

  • #12
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    PHP Code:
    // validation
    if (!empty($Username) && !empty($EmailAddress)) // etc.
    {
        
    //send mail
    }
    else
    {
        print 
    "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
        exit;

    You can use a number of functions besides empty() to check the variables, such as strlen(). Empty will return true if the value sent with the form is 0, false, or null.

    You can do redirects with header() in PHP too, btw. As long as you haven't output anything before you try to use it.

  • #13
    New Coder
    Join Date
    Jul 2007
    Posts
    56
    Thanks
    8
    Thanked 0 Times in 0 Posts
    Aha, So I can just add stuff that I need.

    So I suppose this would work...

    PHP Code:
    // validation
    if (!empty($Username) && !empty($EmailAddress)) // etc.
    {
        
    //send mail
    $success mail($EmailTo$Subject$Body"From: <" $EmailFrom ">");
    }
    else
    {
        print 
    "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
        exit;

    Last edited by Notre; 08-26-2007 at 10:16 PM.

  • #14
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    I don't see any errors, so yes it should.

  • #15
    New Coder
    Join Date
    Jul 2007
    Posts
    56
    Thanks
    8
    Thanked 0 Times in 0 Posts
    It works, But if variable= something other than 0 or null It just goes to the php page, I need it to go back to my index.


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •