-1

I've been trying to add some php code to make my html document send an email based on the form the user puts in but I can't get the connection between php and html to work. Using WAMP and I have a .htaccess file that looks like the following:

RewriteEngine on

RewriteRule ^index$ index.php
AddType application/httpd-php .htm .html

When I go to my webpage and enter my name, email and a message I get this on my browser instead of "You've gotten mail" or something.:

enter image description here

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
  • You can't run PHP in a .html file, you'd need to change the extension to .php – Mark Jan 22 '20 at 10:21
  • 1
    How do you acce to your php page? something like _localhost/your-project/page.php_? – Sfili_81 Jan 22 '20 at 10:21
  • 1
    @MarkOverton, this is not exactly true as you can configure the webserver to process any extension via PHP interpreter, including `.html` or even `.overton` :) – mitkosoft Jan 22 '20 at 10:25
  • @mitkosoft interesting – Mark Jan 22 '20 at 10:27
  • @MarkOverton, more here: https://www.thegeekstuff.com/2014/03/php-custom-file-extension/ – mitkosoft Jan 22 '20 at 10:28
  • Please do not post code as an _image of_ code. Show it in text form & properly formatted. – 04FS Jan 22 '20 at 10:42
  • `AddType application/httpd-php .htm .html` <- the OP is already attempting to force Apache to interpret *.html* files as PHP (which means it should crank up the PHP interpreter). – CD001 Jan 22 '20 at 10:53
  • I posted img to show how my browser reacts. So if I change file to index.php and $_post to $_POST it should work? I tried it now and that didn't do it. is my include right above my form btw – Jesper Olausson Jan 22 '20 at 11:07
  • Don't upload images of text. That is very difficult to read, and for the visually impaired it can be impossible to read. It also can't be indexed or searched. Please copy-paste the text directly instead. – Jonathan Hall Feb 13 '20 at 22:07

1 Answers1

0

You should try and change $_post into $_POST. Variables are case sensitive in PHP. So, with $_post you are referring to something different from $_POST - the super global. Also, I'm not quite sure about header("Location: index.php?mailsend"). Usually you would want to provide a value for URL parameters, like index.php?mailsend=true.

EDIT: Take a look at this question discussion as well. They discuss a similar problem to what you have: page shows PHP code instead of executing it. The answer in there details multiple potential fixes for an issue like this. There is likely an issue with your server configuration. Plus, there are more sources that you can find, similar to that, like this article.

Evgenii Klepilin
  • 695
  • 1
  • 8
  • 21