Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

htlm form with php.. need help

Options
  • 15-10-2008 11:30pm
    #1
    Registered Users Posts: 346 ✭✭


    hey,

    Can anyone help me with the following plse!

    I want to create a hmtl form and take the data entered and send it to an email address via my web server.

    so my htlm form is as follows:

    <form name="asa" action="http://www.website.ie/asa/asa_form_action.php&quot; method="get">
    Name:<br>
    <input type="text" name="email" size="14" maxlength="250" />
    <br>
    Email:<br>
    <input type="text" name="name" size="14" maxlength="250"/>
    <br>
    Mobile:<br>
    <input type="text" name="name" size="14" maxlength="250"/>
    <br>
    <input type="submit" name="Submit" value="Submit" /></form>

    which I think is fine..

    I need help with the php, so far I have...

    <?php
    ASA <?php echo $_POST["name"]; ?>.<br />
    <?php echo $_POST["email"]; ?>
    <?php echo $_POST["mobile number"]; ?>

    and then I guess that takes the data and I just need the code to send it via my mail server to a final email address..

    hope that makes sense.. any help appreciated

    ps its a mobile website.. I guess php works in this enviroment?


Comments

  • Users Awaiting Email Confirmation Posts: 351 ✭✭ron_darrell


    Ok a few problems that I can see. The names for your input fields are not unique. You use name="name" at least twice. The method of the form is get yet you try to retrieve the data using $_POST. The name's used in the $_POST (which should be $_GET by the way if the method in the form is GET) do not match the names used in the input tags (there is no name="mobile number" in your form and it is not recommended to used spaces in the id/name of a tag). Finally, the $_POST (or the $_GET as you should be using if the method of the form is GET) do not send emails. This looks like cut and paste code and if you'll forgive my saying it doesn't look like you know what the code you're copying does. Would you like me to write something simple to do what you are looking for? Can you please give me a little more information on what you want in the email?

    Sorry if the above sounded harsh,
    Regards,
    RD


  • Registered Users Posts: 346 ✭✭deepriver


    your absolutely right I have no idea what I am doing, I just have some basic html and I am trying to copy other websites and patching things together, which dont fit as you rightly pointed out.

    but cheers for the pointers... below is the html form updated with the correct name field


    <form name="asa" action="http://www.website.ie/asa/asa_form_action.php&quot; method="get">
    Name:<br>
    <input type="text" name="name" size="14" maxlength="250" />
    <br>
    Email:<br>
    <input type="text" name="email" size="14" maxlength="250"/>
    <br>
    Mobile Number:<br>
    <input type="text" name="mobile_number" size="14" maxlength="250"/>
    <br>
    <input type="submit" name="Submit" value="Submit" /></form>


    In terms of what the email should contain.

    User comes to the website and requests a brochure for the company by submitting info into three boxes as below

    name
    email
    mobile number

    I want to take that info, put it into an email and send it to my client i.e. client@company.ie

    so they would recieve something to the effect
    name:Shane
    email: shane@company.ie
    mobile number: 0871234567

    I'm a bit lost on the difference between POST and GET, but hopefully the above info answers that query?

    appreciate any further help Ron :P


  • Users Awaiting Email Confirmation Posts: 351 ✭✭ron_darrell


    Save the below as the code for asa_form_action.php. This will send an email from noreply@asa.com to the user of the site (based on the email they entered in the form). You will need to add to this page so that the user just doesn't end up with a blank page. HTML can go around the <?php ?> code (so before or after). Maybe some sort of simple page saying an email has been sent and a link back to the rest of the site.
    <?php
    $from = "noreply@asa.com";
    $headers = "From: ".$from;
    $to = $_GET["email];
    $subject = "E-Brochure from MyCo.ie to ".$_GET["name"];
    $message = "The source for the brochure will go here ok?";
    
    mail($to,$subject,$message,$headers); 
    ?>
    

    Hope that helps a bit.

    Regards,
    RD


  • Registered Users Posts: 346 ✭✭deepriver


    heya RD

    Sorry I explained badly...

    random punter comes to website and fills in their details in the three boxes i.e. requesting more info or contact from the company in question... Asa

    I want to build the website that takes the info entered in the three boxes (name / email contact address & mobile phone number) and send it to my client ie the person who is paying me to the build the website

    so literally I want to take the info submitted in the HTML form and send it to an email address (of my client)

    Doesnt matter what the info submitted is, its up to my client to then take the info and do whatever they want with it.. bin it, contact the customer etc


  • Users Awaiting Email Confirmation Posts: 351 ✭✭ron_darrell


    What's the clients address - ok forget that - lets say it's client@clientsdomain.com.

    Just adapt the code I already gave you in this case
    <?php
    $from = "noreply@asa.com";
    $headers = "From: ".$from;
    $to = "client@clientsdomain.com";
    $subject = "E-Brochure request from ".$_GET["name"];
    $message = $_GET["name"]." requested a brochure. This potential clients details are: <br />Name: ".$_GET["name"]."<br />Email: ".$_GET["email"]."<br />Mobile: ".$_GET["mobile_number"]."<br /><br />";
    
    mail($to,$subject,$message,$headers); 
    ?>
    

    Please don't take this the wrong way but you seem a bit out of your depth here. I'd advise passing this client on the a more fully trained developer & getting some training if this is something you'd like to keep doing. If something as basic as this is throwing you it's not fair to you or to the client to keep trying to 'wing' it.

    RD


  • Advertisement
Advertisement