0

I'm hosting a website on a Linux server, running Ubuntu Server 11.04 (32 bit). The web server is Apache. One of the pages on the site has a form with the submit linking to a PHP email script. Form code:

<form id="contact_form" method="post" action="email.php">
<table>
<tr>
<td>Name:</td>
<td><input type="text" id="name" class="textbox"/></td>
</tr>
<tr>
<td>Email:</td>
<td><input type="text" id="email" class="textbox"/></td>
</tr>
</table>
<div id="message_box_header">Describe your problem:<br /></div>
<textarea class="textbox"></textarea><br />
<input type="submit" value="Submit!" id="submit" />
</form>

The Linux server has the most up to date version of sendmail. I don't know PHP well at all and got the script pre-written, so I imagine my problem is probably there. I replaced the website/emails with dummy ones, for privacy. Here's email.php:

<?php
  $email = $_REQUEST['email'] ;
  $message = $_REQUEST['message'] ;

  mail( "[email protected]", "Form Data",
    $message, "From: $email" );
  header( "Location: http://mywebsite.com" );
?>

When I click the submit button on the actual website, it just downloads email.php.

3
  • Allow it to download and then open the file. If you see PHP code then PHP is not being interpreted on your server. So it would be a configuration issue or possible a host that for some odd reason does not have PHP. Commented Dec 30, 2012 at 18:14
  • Do you have any other PHP on the site? Try to omit the ?> at the end and add exit; to the end. Commented Dec 30, 2012 at 18:16
  • Side note: use $_POST instead of $_REQUEST for post data, and use $_GET for get data. Commented Dec 30, 2012 at 18:21

3 Answers 3

2

Make sure PHP is actually installed on your server (that should be the first thing you do, following cryptic's instructions).

If it is installed, and you're still having the problem, add this to your apache config (.htaccess):

AddType application/x-httpd-php .php 
Sign up to request clarification or add additional context in comments.

5 Comments

Hmm. Installed PHP5 and appended that line to httpd.conf and still no change. So if the site is just downloading the script as is, that's definitely a problem in the server, and not (necessarily) in the script?
Very most probably a server issue. When you open the downloaded file with a text editor, do you see PHP code or just HTML?
Yes. It's the same file, 'email.php'.
Can you try this in your httpd.conf? SetHandler application/x-httpd-php Also, don't forget to restart Apache when you edit httpd.conf
Right. That restart fixed it. Thanks for the help!
0

You should set the name attribute of your input fields instead of id. Otherwise no data is sent. If the file is being downloaded this is a configuration error of the webserver not the script.

Comments

0

update your package manger by running this command:

apt-get update

and install mod_fcgid and php5-cgi by running this command:

apt-get install libapache2-mod-fcgid php5-cgi

mod_fcgid will be enabled by installer otherwise run this command to enable it:

a2enmod fcgid

now you can add these pre configed lines to your apache config file:

AddHandler fcgid-script .php
FcgidIOTimeout 3600
FcgidInitialEnv PHP_FCGI_MAX_REQUESTS 1000 
FcgidMaxRequestLen 52428800
FcgidConnectTimeout 3600
FcgidMaxProcesses 12
FcgidOutputBufferSize 64
FcgidProcessLifeTime 3600
FcgidMaxRequestsPerProcess 500
FcgidMinProcessesPerClass 0
FcgidWrapper /usr/bin/php-cgi .php

your apache config file may be available at /etc/apache2/apache2.conf

for more information about fast cgi handler see: http://httpd.apache.org/mod_fcgid/mod/mod_fcgid.html

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.