Pages: 12Next
Current Page: 1 of 2
PHP files being read as HTML?
Posted by: chris2307 (---.bb.sky.com)
Date: March 24, 2011 12:23AM

HI all,

I am fairly new to php so please bare with me.

I have installed WAMP server to test out a php file which I was hoping would process a form and send it to my email address. I have created the form in HTML and linked the button to the php file which works ok.

Just to test, I created a simple little bit of code to check that it would send me an email

<?php

$to = "email@address.com";
$subject = "test";
$message = "Hello, this is a simple test message!";

mail($to,$subject,$message);
echo "Mail Sent.";


?>

However, when I click on the submit button from the form, the browser displays all of the code and an email is not sent which leads me to believe that it is being read as html. Any thoughts?

I am using Opera internet browser (but this also happens in IE).

Regards

Chris

Options: ReplyQuote
Re: PHP files being read as HTML?
Posted by: yfastud (Moderator)
Date: March 24, 2011 03:06AM

Wamp does NOT come with mail and make sure your php file does not have hidden .txt extension

To setup Website w/ Wamp, follow this
[blog.jlbn.net]

Have fun,

FREE One A Day
FREE Photo
FREE Games
FREE Websites
FREE Portable GPS
FREE WAMP Guides

Options: ReplyQuote
Re: PHP files being read as HTML?
Posted by: chris2307 (95.148.155.---)
Date: March 24, 2011 09:54PM

Hi, I am only trying to test the code for now in WAMP,

The site will be hosted elsewhere. However, even a simple

<?php echo
"hello";
?>

will not work. Just the code is displayed within the browser. The file definitely doesn't have a hidden .txt extension (I wrote the file in notepad++).

I have tried both WAMP 2.1 and WAMP5. All services seem to be running and the icon in the system tray is green. I can't see why this won't work?! sad smiley

Thanks for your reply

Options: ReplyQuote
Re: PHP files being read as HTML?
Posted by: stevenmartin99 (---.b-ras1.srl.dublin.eircom.net)
Date: March 24, 2011 09:57PM

well you must be doing something wrongsmiling smiley

you sure your putting the files in c:\wamp\www and using http:\\localhost\file.php ?

Steven Martin
stevenmartin99@gmail.com
stevenmartin99@hotmail.com
PampServer.com - [pampserver.com]

Options: ReplyQuote
Re: PHP files being read as HTML?
Posted by: lee-wampie (---.tstt.net.tt)
Date: March 25, 2011 10:57PM

hey Chris,

I'm a Newbie to php/apache,mysql .
Windows XP SP2 , Firefox 3.6.x

There are a few things that I had to do to get php files to open on my system. In addition to the help given on here.

I had to make sure that the system variable PATH had
;c:\wamp\www tacked on to the end of the existing path.

I had to change the properties of the default website in IIS so that the port was set to 8080 (choose a free port. this was what was free for mines) and also under one of the tabs has accepted file types such as index.html, index.asp.etc. There should be index.php listed there (if not create it) and then shift it to the top of the list.. thus making it a default for your system.. (Yes your html pages will still work.)

Restart System

I created a folder called TestSite in the www folder in wamp folder. Opened a new Text document. And typed in a similar code to what you have. And then I clicked. File --Save as--> And named the file index.php

Restart System. Hope this helps.

Always System Restore Point and Backup first before waging battle with any opponent.

Options: ReplyQuote
Re: PHP files being read as HTML?
Posted by: stevenmartin99 (---.b-ras1.srl.dublin.eircom.net)
Date: March 25, 2011 11:23PM

please stop post the advice about the system variable PATH..

this is incorrect advice. We dont want people going there messing their machines up when its not needed

thanks

Steven Martin
stevenmartin99@gmail.com
stevenmartin99@hotmail.com
PampServer.com - [pampserver.com]

Options: ReplyQuote
Re: PHP files being read as HTML?
Posted by: lee-wampie (---.tstt.net.tt)
Date: March 26, 2011 05:14AM

Sorry about that steve. I understand your concern.

Options: ReplyQuote
Re: PHP files being read as HTML?
Posted by: julius villapando (121.54.32.---)
Date: March 02, 2012 03:04PM

in order for you to test your php file, you should open first your web browser and type in localhost. then make sure your php file is inside the www folder. the wamp server should be on.

EXAMPLE:

TYPE this in your browser,

localhost/filename.php

