-2

I've been staring at this for almost an hour and as a last resort I was hoping some of you guys might give me a hand figuring out this php code is showing up as regular text in my html file? All help greatly appreciated.

http://jsfiddle.net/YyH27/

<?php
        $name = $_POST['name'];
        $email = $_POST['email'];
        $message = $_POST['message'];
        $from = 'From:'; 
        $to = ''; 
        $subject = 'Hello';
        $human = $_POST['human'];

        $body = "From: $name\n E-Mail: $email\n Message:\n $message";

        if ($_POST['submit'] && $human == '4') {                 
            if (mail ($to, $subject, $body, $from)) { 
            echo '<p>Your message has been sent!</p>';
        } else { 
            echo '<p>Something went wrong, go back and try again!</p>'; 
        } 
        } else if ($_POST['submit'] && $human != '4') {
        echo '<p>You answered the anti-spam question incorrectly!</p>';
        }
    ?>
user3482096
  • 25
  • 2
  • 9
  • 2
    JSfiddle, really, really? – Ryan Apr 06 '14 at 20:44
  • Try changing the extension to .php, some servers are configured not to pass anything to fastcgi unless it ends with .php and it's in a certain path. It's a safer practice than forwarding anything to the php interpreter. – ffflabs Apr 06 '14 at 20:46
  • JSFiddle is for javascript, won't run php at all, your code seems correct to me so i'm pretty sure your server not being setup properly, what server is it (Mac, Windows, ubuntu, CentOS, etc..) ? did you install php on it ? – Mostafa Berg Apr 06 '14 at 20:47

3 Answers3

1

I really only see two possibilities:

a) You are not running it on a server, but on your local PC. If that is the case and you don't have acces to websapce, look at WAMP (windows) or MAMP (Mac)

b) You have a .html-file-extension instead of .php

If it's neither of these, give us more information about where you're runnng the script, how it's saved and everything. Php should never show up as plain text because of an error inside the php - merley because of errors surrounding the php.

Kjeld Schmidt
  • 771
  • 8
  • 19
1

First off, jsfiddle will not run PHP.

Second, it sounds like your PHP server is not configured properly.

ElGavilan
  • 6,610
  • 16
  • 27
  • 36
1

If this is in a .html file, you need to configure your webserver to run html through PHP.

If you're expecting JSFiddle to run your PHP, they do not do that.

Community
  • 1
  • 1
rockerest
  • 10,412
  • 3
  • 37
  • 67