hello
i have create some webpages they work and are nice but when i click in contat form which contain php code inside
it display all code which are inside.

<?php

// Set email variables
$email_to = '';
$email_subject = 'Form submission';

// Set required fields
$required_fields = array('fullname','email','comment');

// set error messages
$error_messages = array(
    'fullname' => 'Please enter a Name to proceed.',
    'email' => 'Please enter a valid Email Address to continue.',
    'comment' => 'Please enter your Message to continue.'
);

// Set form status
$form_complete = FALSE;

// configure validation array
$validation = array();

// check form submittal
if(!empty($_POST)) {
    // Sanitise POST array
    foreach($_POST as $key => $value) $_POST[$key] = remove_email_injection(trim($value));

    // Loop into required fields and make sure they match our needs
    foreach($required_fields as $field) {       
        // the field has been submitted?
        if(!array_key_exists($field, $_POST)) array_push($validation, $field);

        // check there is information in the field?
        if($_POST[$field] == '') array_push($validation, $field);

        // validate the email address supplied
        if($field == 'email') if(!validate_email_address($_POST[$field])) array_push($validation, $field);
    }

    // basic validation result
    if(count($validation) == 0) {
        // Prepare our content string
        $email_content = 'New Website Comment: ' . "\n\n";

        // simple email content
        foreach($_POST as $key => $value) {
            if($key != 'submit') $email_content .= $key . ': ' . $value . "\n";
        }

        // if validation passed ok then send the email
        mail($email_to, $email_subject, $email_content);

        // Update form switch
        $form_complete = TRUE;
    }
}

function validate_email_address($email = FALSE) {
    return (preg_match('/^[^@\s]+@([-a-z0-9]+\.)+[a-z]{2,}$/i', $email))? TRUE : FALSE;
}

function remove_email_injection($field = FALSE) {
   return (str_ireplace(array("\r", "\n", "%0a", "%0d", "Content-Type:", "bcc:","to:","cc:"), '', $field));
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>



    <title>Contact Form</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <script type="text/javascript">
var nameError = '<?php echo $error_messages['fullname']; ?>';
        var emailError = '<?php echo $error_messages['email']; ?>';
        var commentError = '<?php echo $error_messages['comment']; ?>';
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
    </script>


<link href="contact/css/contactcss.css" rel="stylesheet" type="text/css" />
</head>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/mootools/1.3.0/mootools-yui-compressed.js"></script>
<script type="text/javascript" src="contact/validation/validation.js"></script>

<body onload="MM_preloadImages('contact/images/x.png')">

<div id="ForWrap">
<h2>We Appreciate your Fedback </h2>
<div id="form">
<?php if($form_complete === FALSE): ?>

<form action="contact.php" method="post" id="comments-form">
<div class="row">
<div class="label">Your Name</div><!--End of Label-->
<div class="input">
<input type="text" id="fullname" class="detail" name="fullname" value="<?php echo isset($_POST['fullname'])? $_POST['fullname'] : ''; ?>" /><?php if(in_array('fullname', $validation)): ?><span class="error"><?php echo $error_messages['fullname']; ?></span><?php endif; ?>
</div><!--End of input-->
<div class="context">e.g Andi Bevapi ose John Smith</div><!--End Of Context-->
</div><!--End of row-->


<div class="row">
<div class="label">Your Email</div><!--End of Label-->
<div class="input">
<input type="text" id="email" class="detail" name="email" value="<?php echo isset($_POST['email'])? $_POST['email'] : ''; ?>" /><?php if(in_array('email', $validation)): ?><span class="error"><?php echo $error_messages['email']; ?></span><?php endif; ?>
</div><!--End of input-->
<div class="context">nuk do keqperdorim adresen tende dhe nuk do te shajme</div><!--End Of Context-->
</div><!--End of row-->


<div class="row">
<div class="label">Your Message</div><!--End of Label-->
<div class="input2">
<textarea id="comment" name="comment" class="mess"><?php echo isset($_POST['comment'])? $_POST['comment'] : ''; ?></textarea><?php if(in_array('comment', $validation)): ?><span class="error"><?php echo $error_messages['comment']; ?></span><?php endif; ?>

</div><!--End of input-->
</div><!--End of row-->

<div class="submit">
<input type="submit" id="submit" name="submit" value="Send Message" />
</div><!--End of Sumit-->
</form>
<?php else: ?>
<p style="size:35px; font-family:Arial, Helvetica, sans-serif ; color:#255E67 ; margin-left:25px;">Thank you for your Message!</p>
<script type="text/javascript">
setTimeout('ourRedirect()', 5000)
function ourRedirect(){
    location.href='ApiSite.html'<!--Tek index do te vendose faqja e pare HOME -->
    }


</script>
<?php endif; ?>

</div><!--End Of form-->
</div><!--End Of FormWrap-->



</body>
</html>

These files that you say you see the actual code.. they are saved as .php and not another extension like .txt or .htm?

so i have create a folder in xampp which contain all the project i have done all the configuration of the site ect ect in adobe dreamweaver cs6.

i copied that folder and paste it in desktop now the contact page doesnt work it show a lot of code when i click it.
any idea how i can fix that

Sounds like you move the php code out side of the php xampp. if the page is contact.php you need to have the file run through xampp or some sort of web server. You can not run php files on your desktop with out the help of php engine and a web server. Place the files back into xampp or upload to live web server.

yeahh you have write :) but when i send this project with email the contact form did not work.how i can fix this error