that should solve your problem.

Options: ReplyQuote
Re: PHP files being read as HTML?
Posted by: RiggsFolly (---.as13285.net)
Date: March 02, 2012 05:01PM

Julius,

This sounds to me like you have creates a file like test.html i.e. with HTML as the extension.

Change the file name to test.php and try again.


Whats happening is:

you enter test.html and apache say yes I see that I will send it back to the browser. But thats all it does!

If you code the file as test.php apache says, Yes I see that... Oh its a PHP file I will send that to the PHP interpreter for pre-processing. PHP then compiles and runs the code between the <?php and ?> tags and sends the results along with the raw HTML back to the apache and it send it to the browser.


There is a setting in the apache config like this

AddType application/x-httpd-php .php

that tells apache to send files with a .php extension to the php interpreter.
You can add another to make apache send .html files to the php processor but it probably not a good idea unless you have to for some reason.

Options: ReplyQuote
Re: PHP files being read as HTML?
Posted by: julius villapando (121.54.32.---)
Date: April 11, 2012 05:03AM

Riggsfolly,

I think you misunderstood me. I dont have any problem in running my php file. but thanks anyway.

Options: ReplyQuote
Re: PHP files being read as HTML?
Posted by: RiggsFolly (---.as13285.net)
Date: April 11, 2012 04:21PM

Julius,

I was posting to Chris2307 not you.

But thanks for the thanks.

Options: ReplyQuote
Re: PHP files being read as HTML?
Posted by: julius villapando (121.54.32.---)
Date: April 14, 2012 04:35AM

Riggsfolly,

Oh, i see.
But your post on March 02 was addressed to me not to Chris2307.

Options: ReplyQuote
Re: PHP files being read as HTML?
Posted by: julius villapando (121.54.32.---)
Date: April 14, 2012 04:35AM

Riggsfolly,

Oh, i see.
But your post on March 02 was addressed to me not to Chris2307.



Edited 1 time(s). Last edit at 06/17/2012 03:40AM by julius villapando.

Options: ReplyQuote
Re: PHP files being read as HTML?
Posted by: encadyma (---.socal.res.rr.com)
Date: April 16, 2012 07:07AM

use mozilla…

Options: ReplyQuote
Re: PHP files being read as HTML?
Posted by: RiggsFolly (---.as13285.net)
Date: April 17, 2012 01:37PM

Julius,

Oh yes so it was, my confused old brain having a senior moment.

My mistake completely.

Options: ReplyQuote
Re: PHP files being read as HTML?
Posted by: rmanzano216 (---.prod-infinitum.com.mx)
Date: April 17, 2012 09:37PM

i have almost the same problem that chris

my wamp is running, i have an index page already in www, i've created my database,tables,etc, but not even a simple "hello world" php script run well .. i don't know why


php 5.3.10
win7

Options: ReplyQuote
Re: PHP files being read as HTML?
Posted by: stevenmartin99 (Moderator)
Date: April 17, 2012 09:40PM

use <?php tags and make sure the file is called .php and make sure you dont just click the file to open it

use the browser to open it

Steven Martin
stevenmartin99@gmail.com
stevenmartin99@hotmail.com
PampServer.com - [pampserver.com]

Options: ReplyQuote
Re: PHP files being read as HTML?
Posted by: rmanzano216 (---.prod-infinitum.com.mx)
Date: April 17, 2012 10:31PM

yes i did

i put this in a php file

first hello<br>

<?php

echo "Second hello";

?>

when i open it from the browser i just got

first hello

and that's it, where the php code goes to¿ ?

Options: ReplyQuote
Re: PHP files being read as HTML?
Posted by: stevenmartin99 (Moderator)
Date: April 17, 2012 10:35PM

How are you opening it in the browser?

Steven Martin
stevenmartin99@gmail.com
stevenmartin99@hotmail.com
PampServer.com - [pampserver.com]

Options: ReplyQuote
Re: PHP files being read as HTML?
Posted by: Teegirl (---.range86-186.btcentralplus.com)
Date: May 19, 2012 05:34PM

I am a newbie, Read through the thread because i have the same issue but didnt solve my problem. I embbeded php code in html and saved as .php, but when i try to open in the browser it does not open. i get the error HTTP 404 - File not found.

Options: ReplyQuote
Pages: 12Next
Current Page: 1 of 2


Sorry, only registered users may post in this forum.