473,385 Members | 1,888 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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

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
2 3734
JKing
1,206 Expert 1GB
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
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

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

Similar topics

5
by: news.bigpond.com | last post by:
getting errors Notice: Undefined index: name in F:\uni\Software engineering\assignment4\guestbook.php on line 6 the variable $name is declared as $name = _POST; What could be causing this?...
4
by: John Oliver | last post by:
PHP Notice: Undefined index: name in /home/www/reformcagunlaws.com/new.php on line 6 PHP Notice: Undefined index: address in /home/www/reformcagunlaws.com/new.php on line 7 PHP Notice: ...
26
by: Craig Morrison | last post by:
I'm getting this: PHP Notice: Undefined index: D1 in /var/www/html..... From this line of code: $id_option = $_POST; Which is posted by this:
3
cassbiz
by: cassbiz | last post by:
Here are the errors that are coming up in my error_log Notice: Undefined index: andatum in /zipcode.php on line 11 Notice: Undefined index: andatum in /zipcode.php on line 12 Notice: Undefined...
3
by: number1yan | last post by:
Can anyone help me, i am creating a website and am using a php script that recomends the website to other people. I keep getting the same error and can not work out why. The error is: Notice:...
4
by: iera | last post by:
i've got this message Notice: Undefined index: name in c:\program files\easyphp1-8\www\forum\kemaskini.php on line 2 i've used this coding.. <?php $name = $_POST; $date = $_POST; $time...
15
by: bill | last post by:
I am trying to write clean code but keep having trouble deciding when to quote an array index and when not to. sometimes when I quote an array index inside of double quotes I get an error about...
5
by: siyaverma | last post by:
Hi, I am new to php, i was doing some small chnages in a project developed by my collegue who left the job and i got the responsibility for that, After doing some changes when i run it on my...
5
by: movieking81 | last post by:
Another PHP newbie here, I trolled the boards here trying some of the different solutions but I keep getting the errors over an over. maybe my problem is specific. I keep getting the following when...
4
by: cyberlei | last post by:
hi all, I`m getting this error Notice: Undefined index: user in c:\inetpub\wwwroot\login.php on line 96 Notice: Undefined variable: message in c:\inetpub\wwwroot\login.php on line 101 Could...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.