rockyaj Posted September 30, 2013 Share Posted September 30, 2013 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> Quote Link to comment https://forums.phpfreaks.com/topic/282570-new-to-this/ Share on other sites More sharing options...
Psycho Posted September 30, 2013 Share Posted September 30, 2013 Is the file named as a *.php file on the web server? Is the web sever configured to support PHP? Are you accessig the file through a webserver and not just opening it in your browser directly from your file system? Quote Link to comment https://forums.phpfreaks.com/topic/282570-new-to-this/#findComment-1451881 Share on other sites More sharing options...
rockyaj Posted September 30, 2013 Author Share Posted September 30, 2013 i am accessing on my browser locally...oh come on.don't let me turn out to be that silly so if am using a php supported server,then that's fine? yes it's a .php file.how can i test it locally? Quote Link to comment https://forums.phpfreaks.com/topic/282570-new-to-this/#findComment-1451885 Share on other sites More sharing options...
Ch0cu3r Posted September 30, 2013 Share Posted September 30, 2013 (edited) 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 September 30, 2013 by Ch0cu3r Quote Link to comment https://forums.phpfreaks.com/topic/282570-new-to-this/#findComment-1451886 Share on other sites More sharing options...
rockyaj Posted September 30, 2013 Author Share Posted September 30, 2013 i just installed wamp but still when i load the page, i get the code instead of the form... Quote Link to comment https://forums.phpfreaks.com/topic/282570-new-to-this/#findComment-1451894 Share on other sites More sharing options...
Ch0cu3r Posted September 30, 2013 Share Posted September 30, 2013 (edited) 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 September 30, 2013 by Ch0cu3r Quote Link to comment https://forums.phpfreaks.com/topic/282570-new-to-this/#findComment-1451896 Share on other sites More sharing options...
rockyaj Posted September 30, 2013 Author Share Posted September 30, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/282570-new-to-this/#findComment-1451897 Share on other sites More sharing options...
Ch0cu3r Posted September 30, 2013 Share Posted September 30, 2013 (edited) 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 Edited September 30, 2013 by Ch0cu3r Quote Link to comment https://forums.phpfreaks.com/topic/282570-new-to-this/#findComment-1451904 Share on other sites More sharing options...
rockyaj Posted September 30, 2013 Author Share Posted September 30, 2013 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.. Quote Link to comment https://forums.phpfreaks.com/topic/282570-new-to-this/#findComment-1451913 Share on other sites More sharing options...
Ch0cu3r Posted September 30, 2013 Share Posted September 30, 2013 No by smtp i mean the mail server you're using to send emails. PHP needs to configured to use a mail sever to send emails Quote Link to comment https://forums.phpfreaks.com/topic/282570-new-to-this/#findComment-1451915 Share on other sites More sharing options...
rockyaj Posted September 30, 2013 Author Share Posted September 30, 2013 ya i got what the smtp meant.but i just meant if i had to configure that locally or on the hosting website? Quote Link to comment https://forums.phpfreaks.com/topic/282570-new-to-this/#findComment-1451916 Share on other sites More sharing options...
Psycho Posted September 30, 2013 Share Posted September 30, 2013 ya i got what the smtp meant.but i just meant if i had to configure that locally or on the hosting website? Either one - just so long as your PHP installation can connect to that server. Quote Link to comment https://forums.phpfreaks.com/topic/282570-new-to-this/#findComment-1451919 Share on other sites More sharing options...
rockyaj Posted September 30, 2013 Author Share Posted September 30, 2013 Either one - just so long as your PHP installation can connect to that server. thank you guys so much.once my web hosting verifies so i can upload the site and try all out, i'll let you know how it goes.thanks plenty really Quote Link to comment https://forums.phpfreaks.com/topic/282570-new-to-this/#findComment-1451920 Share on other sites More sharing options...
rockyaj Posted October 1, 2013 Author Share Posted October 1, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/282570-new-to-this/#findComment-1451993 Share on other sites More sharing options...
Ch0cu3r Posted October 1, 2013 Share Posted October 1, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/282570-new-to-this/#findComment-1451998 Share on other sites More sharing options...
rockyaj Posted October 1, 2013 Author Share Posted October 1, 2013 that had slipped my mind as i had omitted the email address when i pasted here and forgot to repost it thank you Quote Link to comment https://forums.phpfreaks.com/topic/282570-new-to-this/#findComment-1452013 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.