19 Replies Latest reply: Mar 3, 2013 6:12 AM by Ken Binney RSS

    Contact form nightmare

    kineticcreative123 Community Member

      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.

        • 1. Re: Contact form nightmare
          Ken Binney CommunityMVP

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

          Best suggestion would be to get one from your hosting company

          • 2. Re: Contact form nightmare
            Jon Fritz II CommunityMVP

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

            • 3. Re: Contact form nightmare
              Nancy O. CommunityMVP

              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.

              • 4. Re: Contact form nightmare
                kineticcreative123 Community Member

                Thanks everyone! This is what I am using in my php file and I'm getting somewhere now when clicking submit it goes to the php file displaying the code in the browser.

                 

                http://doubleulabs.com/tfm/index.html

                 

                 

                This is the form:

                 

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

                 

                 

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

                            <input type="text" id=name name=name placeholder="First and last name" tabindex="1" />

                 

                 

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

                            <input type="text" id=email name=email placeholder="example@domain.com" tabindex="2" />

                 

                 

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

                            <textarea name="comment" id=comment name=comment placeholder="Comments" tabindex="4"></textarea>

                 

                 

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

                 

                 

                        </form>

                                                  

                                        </form>

                 

                 

                This is the php:

                 

                 

                 


                <?php

                if(isset($_POST['submit'])) {

                 

                 

                    $to = "wdesign@comporium.net";

                    $subject = "from MSTRPLN website form";

                    $name_field = $_POST['name'];

                    $email_field = $_POST['email'];

                    $message = $_POST['message'];

                        

                    foreach($_POST['check'] as $value) {

                        $check_msg .= "Checked: $value\n";

                    }

                    

                    $body = "From: $name_field\n E-Mail: $email_field\n $check_msg Message:\n $message\n";

                 

                 

                    if(mail($to, $subject, $body)){

                  header("Location: http://hybrid.concordia.ca/~mstrpln/thankyou.html");

                }else{

                  echo "Mail was not sent!";

                }

                }

                ?>

                • 5. Re: Contact form nightmare
                  bregent CommunityMVP

                  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.

                  • 6. Re: Contact form nightmare
                    osgood_ CommunityMVP

                    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>

                    • 7. Re: Contact form nightmare
                      Ken Binney CommunityMVP

                      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

                      • 8. Re: Contact form nightmare
                        osgood_ CommunityMVP

                        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

                        • 9. Re: Contact form nightmare
                          Ken Binney CommunityMVP

                          Thanks mate,

                           

                          I am attracted to the honeypot feature.

                          I'll check out the processing script now

                          • 10. Re: Contact form nightmare
                            Ken Binney CommunityMVP

                            Worked like a charm, thanks again.

                            • 11. Re: Contact form nightmare
                              Ken Binney CommunityMVP

                              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?

                              • 12. Re: Contact form nightmare
                                osgood_ CommunityMVP

                                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.

                                • 13. Re: Contact form nightmare
                                  kineticcreative123 Community Member

                                  Thank everyone. I got it working:) But one more thing.....

                                   

                                  Why am I seeing this in the sender portion of the email?

                                   

                                  From:           boat7762@p3nlh244.shr.prod.phx3.secureserver.net

                                            Subject:           Taste Of Fort Mill Registration

                                            Date:           February 26, 2013 9:45:44 PM EST

                                            To:           Wes Whalen <wdesign@comporium.net>

                                  • 14. Re: Contact form nightmare
                                    kineticcreative123 Community Member

                                    Thanks so much Nancy! You always are a big help. Everything works but I can't figure why I am seeing this in the sender portion of the email?

                                     

                                    From:   boat7762@p3nlh244.shr.prod.phx3.secureserver.net

                                      Subject:   Taste Of Fort Mill Registration

                                      Date:   February 26, 2013 9:45:44 PM EST

                                      To:   Wes Whalen <wdesign@comporium.net>

                                    • 15. Re: Contact form nightmare
                                      lostinny Community Member

                                      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 

                                      • 16. Re: Contact form nightmare
                                        bregent CommunityMVP

                                        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!

                                        • 17. Re: Contact form nightmare
                                          Ken Binney CommunityMVP

                                          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

                                          • 18. Re: Contact form nightmare
                                            lostinny Community Member

                                            Okay, sorry - will start another thread.

                                             

                                            Thanks for taking a look.

                                            • 19. Re: Contact form nightmare
                                              Ken Binney CommunityMVP

                                              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?