Jump to content

new to this


rockyaj

Recommended Posts

i keep getting the whole script out on the website.am not so familiar with php, hence i got this using a template.so any help would be appreciated. thank you

 

p.s: tried to upload it in .txt but keeps failing so am pasting the whole code:

 

 

<!DOCTYPE HTML>
<html>

<head>
  <title>Contact Us</title>
  <meta name="description" content="website description" />
  <meta name="keywords" content="website keywords, website keywords" />
  <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
  <link rel="stylesheet" type="text/css" href="css/style.css" />
  <!-- modernizr enables HTML5 elements and feature detects -->
  <script type="text/javascript" src="js/modernizr-1.5.min.js"></script>
</head>

<body>
  <div id="main">
    <header>
      <div id="logo">
        <div id="logo_text">
          <!-- class="logo_colour", allows you to change the colour of the text -->
          <h1><a href="index.html">Data<span class="logo_colour">Cryption</span></a></h1>
          <h2> </h2>
        </div>
        <p style="float: right;"><a href="http://www.twitter.com" target="new"><img src="images/twitter.png" alt="twitter" /></a> <a href="http://www.facebook.com" target="new"><img src="images/facebook.png" alt="facebook" /></a> <a href="http://www.rss.com" target="new"><img src="images/rss.png" alt="rss" /></a></p>
      </div>
      <nav>
        <ul class="sf-menu" id="nav">
          <li><a href="index.html">Home</a></li>
          <li><a href="about.html">About Us</a></li>
          <li><a href="products_services.html">Products and Services</a></li>
          <li class="selected"><a href="contact.php">Contact Us</a></li>
        </ul>
      </nav>
    </header>
    <div id="site_content">
      <div id="sidebar_container">
        <div id="gallery">
          <ul class="images">
            <li class="show"><img width="450" height="450" src="images/1.jpg" alt="photo_one" /></li>
            <li><img width="450" height="450" src="images/2.jpg" alt="photo_two" /></li>
          </ul>
        </div>
      </div>
      <div id="content">
        <h1>Contact Us</h1>
        <?php
          // This PHP Contact Form is offered "as is" without warranty of any kind, either expressed or implied.
          // David Carter at www.css3templates.co.uk shall not be liable for any loss or damage arising from, or in any way
          // connected with, your use of, or inability to use, the website templates (even where David Carter has been advised
          // of the possibility of such loss or damage). This includes, without limitation, any damage for loss of profits,
          // loss of information, or any other monetary loss.

          // Set-up these 3 parameters
          // 1. Enter the email address you would like the enquiry sent to
          // 2. Enter the subject of the email you will receive, when someone contacts you
          // 3. Enter the text that you would like the user to see once they submit the contact form
          $to = 'enter email address here';
          $subject = 'Enquiry from the website';
          $contact_submitted = 'Your message has been sent.';

          // Do not amend anything below here, unless you know PHP
          function email_is_valid($email) {
            return preg_match('/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i',$email);
          }
          if (!email_is_valid($to)) {
            echo '<p style="color: red;">You must set-up a valid (to) email address before this contact page will work.</p>';
          }
          if (isset($_POST['contact_submitted'])) {
            $return = "\r";
            $youremail = trim(htmlspecialchars($_POST['your_email']));
            $yourname = stripslashes(strip_tags($_POST['your_name']));
            $yourmessage = stripslashes(strip_tags($_POST['your_message']));
            $contact_name = "Name: ".$yourname;
            $message_text = "Message: ".$yourmessage;
            $user_answer = trim(htmlspecialchars($_POST['user_answer']));
            $answer = trim(htmlspecialchars($_POST['answer']));
            $message = $contact_name . $return . $message_text;
            $headers = "From: ".$youremail;
            if (email_is_valid($youremail) && !eregi("\r",$youremail) && !eregi("\n",$youremail) && $yourname != "" && $yourmessage != "" && substr(md5($user_answer),5,10) === $answer) {
              mail($to,$subject,$message,$headers);
              $yourname = '';
              $youremail = '';
              $yourmessage = '';
              echo '<p style="color: blue;">'.$contact_submitted.'</p>';
            }
            else echo '<p style="color: red;">Please enter your name, a valid email address, your message and the answer to the simple maths question before sending your message.</p>';
          }
          $number_1 = rand(1, 9);
          $number_2 = rand(1, 9);
          $answer = substr(md5($number_1+$number_2),5,10);
        ?>
        <form id="contact" action="contact.php" method="post">
          <div class="form_settings">
            <p><span>Name</span><input class="contact" type="text" name="your_name" value="<?php echo $yourname; ?>" /></p>
            <p><span>Email Address</span><input class="contact" type="text" name="your_email" value="<?php echo $youremail; ?>" /></p>
            <p><span>Message</span><textarea class="contact textarea" rows="5" cols="50" name="your_message"><?php echo $yourmessage; ?></textarea></p>
            <p style="padding: 10px 0; line-height: 2em;">To help prevent spam, please enter the answer to this question:</p>
            <p><span><?php echo $number_1; ?> + <?php echo $number_2; ?> = ?</span><input type="text" name="user_answer" /><input type="hidden" name="answer" value="<?php echo $answer; ?>" /></p>
            <p style="padding-top: 15px"><span> </span><input class="submit" type="submit" name="contact_submitted" value="send" /></p>
          </div>
        </form>
      </div>
    </div>
    <footer>
      <p>Copyright © DataCryption 2013</p>
    </footer>
  </div>
  <!-- javascript at the bottom for fast page loading -->
  <script type="text/javascript" src="js/jquery.js"></script>
  <script type="text/javascript" src="js/jquery.easing-sooper.js"></script>
  <script type="text/javascript" src="js/jquery.sooperfish.js"></script>
  <script type="text/javascript" src="js/image_fade.js"></script>
  <script type="text/javascript">
    $(document).ready(function() {
      $('ul.sf-menu').sooperfish();
    });
  </script>
