-1
我試圖做電子郵件代碼,但我有我無法解決的錯誤。這是我的代碼。PHP未定義的錯誤,試圖做電子郵件代碼
錯誤:
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;?>
你發佈的代碼如何相關電子郵件?我什麼也沒有看到。 – eis 2014-10-04 14:49:56
錯誤消息告訴你,究竟是什麼錯誤。也許看看'isset()'。 – Sirko 2014-10-04 14:56:40
嘗試'if(isset($ _ POST ['submit'])&&($ _POST ['action'] =='postcomment')){...}'將'action =「comment.php」'改爲' action =「」'因爲你正在同一頁面內運行你的整個代碼。 – 2014-10-04 14:59:37