Skip navigation
Currently Being Moderated

Contact form nightmare

Feb 25, 2013 8:53 AM

I feel like an idiot for even asking this but I've tried to no avail. I just need the simple php code to link this form to. I'm also trying to redirect to a custom page after submission but I won't be greedy if someone can just help me with getting the form to send correctly.

 

Thanks for any help.

 

This is the page to see the form.

 

http://www.doubleulabs.com/tfm/index.html#contact

 

Thank for any help. I've searched the forums and still can't figure it out.

 
Replies
  • Currently Being Moderated
    Feb 25, 2013 9:18 AM   in reply to kineticcreative123

    Server-side email processing scripts are available all over the internet.

    Best suggestion would be to get one from your hosting company

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 25, 2013 9:19 AM   in reply to Ken Binney

    I like Formmail from http://www.tectite.com

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 25, 2013 9:21 AM   in reply to kineticcreative123

    You need a form-to-email processing script. Preferably one which conceals your e-mail address from harvesters and has built-in security & spam prevention.

     

    Contact your web host and ask them if they have one you can use.  Hosts often provide scripts on their servers which you can activate through your C-Panel or by referencing the script in your form's action attribute.

     

         <form id="form1" action="path-to-form-on-server/form-to-email-script.php">

     

    If your host doesn't provide scripts, ask them which server-side languages you can use (php, asp, asp.net, perl, coldfusion, etc...).

     

    Related Links:

     

        Formm@ailer PHP from DB Masters

        http://dbmasters.net/index.php?id=4

     

        FormToEmail.com (free & pro versions available)

        http://formtoemail.com/formtoemail_pro_version.php    

     

        Tectite

        http://www.tectite.com/formmailpage.php

     

     

        Forms to Go from Bebosoft (script generating software)

        http://www.bebosoft.com/products/formstogo/overview/

     

     

        Wufoo.com (on-line form service)

        http://wufoo.com/

     

     

     

    Nancy O.

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 25, 2013 11:12 PM   in reply to kineticcreative123

    That error usually means you have some whitespace in your php document. White space will cause headers to be sent to the client and once that occurs you can not do a header redirect. Look for blank lines before the php tags.

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 25, 2013 11:49 PM   in reply to kineticcreative123

    If you get stuck, below is a complete form page, cut and paste it into a document and save it as contactform.php. The page sends the information to itself, processes it, validates it, sends the collected information to the email if there are no validation errors, and then re-routes to the thankyou page. It also has a honeypot spam catcher so if a bot fills it out the send mail will be aborted.

     

    IMPORTANT: add your email address in the php code where it says:

    // recipient

    $to = "xxxxxx@xxxxxxxxx.net";

     

     

     

    <?php

    if (array_key_exists('submit', $_POST)) {

        // check name field

    $name = trim($_POST['name']);

    if (empty($name)) {

        $error['name'] = 'Please enter your name';

    }

    elseif ($name == 'Please enter your name') {

        $error['name'] = '';

    }

    // check email field

    $email = trim($_POST['email']);

    if (empty($email)) {

        $error['email'] = 'Please enter your email address';

    }

    elseif ($email == 'Please enter your email address') {

        $error['email'] = '';

    }

    // check comment field

    $comment = trim($_POST['comment']);

    if (empty($comment)) {

        $error['comment'] = 'Please enter your comment';

    }

    elseif ($comment == 'Please enter your comment') {

        $error['comment'] = '';

    }

    if (!empty($_POST['ufo'])) { return false; }

    // recipient

    $to = "xxxxxx@xxxxxxxxx.net";

    // email subject

    $subject = "from MSTRPLN website form";

    // sender

    $sender = "From: ".$_POST['email']."\r\n";

    // build message

    $message  = "Name: $name\n\n";

    $message .= "Email Address: $email\n\n";

    $message .= "Comment: $comment\n\n";

    // send email if no form erorrs

    if (!isset($error)) {

    mail($to, $subject, $message, $sender);

    mail($reply, $replysubject, $replymessage, $replyfrom);

    header("Location: http://hybrid.concordia.ca/~mstrpln/thankyou.html");        //Redirect page -- change to your own page

    }

    }

    ?>

     

     

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml">

    <head>

    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

    <title>Untitled Document</title>

     

    </head>

    <body>

    <form method="post" id="contactform" action="contactform.php">

    <p><label for="name">Name</label></p>

    <input type="text" id="name" name="name" tabindex="1" <?php if(isset($error['name'])) echo "style='border: 1px solid #C00; color: #C00;'"; ?> value="<?php if(isset($name)) {echo $name;} ?><?php if(isset($error['name'])) echo $error['name']; ?>" onfocus="this.value=''"/>

    <p><label for="email">Email</label></p>

    <input type="text" id="email" name="email" tabindex="2" <?php if(isset($error['email'])) echo "style='border: 1px solid #C00; color: #C00;'"; ?> value="<?php if(isset($email)) {echo $email;} ?><?php if(isset($error['email'])) echo $error['email']; ?>" onfocus="this.value=''"/>

    <p><label for="comment">Your Message</label></p>

    <textarea name="comment" id="comment" tabindex="4" <?php if(isset($error['comment'])) echo "style='border: 1px solid #C00; color: #C00;'"; ?>><?php if(isset($comment)) {echo $comment;} ?><?php if(isset($error['comment'])) echo $error['comment']; ?></textarea>

    <input name="submit" type="submit" id="submit" tabindex="5" value="Send Message" />

    <input type="text" name="ufo" style="visibility: hidden;">

    </form>

    </body>

    </html>

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 26, 2013 5:59 AM   in reply to osgood_

    Hi guy -

    Good to see you again.

    Have not tested the PHP script, but unexpected display on the HTML portion of your post.

    Can you assist?

    osgood.jpg

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 26, 2013 7:23 AM   in reply to Ken Binney

    Hi Ken,

     

    This is a php document. If you save it as .html and try to view it in a browser you will see those errors

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 26, 2013 7:32 AM   in reply to osgood_

    Thanks mate,

     

    I am attracted to the honeypot feature.

    I'll check out the processing script now

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 26, 2013 7:42 AM   in reply to osgood_

    Worked like a charm, thanks again.

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 26, 2013 8:08 AM   in reply to osgood_

    One further question if I may Os.

     

    The processing script suggests that an error message would be displayed if form were submitted with an empty field.  This is not happening.

     

    http://www.binney.us/contact.php

     

    Is there some code modification required for errors to display?

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 26, 2013 10:09 AM   in reply to Ken Binney

    Hi Ken,

     

    All the code goes into one document, not two. At the moment you are splitting the two, putting the html in contact.php and sending to contactForm.php

     

     

    If you just copy all the code from my original post and save it as contactForm.php it will send back to itself to do the processing. If it finds an empty field the field will be flagged with an error message.

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 27, 2013 3:56 PM   in reply to osgood_

    Well, kineticcreative123 felt like an idiot asking the question, but at least he got his to work. I simply can't get this (I asked a similar question a couple of days ago).

     

    I copied and pasted into a blank document and saved it as contactform.php.  I changed this:  $to = "xxxxxx@xxxxxxxxx.net"; to my email address and this:

    header("Location: http://hybrid.concordia.ca/~mstrpln/thankyou.html");  //Redirect page -- change to your own page  to my site's contact page (http://www.dirtbikes101.com/contact.html).

     

    I uploaded the php file to my public_html file.

     

    I'm not sure where I'm going wrong 

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 27, 2013 4:13 PM   in reply to lostinny

    1) you probably should start a new thread. Tagging onto the end of another thead can get confusing.

    2) you'll need to show us your code and explain the symtoms

    3) I visited your contact page but there is nothing there!

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 27, 2013 4:45 PM   in reply to lostinny

    Ditto tp bregent

     

    Note I think in Osgood's proposal, you were supposed to redirect to your own thankyou page, not your contact page

     

    @Osgood -

     

    His page is at:

    http://www.dirtbikes101.com/contactform.php

    but displays only code

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 27, 2013 5:21 PM   in reply to Ken Binney

    Okay, sorry - will start another thread.

     

    Thanks for taking a look.

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 3, 2013 6:12 AM   in reply to lostinny

    You're welcome pal -

     

    Please check your online page would you.  There's a ton of tags in it that were not in the recommended page. 

     

    Is it possible you pasted it into DESIGN view instead of CODE view?

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points