</body>
</html>

 

Link to comment
Share on other sites

You need to install a http server configured with php to run php code locally.

 

If you're on linux then install Apache and PHP from your linux distros package manager. If you're on mac then you can install MAMP. If you're on windows install WAMP.

Edited by Ch0cu3r
Link to comment
Share on other sites

You need to save the file in C:\wamp\(www or htdocs) folder (which ever one exists) and make sure it has .php extension. Start wampserver, should be an icon in the system tray near the clock, I thinks it a green W or a green semi-colon. if its not green left click it and click start Apache server.

 

If its green then open your browser and go to http://localhost/filename.php to run your php script. 

 

Also make sure Widows is not hiding file extensions. Open Windows Exporer window in any folder and go to Organise > Folder and Search options > View > Untick "Hide extensions for known file types". Click Ok.

Edited by Ch0cu3r
Link to comment
Share on other sites

You need to save the file in C:\wamp\(www or htdocs) folder (which ever one exists) and make sure it has .php extension. Start wampserver, should be an icon in the system tray near the clock, I thinks it a green W or a green semi-colon. if its not green left click it and click start Apache server.

 

If its green then open your browser and go to http://localhost/filename.php to run your php script. 

 

Also make sure Widows is not hiding file extensions. Open Windows Exporer window in any folder and go to Organise > Folder and Search options > View > Untick "Hide extensions for known file types". Click Ok.

 

thanks for the help.now am getting undefined variables

Notice: Undefined variable: yourname in C:\wamp\www\contact.php on line 93 Call Stack #TimeMemoryFunctionLocation 10.0008266112{main}( )..\contact.php:0 " />

Notice: Undefined variable: youremail in C:\wamp\www\contact.php on line 94 Call Stack #TimeMemoryFunctionLocation 10.0008266112{main}( )..\contact.php:0 " />

 

and inside the "message" form i get all the code. as i said this is a template from net and i really have no idea about php but i NEED and HAVE to make this work.

Link to comment
Share on other sites

Add 

          else
          {
            $yourname = '';
            $youremail = '';
            $yourmessage = '';
            $answer = '';
          }

after line 86.

 

For your PHP script to send emails with the mail() function you'll need to configure the php.ini file with your SMTP server address

really thanks a lot. no more errors.now the last part i guess.what did you mean with configuring the php.ini with my smtp? am using winscp client for ftp if that matters..

Link to comment
Share on other sites

hey again guys.i just put my website up.and am trying to figure where to configure the smtp settings but i can't find it.and even on the website i got the "You must set-up a valid (to) email address before this contact page will work." error again.

Link to comment
Share on other sites

If you have your PHP script on your website. Then you shouldn't need to configure the SMTP server, as your webhost should have this all set-up for you.

 

In order for your PHP script to work there is 3 steps it requires you to do. Read lines 52 to line 55. Then set lines 56 - to 58 to what you want them to be.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.