PHP未定义错误,尝试执行电子邮件代码


PHP Undefined error , trying to do email code

我试图编写电子邮件代码,但我遇到了无法解决的错误。这是我的密码。

错误:

Notice: Undefined index: action in line 5

代码:

<?php
$Datacomment = 'data.txt';
$Key = '[@]';
$Key2 = '/n';
if($_POST['action'] == 'postcomment'){
   $Name    = str_replace(array($Key,$Key2),'',$_POST['name']);
   $Comment = str_replace(array($Key,$Key2),'',$_POST['content']); 
   $Comment = $Name.$Key.$Comment.$Key2; 

   $Modwrite = 'a';
   if(!file_exists($Datacomment)){
      $Modwrite = 'w';
   }
   $File = fopen($Datacomment,$Modwrite);
   fwrite($File,$Comment);
   fclose($File);
   header("Location: index.php"); /*replace comment.php by your homepage*/
}
/*load coment*/
if(!file_exists($Datacomment)){
   $Showcomment = '<div class="showcomment">No comment</div>';
}
else{
   $Cm = file_get_contents($Datacomment);
   $Array = explode($Key2,$Cm);
   $Total = count($Array) -1;
   $Showcomment = '<h3 style="margin-left:1%;">'.$Total.' comments</h3>';
   for($i = $Total-1;$i >= 0;$i--){
      $Arraycm  = explode($Key,$Array[$i]);
      $Name = $Arraycm[0];
      $Comment = $Arraycm[1];
      $Showcomment .= '<div class="showcomment"><h4>'.$Name.'</h4>'.$Comment.'</div>';
   }
}
?>
<style type="text/css">
   .showcomment { width:96%; float:left; border:1px solid #ccc; padding:1%; margin:0 0 10px 1%; color:#333;}
   .showcomment h4 { color:#03C; padding:0px; margin:0px;}
   .comment {width:400px; height:100px; outline:none;}
   .name { width:400px;outline:none}
</style>
<form style="margin-left:1%;"  action="comment.php" method="post">
   <input type="hidden" name="action" value="postcomment" />
    <h3>Enter your name :</h3>
    <input type="text" name="name" class="name" />
    <h3>Eenter comment :</h3>
    <textarea name="content" class="comment"></textarea>
    <p>
    <input type="submit" name="submit" value="SEND COMMENT" />
    </p>
</form>
<?php echo $Showcomment;?>

第一次输入注释时。php验证

if(isset($_POST['action']) && $_POST['action'] == 'postcomment'){

按下submit时发送参数"action"

相关文章: