PHP Woes!

Discussion in 'Web Design & Coding' started by Ownerer, Sep 23, 2010.

  1. Ownerer

    Ownerer

    Joined:
    Apr 30, 2006
    Messages:
    11
    Likes Received:
    0
    Location:
    UK
    Hey guys. I can get a basic form (stolen from a template) to work, it is as follows:

    The HTML Form Code:

    <form method="post" action="sendmail.php">
    Client Email: <input name="email" type="text" /><br />
    Message:<br /> <textarea name="message" rows="15" cols="40"></textarea><br />
    <input type="submit" />
    </form>

    The sendmail.php code:

    <?php
    $email = $_REQUEST['email'] ;
    $message = $_REQUEST['message'] ;

    mail( "your@emailhere.com", "Feedback Form Results",
    $message, "From: $email" ) ;
    header( "Location: http://www.example.com/thankyou.html" );
    ?>

    ----------------------------------------------------------------------------------------------------------------------------

    The above, sends an email to my account which is 'from' the email address entered in the email input box. The details from the 'message' then are in the main body of the email. The page then redirects to the address specified.

    However whenever I try to add an input field, it doesn't work, and the same two things from before just come through. Oh, and obviously I update the HTML form code with a new input area as below in bold:

    <form method="post" action="sendmail.php">
    Client Email: <input name="email" type="text" /><br />
    Message:<br /> <textarea name="message" rows="15" cols="40"></textarea><br />
    Business Name: <input name="businessname" type="text" /><br />
    <input type="submit" />
    </form>

    If someone could tell me how to add additional fields and the necessary code in the PHP page, that would be greatly appreciated!

    I tried adding a field called 'businessname'

    then in the PHP file added the items in bold:

    <?php
    $email = $_REQUEST['email'] ;
    $message = $_REQUEST['message'] ;
    $businessename = $_REQUEST['businessemail'] ;

    mail( "your@emailhere.com", "Feedback Form Results",
    $message, "From: $email", $businessname, "Business Name: $businessname" ) ;
    header( "Location: http://www.example.com/thankyou.html" );
    ?>

    I'm totally unaware of how I should have entered the extra field information, so please tell me! The above was just an attempt I made!
     
    Ownerer, Sep 23, 2010
    #1
    1. Advertisements

  2. Ownerer

    S Walch MAME 0.64 :) VIP Member

    Joined:
    Jun 2, 2003
    Messages:
    1,026
    Likes Received:
    14
    Location:
    Manchester
    I think the problem is this line: $businessename = $_REQUEST['businessemail'] ; - you have it trying to get a "businessemail" when actually all you have specified is a businessname.

    I don't know too much about PHP, and prefer to just use a CMS plus their relative plugins which do it a lot better than I could code myself.
     
    S Walch, Sep 24, 2010
    #2
    1. Advertisements

  3. Ownerer

    Ownerer

    Joined:
    Apr 30, 2006
    Messages:
    11
    Likes Received:
    0
    Location:
    UK
    The businessname, businessemail thing was a mistake in how I typed the code in, in my example, sorry!

    A friend of mine gave me a hand and this code works perfectly:

    <?php
    $email = $_REQUEST['email'] ;
    $message = $_REQUEST['message'] ;
    $businessemail = $_REQUEST['businessemail'] ;

    mail("awpert@gmail.com", "Feedback Form Results",
    "Message: ".$message."\n"."Business name: ".$businessemail, "From: $email");
    header( "Location: http://www.google.co.uk" );
    ?>

    In case anyone has the same issue, that's how you add stuff! :)
     
    Ownerer, Sep 24, 2010
    #3
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.