Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jan 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Help getting Contact Form to work

    Im making a website from a template that has an html/php contact form. I've seen plenty of tutorials on how to make php forms but they are all different from the code that was included in my template.
    Is it just as simple as entering my email in the [ICODE]$your_email = "james@example.com";[ICODE] line of code? and uploading to my server?

    [PHP]

    <?php

    if(!$_POST) exit;

    $email = $_POST['email'];


    //$error[] = preg_match('/\b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i', $_POST['email']) ? '' : 'INVALID EMAIL ADDRESS';
    if(!eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-z]{2,}"."$",$email )){
    $error.="Invalid email address entered";
    $errors=1;
    }
    if($errors==1) echo $error;
    else{
    $values = array ('name','email','message');
    $required = array('name','email','message');

    $your_email = "james@example.com";
    $email_subject = "New Message: ".$_POST['subject'];
    $email_content = "new message:\n";

    foreach($values as $key => $value){
    if(in_array($value,$required)){
    if ($key != 'subject' && $key != 'company') {
    if( empty($_POST[$value]) ) { echo 'PLEASE FILL IN REQUIRED FIELDS'; exit; }
    }
    $email_content .= $value.': '.$_POST[$value]."\n";
    }
    }

    if(@mail($your_email,$email_subject,$email_content)) {
    echo 'Message sent!';
    } else {
    echo 'ERROR!';
    }
    }
    ?>
    [PHP]


    HTML PART

    [CODE]
    <!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>
    <title>DreamTemplate</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <link href="style.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="js/jquery.js"></script>
    <script type="text/javascript">
    // <![CDATA[
    jQuery(document).ready(function(){
    $('#contactform').submit(function(){
    var action = $(this).attr('action');
    $.post(action, {
    name: $('#name').val(),
    email: $('#email').val(),
    company: $('#company').val(),
    subject: $('#subject').val(),
    message: $('#message').val()
    },
    function(data){
    $('#contactform #submit').attr('disabled','');
    $('.response').remove();
    $('#contactform').before('<p class="response">'+data+'</p>');
    $('.response').slideDown();
    if(data=='Message sent!') $('#contactform').slideUp();
    }
    );
    return false;
    });
    });
    // ]]>
    </script>
    </head>
    <body>
    <div class="main">
    <div class="blok_header">
    <div class="header">
    <div class="logo"> <a href="index.html"><img src="images/logo.gif" width="139" height="153" border="0" alt="logo" class="one" /></a> </div>
    <div class="menu">
    <ul>
    <li><a href="index.html"><span>Home</span></a></li>
    <li><a href="about.html"><span>About Us</span></a></li>
    <li><a href="portfolio.html"><span>Portfolio</span></a></li>
    <li><a href="contact.html" class="active"><span>Contact Us</span></a></li>
    </ul>
    </div>
    <div class="clr"></div>
    </div>
    <div class="clr"></div>
    </div>
    <div class="clr"></div>
    <div class="header_text_bg">
    <h2>&nbsp;</h2>
    <div class="header_text">
    <div class="header_text_resize">
    <div class="search">
    <form id="form1" name="form1" method="post" action="">
    <label><span>
    <input name="q" type="text" class="keywords" id="textfield" maxlength="50" value="Search..." />
    </span>
    <input name="b" type="image" src="images/search.gif" class="button" />
    </label>
    </form>
    </div>
    <h2>Your company's welcome message or slogan. Lorem ipsum dolor sit amet, consectur el.<br />
    <span>Donec metus lacus, porta id, auctor sit amet, aliquam eu, lacus. Quisque sagittis vulputate orci.</span></h2>
    <div class="clr"></div>
    </div>
    </div>
    <div class="clr"></div>
    </div>
    <div class="body_resize">
    <div class="body">
    <div class="left">
    <h3>Contact Us<br />
    <span> Our mission is simple: </span> </h3>
    <p><em>&quot;Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt.&quot;</em></p>
    <p>Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. </p>
    <p><br />
    </p>
    <form action="contact.php" method="post" id="contactform">
    <ol>
    <li>
    <label for="name">First Name <span class="red">*</span></label>
    <input id="name" name="name" class="text" />
    </li>
    <li>
    <label for="email">Your email <span class="red">*</span></label>
    <input id="email" name="email" class="text" />
    </li>
    <li>
    <label for="company">Company</label>
    <input id="company" name="company" class="text" />
    </li>
    <li>
    <label for="subject">Subject</label>
    <input id="subject" name="subject" class="text" />
    </li>
    <li>
    <label for="message">Message <span class="red">*</span></label>
    <textarea id="message" name="message" rows="6" cols="50"></textarea>
    </li>
    <li class="buttons">
    <input type="image" name="imageField" id="imageField" src="images/send.gif" class="send" />
    <div class="clr"></div>
    </li>
    </ol>
    </form>
    </div>
    <div class="right">
    <h3>Contact Details<br />
    <span> Lorem ipsum dolor sit amet consectetur </span> </h3>
    <p><strong>Address</strong>: 1458 Sample Road, Greenvalley<br />
    <strong>Telephone</strong>: +123-1234-5678<br />
    <strong>FAX</strong>: +458-4578<br />
    <strong>Others</strong>: +301 - 0125 - 01258<br />
    <strong>E-mail</strong>: mail@yoursitename.com</p>
    <h3>Testimonials<br />
    <span> Lorem ipsum dolor sit amet</span></h3>
    <p><em>“ Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridicu lus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. „<br />
    <strong>- John Doe, companyname.com </strong></em></p>
    <h3>Social Places<br />
    <span> Lorem ipsum dolor sit amet, consectetur adipiscing <br />
    elit. Vestibulum eget bibendum tellus. </span></h3>
    <img src="images/rss.jpg" alt="picture" width="259" height="25" /></div>
    <div class="clr"></div>
    <div class="clr"></div>
    </div>
    <div class="clr"></div>
    </div>
    </div>
    <div class="FBG">
    <div class="FBG_resize">
    <div class="left">
    <h2>about</h2>
    <p>Code is seo friendly, optimized for getting the top results in the search engines .</p>
    <ul>
    <li><a href="#">Overview </a></li>
    <li> <a href="#">Another Link </a></li>
    <li> <a href="#">Our Company </a></li>
    <li> <a href="#">Our Staff </a></li>
    <li> <a href="#">Mision Statement </a></li>
    </ul>
    </div>
    <div class="left">
    <h2>philosophy</h2>
    <p>Neque id cursus faucibus, tortor neque egestas augue, eu vulputate magna eros eu erat magna eros eu erat. </p>
    <p>Neque id cursus faucibus, tortor neque egestas augue, eu vulputate magna eros eu erat. </p>
    <p><a href="#">Check Our Works </a></p>
    </div>
    <div class="left">
    <h2>blog</h2>
    <p>Neque id cursus faucibus, tortor <br />
    neque egestas augue, eu <br />
    vulputate magna eros eu erat. </p>
    <ul>
    <li><a href="#">Category 1 </a></li>
    <li><a href="#">Category 2 </a></li>
    <li><a href="#">Category 3 </a></li>
    <li><a href="#">Category 4 </a></li>
    <li><a href="#">Category 5 </a></li>
    </ul>
    </div>
    <div class="left">
    <h2>support</h2>
    <p>Praesent dapibus, neque id cursus faucibus, tortor neque egestas augue, eu vulputate magna eros eu erat. </p>
    <p><span>support@yoursite.com <br />
    +1 (123) 444-5677</span></p>
    <p><span>sales@yoursite.com <br />
    +1 (123) 444-5678</span></p>
    </div>
    <div class="clr"></div>
    </div>
    <div class="clr"></div>
    </div>
    <div class="footer">
    <div class="footer_resize">
    <p class="leftt"> Copyright YourSiteName. All Rights Reserved<br />
    <a href="#">Home</a> | <a href="#">Contact</a> | <a href="#">RSS</a></p>
    <p class="right">(DT) <a href="http://www.dreamtemplate.com"><strong>Website Templates</strong></a></p>
    <div class="clr"></div>
    </div>
    <div class="clr"></div>
    </div>
    </body>
    </html>

    [CODE]
    Last edited by henry2326; 01-25-2012 at 08:15 PM.

  • #2
    Regular Coder
    Join Date
    Jan 2012
    Posts
    271
    Thanks
    2
    Thanked 65 Times in 65 Posts
    the $your_email variable will be where the email get's sent to... the recipient...


  •  

    Posting Permissions

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