Topic: SOS! PHP Email processing script returns "500 - Internal Server Error"

Hi, I am in urgent need of some professional advice,  I needed an online
form to send some info to me on my site, so
I found a tutorial for setting up a form with dreamweaver cs4, and
writing a PHP script to email it to my inbox, and then view a page
after it has been sent.

However, when the site was uploaded and I tested the form I get a
error message:

 

*500 - Internal server error.*

*There is a problem with the resource you are looking for, and it
cannot be displayed.*

 
In addition to this, I do get an email come through (sometimes), but
it does not have the user data entered in form. The body is there,
just no data!

I have seen loads of blogs and forums, but nothing has been able to
resolve the issue, please can you help? The script is exactly as the
tutorial demonstrates, and the guy even shows it working.  Obviously I
have entered my own variables.  If it helps the tutorial is from
www.tutvid.com -  choose the tutorials tab , then
dreamweaver, and its near the bottom.
If you can help, I would be forever in your debt.

Here is the PHP script. The form action directs to the script and the
method is POST.

<?php

/* Subject and Email Variables */

    $emailSubject = 'General Web Enquiry';
    $webMaster = 'enquiries@kyu-images.com';
   
/* Gathering Data Variables */

    $nameField = $_POST['name'];
    $emailField = $_POST['email'];
    $address1Field = $_POST['address1'];
    $address2Field = $_POST['address2'];
    $townField = $_POST['town'];
    $postcodeField = $_POST['postcode'];
    $phoneField = $_POST['phone'];
    $serviceField = $_POST['service'];
    $brochureField = $_POST['brochure'];
    $aboutusField = $_POST['aboutus'];
    $oursiteField = $_POST['oursite'];
    $commentsField = $_POST['comments'];
   
    $body = <<<EOD
<br><hr><br>
Name: $name <br>
Email: $email <br>
First Address Line: $address1 <br>
Second Address Line: $address2 <br>
Address Town: $town <br>
Postcode: $postcode <br>
Telephone: $phone <br>
Service Enquiry: $service <br>
Send Brochure: $brochure <br>
How Did They Find Us: $aboutus <br>
Did They Like Our Site: $oursite <br>
Client Comments: $comments <br>
<br><hr><br>
EOD;

    $headers = "From: $email\r\n";
    $headers .= "Content-type: text/html\r\n";
    $success = mail($webMaster, $emailSubject, $body, $headers);
   
/*Results Rendered As HTML */

    $theResults = <<<EOD
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Kyu Images | Web Design | Logo Design | Brand Image | Photography</title>
<link href="../css/main_layout.css" rel="stylesheet" type="text/css" />
<link href="../css/servicepage_layout.css" rel="stylesheet" type="text/css" />
<link href="../css/bracket.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
a:link {
text-decoration: none;
color: #000;
}
a:visited {
text-decoration: none;
color: #000;
}
a:hover {
text-decoration: none;
color: #000;
}
a:active {
text-decoration: none;
color: #000;
}
-->
</style></head>
<body>
<div id="wrapper">
<div id="banner">
<div id="title">
<h1 align="center"><span class="bracket">[</span> Contact Us <span class="bracket">]</span></h1>
</div>
<div id="navigationbar">
<div align="center">
<h2>Thank your email, it has been successfully sent. We shall soon receive it and will respond as soon as possible.</h2>
</div>
</div>
</div>
<div id="mainbody">
<div id="content">
<p>If your query requires an urgent reply, or you already have a project underway with us, you can email directly to the relevent person:</p>
<p>Concept Arts : conceptarts@kyu-images.com</p>
<p>Web Concepts : webconcepts@kyu-images.com</p>
<p>Photography : photography@kyu-images.com</p>
<p>Enquiries : enquiries@kyu-images.com</p>
<p>&nbsp;</p>
<p>Or telephone : 01502 281284 between 09:00 - 18:00 Monday to Friday, and 10:00 - 15:00 Saturday.</p></div>
<div id="levels">
<h2 align="right">Please choose where to go next:</h2>
<p align="right"><span class="bracket">[</span> <a href="../index.html" target="_parent">Home</a> <span class="bracket">]</span></p>
<p align="right"><span class="bracket">[</span> <a href="../about_us.html" target="_parent">About Us</a> <span class="bracket">]</span></p>
<p align="right"><span class="bracket">[</span> <a href="../corporate-identity/web_design.html" target="_parent">Web Design</a> <span class="bracket">]</span></p>
<p align="right"><span class="bracket">[</span> <a href="../corporate-identity/logo_design.html" target="_parent">Logo Design</a> <spanclass="bracket">]</span></p>
<p align="right"><span class="bracket">[</span> <a href="../corporate-identity/brand_image.html" target="_parent">Brand Imaging</a> <span class="bracket">]</span></p>
<p align="right"><span class="bracket">[</span> <a href="../photography/photography.html" target="_parent">Photography</a> <span class="bracket">]</span></p>
</div>
</div>
<div id="mininav">
<div align="center"></div></div>
</div>
</body>
</html>
EOD;
echo "$theResults";


?>

Re: SOS! PHP Email processing script returns "500 - Internal Server Error"

The script itself seems to be fine... at least, I'm not seeing any significant coding issues.  As a start, perhaps try creating a new file with these contents (replace the email address), and uploading it to your server:

mailtest.php:

<?php mail('youremailhere', 'My Subject', 'A test message');  ?>

Open that up in your browser, and see if you still get the error. I'm just trying to check that the mail() function works correctly before debugging the script further.

Re: SOS! PHP Email processing script returns "500 - Internal Server Error"

My host did that already and it worked fine - I wondered if it was an issue with the hosts server, but they seem to think the issue must come my side!

Re: SOS! PHP Email processing script returns "500 - Internal Server Error"

Ok I found a script on the net that should send data from any form without knowing much about it, kind of a generic handler.  I copied and uploaded, set the form action to follow it, and tested it.

It returned a failed to send message. (the message is coded in the PHP for failure to send the message).

So to it looks more likely an external problem?????  The script I tried is:

<?php
   if ($_SERVER['REQUEST_METHOD']=="POST"){
      // In testing, if you get an Bad referer error
      // comment out or remove the next three lines
      if (strpos($_SERVER['HTTP_REFERER'], $_SERVER['HTTP_HOST'])>7 ||
         !strpos($_SERVER['HTTP_REFERER'], $_SERVER['HTTP_HOST']))
         die("Bad referer");
      $msg="Values submitted by the user:\n";
      foreach($_POST as $key => $val){
         if (is_array($val)){
            $msg.="Item: $key\n";
            foreach($val as $v){
               $v = stripslashes($v);
               $msg.="   $v\n";
            }
         } else {
            $val = stripslashes($val);
            $msg.="$key: $val\n";
         }
      }
      $recipient="enquiries@kyu-images.com";
      $subject="General Web Enquiry";
      error_reporting(0);
      if (mail($recipient, $subject, $msg)){
         echo "<h1>Thank you</h1><p>Message successfully sent:</p>\n";
         echo nl2br($input);
      } else
         echo "An error occurred and the message could not be sent.";
   } else
      echo "Bad request method";
?>