Page 1 of 1

PHP Postcard error Message:

Posted: Thu Aug 12, 2010 10:45 am
by norwichchris
Hi,
I am currently designing a PHP postcard system as voluntary work. The script basically works but when you click on the link i get the error message:

Internal Server Error, this is an error with your script, check your error log for more information.

See code Below:

Code: Select all

<?php
session_start();
// CHANGE PARAMETERS HERE BEGIN
$senderName  = " Holidays From Home "; // Eg.: John's Postcards
$senderEmail = " Sender Email Address ";  // Eg.: john@postcard.com
// Change only if you have problems with urls
$postcardURL = "http://".$_SERVER["HTTP_HOST"].$_SERVER["SCRIPT_NAME"];
// CHANGE PARAMETERS HERE END
$result = 0;
$msg = "";
$msg1 = "";
$pic = "";
function displayPhotos()
{
 global $pic;
 $columns = 5;
 $act = 0;
 $act1 = 0;
 // Open the actual directory
 if($handle = opendir("thumbs"))
 {
  // Read all file from the actual directory
  while($file = readdir($handle))
  {
   if(!is_dir($file))
   {
    if(isset($pic[1]))
    {
     if($pic[1] == $act1){$sel = "checked";}
     else{$sel = "unchecked";}
     }
    if($act == 0){echo "<tr>";}
    echo "<td align='center'><img src='thumbs/$file' alt='postcard' /><br/><input type='radio' name='selimg' value='$file,$act1' $sel /></td>";
    $act++;
    $act1++;
    if($act == $columns){$act = 0;echo "</tr>";}
       }
    }
  echo "</tr>";
  }    
 }
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
<html>
<head>
 <title>Micro Postcard</title>
 <link href= "style/style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="main">
<div class="style1" id="caption">
<div align="left" class="style1"></div>
</div>
   <?php //makes sure form is correctly filled in 
 if(!empty($_POST["submit"]))
 {
  if(empty($_POST["selimg"])){$msg = "Please select an image from above!";$result = 3;}
  else{$pic = explode(",",$_POST["selimg"]);}
  if(empty($_POST["email"]) && empty($result)){$msg1 = "You must enter an email address!";$result = 3;}
  $secCode = empty($_POST["secCode"]) ? "" : strtolower($_POST["secCode"]);
  if($secCode == $_SESSION["securityCode"] && $result != 3)
  {
   $filename = date("YmdGis");
   $f = fopen("messages/".$filename.".txt","w+");
   fwrite($f,$pic[0]."\n");
   fwrite($f,$_POST['email']."\n");
   fwrite($f,stripslashes($_POST["message"])."\n");
   fclose($f);
   // Compose the mail
   $from = "From: $senderName <$senderEmail>\r\n";
   $replay = "Reply-To: $senderEmail\r\n";    
   $params = "MIME-Version: 1.0\r\n";
   $params .= "Content-type: text/plain; charset=iso-8859-1\r\n";
   $mailtext = "You have just received a Virtual Postcard!\r\n\r\n
                You can pick up your postcard at the following web address:\r\n
                $postcardURL?show=$filename\r\n\r\n
                We hope you enjoy your postcard, and if you do, please take a moment to send a few yourself!\r\n\r\n
                Regards,\r\n
                Holidays From Home\r\n
                $postcardURL";
   // Send email
   @mail($_POST["email"],"You've received a postcard",$mailtext,$from.$replay.$params);
   echo "<center>
          Your postcard was sent successfully!<br /><br />
          <img src='images/$pic[0]' alt='postcard' /><br /><br /><br />".stripslashes($_POST["message"]).
        "</center>";
   $result = 1;
   }
  else{if($result != 3){$result = 2;}}
  }
 if(!empty($_GET["show"]))
 {
  $file = $_GET["show"];
  $content = file("messages/$file.txt");
  $pic = $content[0];
  unset($content[0]);
  unset($content[1]);
  foreach($content as $value){$main .= $value;}
  echo "<center>
         Your postcard!<br /><br />
         <img src='images/$pic' alt='postcard' /><br /><br /><br />$main
        </center>";
  }
 if((empty($result) || $result == 2 || $result == 3) && empty($_GET["show"]))
 {
  echo "<form action='#' method='post'>
         <table align='center'>";
         displayPhotos();
  echo  "</table>
         <div style='color:#f00;font-size:16px;'>$msg</div>        
         <h2>Fill in the Form and then click on Send Card!!</h2>
         <table width='100%'>
          <tr><td>Send to (email address):</td><td><div style='color:#f00;font-size:16px;'>$msg1</div><input type='text' name='email' size='30' value='".$_POST["email"]."' /></td></tr>
          <tr><td>Message:</td><td><textarea name='message' rows='10' cols='40'>".stripslashes($_POST["message"])."</textarea></td></tr>
          <tr><td colspan='2'>".($result == 2 ? "<p style='color:#f00;font-size:16px;'>Sorry the security code is invalid! Please try it again!</span></p>" : "&nbsp;")."</tr>
          <tr>
           <td>Security code: <input class='text' name='secCode' type='text' size='10' />
           </td><td><img src='securityCode.php' alt='security code' border='1' /></td>
          </tr>
          <tr><td colspan='2'>&nbsp;</tr>
          <tr><td colspan='2' align='left'><input type='submit' value='Send card!' name='submit'/></td></tr>
         </table>
        </form>";
  }
?>
I really am struggling to understand this error message and any help would be much appreciateed.
:?

Re: PHP Postcard error Message:

Posted: Thu Aug 12, 2010 11:03 am
by Benjamin
Have you checked the error log?

Re: PHP Postcard error Message:

Posted: Thu Aug 12, 2010 2:30 pm
by norwichchris
How?
:?:

Re: PHP Postcard error Message:

Posted: Mon Aug 16, 2010 12:11 pm
by norwichchris
hi,
I am really really stuck on this issue here is the link:
http://www.holidaysfromhome.co.uk/postc ... 282%29.php

here is what it says in the browser header:
http://www.holidaysfromhome.co.uk/execs ... 0816175902

http://www.holidaysfromhome.co.uk/execs ... 0816175902

Should i ask the web-hosts them selves?

- Chris

Re: PHP Postcard error Message:

Posted: Mon Aug 16, 2010 4:50 pm
by norwichchris
I tried the script out again on my server on awardspace and it didn't work but I think i figured out what the problem at the top of my code it states:

$postcardURL = "http://".$_SERVER["HTTP_HOST"].$_SERVER["SCRIPT_NAME"];

I think i need to find the HTTP host name and script name URL.

Can anyone help me find this?