繁体   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