簡體   English   中英

簡單的PHP表單錯誤

[英]Simple PHP form error

我正在嘗試創建一個可以嵌入到我的網站中的簡單PHP電子郵件表單。 我有兩個問題,語法在href = \\“ \\”>之后似乎是錯誤的,我不確定為什么。 其余文本顯示在瀏覽器中href = \\“ \\”>部分之后。 如果我使用這種形式,阻止用戶以這種PHP形式查看我的電子郵件會更容易嗎? 忠告,我是PHP新手

<?php 
$action=$_REQUEST['action']; 
if ($action=="")    /* display the contact form */ 
    { 
    ?> 
<form  action="" method="POST" enctype="multipart/form-data"> 
<input type="hidden" name="action" value="submit">
Your email:<br> 
<input name="email" type="text" value="" size="30"/><br> 
Your message:<br> 
<textarea name="message" rows="7" cols="30"></textarea><br> 
<input type="submit" value="Send email"/> 
</form> 
<?php 
}  
else                /* send the submitted data */ 
{ 
$email=$_REQUEST['email']; 
$message=$_REQUEST['message']; 
if (($name=="")||($email=="")||($message=="")) 
    { 
    echo "All fields are required, please fill <a href=\"\">the form</a> again."; 
    } 
else{         
    $from="From: $name<$email>\r\nReturn-path: $email"; 
    $subject="Message sent using your contact form"; 
    mail("me@email.org", $subject, $message, $from); 
    echo "Email sent!"; 
    } 
}   
?> 

看到有什么問題嗎?

您正在檢查$name ,它不存在。 這將使您工作,但是在定義$_REQUEST之前,應先檢查是否存在。 始終在啟用錯誤報告的情況下編寫代碼。

<?php 
$action=$_REQUEST['action']; 
if ($action=="")    /* display the contact form */ 
    { 
    ?> 
<form  action="" method="POST" enctype="multipart/form-data"> 
<input type="hidden" name="action" value="submit">
Your email:<br> 
<input name="email" type="text" value="" size="30"/><br> 
Your message:<br> 
<textarea name="message" rows="7" cols="30"></textarea><br> 
<input type="submit" value="Send email"/> 
</form> 
<?php 
}  
else                /* send the submitted data */ 
{ 
$email=$_REQUEST['email']; 
$message=$_REQUEST['message']; 
if (($email=="")||($message=="")) 
    { 
    echo "All fields are required, please fill <a href=\"\">the form</a> again."; 
    } 
else{         
    $from="From: $name<$email>\r\nReturn-path: $email"; 
    $subject="Message sent using your contact form"; 
    mail("me@email.org", $subject, $message, $from); 
    echo "Email sent!"; 
    } 
}   
?> 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM