Page 1 of 4 123 ... LastLast
Results 1 to 10 of 38

Thread: Form help

  1. #1
    Join Date
    Oct 2006
    Posts
    41
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Form help

    Hopefully I'm not being a pain with these questions. I'm extremely new to forms and I don't have the time to read through a bunch of tutorials (although I realise this is the smartest way).

    I have a simple form on my page where the user submits their address and email info, and then I want it mailed to me.

    I have the basic script so far, and the submit button and all that, and I understand that the way I have it now (the mailto:blahblah@blahblah.com) is not ideal as it just links to your computer email program or whatnot.

    I believe I need to use something called PHP or I need a file in my cgi-bin folder on the server, something like that? Can someone (in a very simple way please) tell me what exactly I need to do to get this information submitted to my email AND display a thank you page? As well in the future I will want to change to the business owner's email and I don't want this to be complicated or to be a problem. I'm just temporarily having the info submitted go to my email.

    Thanks in advance
    Last edited by vacatia; 04-30-2008 at 12:53 AM.

  2. #2
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    if you wish to do it through php, you first need to see if your host (isp) supports php. you also need to be sure it supports mailing, which it probably will.

    writing the script to send the email is fairly easy, you create a message body from the values in the form. then you assign a recipient, subject and you can email the message. the basic php mailer function is

    PHP Code:
    mail($RECIPIENT$SUBJECT$MESSAGE); 
    The second option is to use cgi-bin, in which your server will most likely have a canned (pre-made) template that you need to follow to send the email.

  3. #3
    Join Date
    Oct 2006
    Posts
    41
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    Hi there,

    When I login to server stuff I do see a cgi-bin folder...but like I said I am a complete beginner at this so basically the stuff you just said was like Japanese to me. Like, I don't even know where to begin. I have the forms embedded on my website but after that I'm completely lost.

  4. #4
    Join Date
    Apr 2006
    Posts
    205
    Thanks
    11
    Thanked 0 Times in 0 Posts

    Smile

    Hi Vacatia,

    Just to cover the basics, generally speaking a form has a frontend, this is what you probably already have in your HTML document, a basic one might look something like this:

    HTML Code:
    <form name="form1" action="formSender1.php"  method="post">
    
     <label for="name">Name :</label>
     <input name="name" type="text" />
     <br />
     
     <label for="email">Email address :</label>
     <input name="email" type="text" />
     <br />
    
     <input type="reset" />
     <input type="submit" />
     
    </form>
    There's also a backend which in the case of this form is "formSender1.php". The backend can be what receives the information submitted through the form and then does something with it, like sends it as an email.

    Here is some simple PHP that you could use to send the information of a form like this one as an email:

    Code:
    <?
    
    
    $name = $_POST['name'];
    $email = $_POST['email'];
    
       $to = "your@email.com";   
       $subject = "From Contact Form";   
       $body = "Name: ".$name."\r\n\r\n";
       $body .= "Email: ".$email."\r\n\r\n"; 
     
       $from = ".$email.";
    
      mail($to, $subject, $body, $from);
      header("Location: http://yoursite.com/thanks.html");
      exit;
        
    ?>
    I hope this helps.

    PEACE

    dog

  5. #5
    Join Date
    Oct 2006
    Posts
    41
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    Thanks dog, so what that will bring up a thank you page too right? Is this all I need to do//I don't need to download some file and put it in my cgi-bin?

    *Edit* I tried the code above, everything looks good and the reset button works, but when I click submit it just takes me to a page that doesn't work and I didn't get an email. What am I doing wrong?
    Last edited by vacatia; 04-30-2008 at 12:53 AM.

  6. #6
    Join Date
    Apr 2006
    Posts
    205
    Thanks
    11
    Thanked 0 Times in 0 Posts

    Default

    Oops! I should have mentioned that PHP is a server-side language. You won't be able to test it on your local machine without setting up a special environment. What's often best is uploading your files and testing them online.

    If you're still having problems make sure that you've edited the code I posted correctly. In my example, as well as the file containing your form you need to create two extra files, 'formSender1.php' and 'thanks.html' and position them in the correct places and make sure all the links to them are correct.

    eg. lines like this will obviously need editing:
    PHP Code:
    header("Location: http://yoursite.com/thanks.html"); 
    As for the 'formSender1.php' just copy the code I posted into a blank document and save it as formSender1.php in the same folder as the form.

    Another possible source of problems is your hosting package. Check with your hosting provider that PHP is supported and take a look around to see if there are any special conditions regarding sending email from your site.

    If you're still having problems after this, post the code you are using for other people to take a look.

    Good luck!

    dog

  7. #7
    Join Date
    Oct 2006
    Posts
    41
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    Hi again!

    Ok I have a thanks page, and I saved your php code into a file and saved it in the same folder. Still not working though:

    The form code on my main page is:
    HTML Code:
    <form name="form1" action="formSender1.php"  method="post">
    
     <label for="firstname">First Name :</label>
     <input name="firstname" type="text" />
     <br />
     
     <label for="lastname">Last Name :</label>
     <input name="lastname" type="text" />
     <br />
     
      <label for="address">Address :</label>
      <input name="address" type="text" />
    <br />
    
      <label for="phonehome">Phone (home) :</label>
      <input name="phonehome" type="text" />
    <br />
    
    <label for="phonecell">Phone (cell) :</label>
    <input name=phonecell" type="text" />
    <br />
    
    <label for="emailaddress">Email Address :</label>
    <input name="emailaddress" type="text" />
    <br />
    
    <input type="reset" />
     <input type="submit" />
     
    </form>
    Then I created a php page called formsender1.php and I used your code:
    PHP Code:
    <?


    $firstname 
    $_POST['firstname'];
    $lastname $_POST['lastname'];
    $address $_POST['address'];
    $phonehome $_POST['phonehome'];
    $phonecell $_POST['phonecell'];
    $emailaddress $_POST['emailaddress'];

       
    $to "whatever@yahoo.com";   
       
    $subject "Grill Form";   
       
    $body "First name: ".$firstname."\r\n\r\n";
       
    $body "Last name: ".$lastname."\r\n\r\n"
       
    $body "Address: ".$address."\r\n\r\n";
       
    $body "Home Phone: ".$phonehome."\r\n\r\n";
       
    $body "Home (cell): ".$phonecell."\r\n\r\n";
       
    $body "Email Address: ".$emailaddress."\r\n\r\n";
     
       
    $from ".$emailaddress.";

      
    mail($to$subject$body$from);
      
    header("Location: http://www.mypage.ca/thankyou.htm");
      exit;
        
    ?>
    I believe my server supports php stuff as well, did I do anything wrong above?
    Last edited by vacatia; 04-30-2008 at 12:54 AM.

  8. #8
    Join Date
    Mar 2007
    Location
    Currently: New York/Philadelphia
    Posts
    2,735
    Thanks
    3
    Thanked 519 Times in 507 Posts

    Default

    Seems like it should work at quick glance. One thing that *might* be an issue is that some servers are pretty strict as far as naming and cases.

    So...

    formsender1.php is different than formSender1.php (notice the capitalization of S). That might be something you want to look to.

    Also, some PHPconfigurations don't have the PHP short tag turned on. So change the <? opening tag to <?php and see if that fixes it.

    If it still doesn't work...try this to make sure that you're able to send email via PHP:

    Open up a text editor. Copy and paste in the code below and name it mailtest.php. Then upload it to your server and access the page. If you uploaded it to your root directory, then it should simply be at www.yourwebsite.com/mailtest.php.
    PHP Code:
    <?php

    mail
    ("email@email.com","This is a test","Testing Server Mail Support")

    ?>
    Change email@email.com to where ever you want your email sent. Also, if the minielky email address in your post is your real email address, I would remove it unless you want to start getting spammed like crazy. The DD forums have really high bot traffic.

    Whether this works or not will tell us if your server PHP and/or SMTP (mail) support.

  9. #9
    Join Date
    Oct 2006
    Posts
    41
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    Hi Medyman,

    I tried the test and it worked, so it looks like that aspect is good to go.

    I actually changed the code I used above as I'm trying to use that dagon design script, but that's a whole other thing I'm having problems with

  10. #10
    Join Date
    Mar 2007
    Location
    Currently: New York/Philadelphia
    Posts
    2,735
    Thanks
    3
    Thanked 519 Times in 507 Posts

    Default

    Well, I can't help with the Dagon script. As I said, I haven't used it personally.

    Back to this script that dog posted though.

    Are you getting a blank email or no mail at all? You should be getting an email with just the person's email address in it.

    Fix this error to get the entire "body":

    PHP Code:
     $body "First name: ".$firstname."\r\n\r\n"
       
    $body .= "Last name: ".$lastname."\r\n\r\n";  
       
    $body .= "Address: ".$address."\r\n\r\n"
       
    $body .= "Home Phone: ".$phonehome."\r\n\r\n"
       
    $body .= "Home (cell): ".$phonecell."\r\n\r\n"
       
    $body .= "Email Address: ".$emailaddress."\r\n\r\n"
    Also change
    PHP Code:
    $from ".$emailaddress."
    to this:
    PHP Code:
    $from $emailaddress
    Notice the periods in front of the equal sign.


    If that still doesn't work, change your formSender1.php code to the following (remove ALL of what you have and enter this):
    PHP Code:
    <?php

    $firstname 
    $_POST['firstname']; 
    $lastname $_POST['lastname']; 
    $address $_POST['address']; 
    $phonehome $_POST['phonehome']; 
    $phonecell $_POST['phonecell']; 
    $emailaddress $_POST['emailaddress']; 

       
    $to "whatever@yahoo.com";    
       
    $subject "Grillmasters Form";    
       
    $body "First name: ".$firstname."<br>"
       
    $body .= "Last name: ".$lastname."<br>";  
       
    $body .= "Address: ".$address."<br>"
       
    $body .= "Home Phone: ".$phonehome."<br>"
       
    $body .= "Home (cell): ".$phonecell."<br>"
       
    $body .= "Email Address: ".$emailaddress."<br>"
      
       
    $from $emailaddress

       
       echo 
    "To: ".$to;
       echo 
    "<br>Subject: ".$subject;
       echo 
    "<br><br>Message:<br> ".$body;
       echo 
    "<br><br>From: ".$from;
       
    ?>
    Now, go to wherever your form is, enter some data and hit submit. You should get a page that lists what would have been in the email. This won't send an email but it'll make sure that the values are being carried over to the script correctly. If the values are correct (as determined by this test) and you can send mail (as determined by the test script earlier) than there is something up with the mail function.
    Last edited by Medyman; 04-27-2008 at 01:46 PM.

  11. The Following User Says Thank You to Medyman For This Useful Post:

    vacatia (04-27-2008)

Bookmarks

Posting Permissions

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