By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,741 Members | 2,004 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,741 IT Pros & Developers. It's quick & easy.

PHP Postcard Notice: Undefined index: Notice: Undefined variable errors

P: 2
hi, I am having serious trouble with my PHP Postcard script. The error message i get is:

Notice: Undefined index:
Notice: Undefined variable

Basically it does not send out the scripts at all. It is hosted on Awardspace.
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. session_start();
  4. //check error log
  5. ini_set('display_errors', 1);
  6. ini_set('log_errors', 1);
  7. ini_set('error_log', dirname(__FILE__) . '/error_log.txt');
  8. error_reporting(E_ALL);
  9.  
  10. // CHANGE PARAMETERS HERE BEGIN
  11. $senderName  = " Holidays From Home "; // Eg.: John's Postcards
  12. $senderEmail = "chris01@voluntary.awardspace.co.uk";  // Eg.: john@postcard.com
  13. // Change only if you have problems with urls
  14. $postcardURL = "http://".$_SERVER[""].$_SERVER[""]; //problem is definetely here!!!
  15. // CHANGE PARAMETERS HERE END
  16. $result = 0;
  17. $msg = "";
  18. $msg1 = "";
  19. $pic = "";
  20. function displayPhotos()
  21. {
  22.  global $pic;
  23.  $columns = 5;
  24.  $act = 0;
  25.  $act1 = 0;
  26.  // Open the actual directory
  27.  if($handle = opendir("thumbs"))
  28.  {
  29.   // Read all file from the actual directory
  30.   while($file = readdir($handle))
  31.   {
  32.    if(!is_dir($file))
  33.    {
  34.     if(isset($pic[1]))
  35.     {
  36.      if($pic[1] == $act1){$sel = "checked";}
  37.      else{$sel = "unchecked";}
  38.      }
  39.     if($act == 0){echo "<tr>";}
  40.     echo "<td align='center'><img src='thumbs/$file' alt='postcard'/><br/><input type='radio' name='selimg' value='$file,$act1' $sel/></td>";
  41.     $act++;
  42.     $act1++;
  43.     if($act == $columns){$act = 0;echo "</tr>";}
  44.  
  45.        }
  46.     }
  47.   echo "</tr>";
  48.   }    
  49.  }
  50. ?>
  51. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
  52. <html>
  53. <head>
  54.  <title>Micro Postcard</title>
  55.  <link href= "style/style.css" rel="stylesheet" type="text/css" />
  56. </head>
  57. <body>
  58. <div id="main">
  59. <div class="style1" id="caption">
  60. <div align="left" class="style1"></div>
  61. </div>
  62.    <?php //makes sure form is correctly filled in 
  63.  if(!empty($_POST["submit"]))
  64.  {
  65.   if(empty($_POST["selimg"])){$msg = "Please select an image from above!";$result = 3;}
  66.   else{$pic = explode(",",$_POST["selimg"]);}
  67.   if(empty($_POST["email"]) && empty($result)){$msg1 = "You must enter an email address!";$result = 3;}
  68.   $secCode = empty($_POST["secCode"]) ? "" : strtolower($_POST["secCode"]);
  69.   if($secCode == $_SESSION["securityCode"] && $result != 3)
  70.   {
  71.    $filename = date("YmdGis");
  72.    $f = fopen("messages/".$filename.".txt","w+");
  73.    fwrite($f,$pic[0]."\n");
  74.    fwrite($f,$_POST['email']."\n");
  75.    fwrite($f,stripslashes($_POST["message"])."\n");
  76.    fclose($f);
  77.    // Compose the mail
  78.    $from = "From: $senderName <$senderEmail>\r\n";
  79.    $replay = "Reply-To: $senderEmail\r\n";    
  80.    $params = "MIME-Version: 1.0\r\n";
  81.    $params .= "Content-type: text/plain; charset=iso-8859-1\r\n";
  82.    $mailtext = "You have just received a Virtual Postcard!\r\n\r\n
  83.                 You can pick up your postcard at the following web address:\r\n
  84.                 $postcardURL?show=$filename\r\n\r\n
  85.                 We hope you enjoy your postcard, and if you do, please take a moment to send a few yourself!\r\n\r\n
  86.                 Regards,\r\n
  87.                 Holidays From Home\r\n
  88.                 $postcardURL";
  89.    // Send email
  90.    @mail($_POST["email"],"You've received a postcard",$mailtext,$from.$replay.$params);
  91.    echo "<center>
  92.           Your postcard was sent successfully!<br /><br />
  93.           <img src='images/$pic[0]' alt='postcard' /><br /><br /><br />".stripslashes($_POST["message"]).
  94.         "</center>";
  95.    $result = 1;
  96.    }
  97.   else{if($result != 3){$result = 2;}}
  98.   }
  99.  if(!empty($_GET["show"]))
  100.  {
  101.   $file = $_GET["show"];
  102.   $content = file("messages/$file.txt");
  103.   $pic = $content[0];
  104.   unset($content[0]);
  105.   unset($content[1]);
  106.   foreach($content as $value){$main .= $value;}
  107.   echo "<center>
  108.          Your postcard!<br /><br />
  109.          <img src='images/$pic' alt='postcard' /><br /><br /><br />$main
  110.         </center>";
  111.   }
  112.  if((empty($result) || $result == 2 || $result == 3) && empty($_GET["show"]))
  113.  {
  114.   echo "<form action='#' method='post'>
  115.          <table align='center'>";
  116.          displayPhotos();
  117.   echo  "</table>
  118.          <div style='color:#f00;font-size:16px;'>$msg</div>        
  119.          <h2>Fill in the Form and then click on Send Card!!</h2>
  120.          <table width='100%'>
  121.           <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>
  122.           <tr><td>Message:</td><td><textarea name='message' rows='10' cols='40'>".stripslashes($_POST["message"])."</textarea></td></tr>
  123.           <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>
  124.           <tr>
  125.            <td>Security code: <input class='text' name='secCode' type='text' size='10' />
  126.            </td><td><img src='securityCode.php' alt='security code' border='1' /></td>
  127.           </tr>
  128.           <tr><td colspan='2'>&nbsp;</tr>
  129.           <tr><td colspan='2' align='left'><input type='submit' value='Send card!' name='submit'/></td></tr>
  130.          </table>
  131.         </form>";
  132.   }
  133. ?>
  134.  
Any help would be much appreciated
Aug 18 '10 #1
Share this Question
Share on Google+
2 Replies


JKing
Expert 100+
P: 1,206
Expand|Select|Wrap|Line Numbers
  1. $postcardURL = "http://".$_SERVER[""].$_SERVER[""]; //problem is definetely here!!!
  2.  
$_SERVER is an array of variables. You are using a blank index which results in the undefined index and variable.

It should look something like $_SERVER['SERVER_NAME'] but without knowing where you want to send the users I cannot direct you much further.

Here is some more info on the $_SERVER variablePHP $_SERVER
Aug 18 '10 #2

P: 2
Here is the URL script. IT is supposed to send an email with a hyperlink and then the reciepient can opne the link to view the card.

see link below:
http://voluntary.awardspace.co.uk/Postcard.php

Thx!
Aug 20 '10 #3

Post your reply

Sign in to post your reply or Sign up for a free account.