I dont understand what you mean, " but when I send this project with email the contact form did not work" What is the problem.. You said you remove the files from xampp htdocs folder? If so, then you need to put back in. Also if you are using mail() function or send mail. you need to set up the send mail feature on your xampp server. By default send mail does not work. (so one correct me if Im wrong). You may need to install the send_mail lib.

for exmaple give me your email and i will send this project which contain the contact form.all the other page work great but when you click in the contact form it didnt work.
i wont to send this project to someone but he didnt have xampp in pc and the contact form will not work now how i can fix this

Member Avatar

diafol

for exmaple give me your email and i will send this project which contain the contact form.all the other page work great but when you click in the contact form it didnt work.
i wont to send this project to someone but he didnt have xampp in pc and the contact form will not work now how i can fix this

That makes little sense, but if you're asking to send your work to somebody via email so they can check it for you - that's not what this site is about.

Your thread has received few replies due to the fact that you are not able to express yourself sufficiently. English is obviously not your first language, so this may be difficult for you.

If you are using XAMPP - all the php files need to be in the htdocs directory
and you access them via the http://localhost url.

Alternatively if you want to have multiple sites set up under xampp, you need to have virtual hosts. Assuming XAMPP is installed at c:\xampp

e.g. to set up a site called "mynewsite". Go to the c:\xampp\htdocs directory and create a new folder: c:\xampp\htdocs\mynewsite

Next open the file: C:\xampp\apache\conf\extra\httpd-vhosts.conf

Open this file in a text editor and you should see...

#
# Virtual Hosts
#
# If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at 
# <URL:http://httpd.apache.org/docs/2.2/vhosts/>
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.

#
# Use name-based virtual hosting.
#
##NameVirtualHost *:80

#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
#
##<VirtualHost *:80>
    ##ServerAdmin postmaster@dummy-host.localhost
    ##DocumentRoot "C:/xampp/htdocs/dummy-host.localhost"
    ##ServerName dummy-host.localhost
    ##ServerAlias www.dummy-host.localhost
    ##ErrorLog "logs/dummy-host.localhost-error.log"
    ##CustomLog "logs/dummy-host.localhost-access.log" combined
##</VirtualHost>

##<VirtualHost *:80>
    ##ServerAdmin postmaster@dummy-host2.localhost
    ##DocumentRoot "C:/xampp/htdocs/dummy-host2.localhost"
    ##ServerName dummy-host2.localhost
    ##ServerAlias www.dummy-host2.localhost
    ##ErrorLog "logs/dummy-host2.localhost-error.log"
    ##CustomLog "logs/dummy-host2.localhost-access.log" combined
##</VirtualHost>

NameVirtualHost *:80
  <VirtualHost *:80>
    DocumentRoot "C:/xampp/htdocs"
    ServerName localhost
  </VirtualHost>

Add the following below this...

<VirtualHost *:80>
    DocumentRoot "C:/xampp/htdocs/mynewsite"
    ServerName mynewsite
  <Directory "C:/xampp/htdocs/mynewsite">
    Order allow,deny
    Allow from all
  </Directory>
</VirtualHost>

Save the file
Then open the file: C:\Windows\System32\drivers\etc\hosts
And you should see...

# Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
#      102.54.94.97     rhino.acme.com          # source server
#       38.25.63.10     x.acme.com              # x client host

# localhost name resolution is handled within DNS itself.
    127.0.0.1       localhost
    ::1             localhost

Below that just add...

127.0.0.1   mynewsite

Save the file.

When you create a new virtual host, you'll need to stop and restart Apache.

You should be able to access your new site: http://mynewsite/

As already mentioned if you have php code, it should be contained in a file with the .php extansion. There are ways to run php in other types of file, but there isn't any need as far as I can see in your project.

Hope it helps.

commented: great explanation. +12

now i can aces to the site by writing 127.0.0.1 (name of the site).
is this correct have i done it well?
by the way i have 2 years here and you have help me a lot thank you from my hart

Write PHP header and XML header in line 65
header("Content-type:text/html;charset=utf-8");
print "<?xml version=\"1.0\" encoding=\"utf-8\"?>";

AndriP this example didnt work thanks by the way