我试图为访问者实现一个简单的表单来联系我。我使用PHP(我是一个非常初学者),我遇到的问题是它返回500内部服务器错误。表单显示正常和一切,它只是当我按提交它发生。表格位于This page
代码如下:
<?php
if (isset($_REQUEST['email']))
//if "email" is filled out, send email
{
//send email
$email = $_REQUEST['email'] ;
$subject = $_REQUEST['subject'] ;
$message = $_REQUEST['message'] ;
mail('tburn76@gmail.com', $subject,
$message, 'From:' . $email);
echo "Thank you for using our mail form";
}
else
//if "email" is not filled out, display the form
{
echo "<form method='post' action='mailform.php'>
Email : <input name='email' type='text'><br>
Subject: <input name='subject' type='text'><br>
Message:<br>
<textarea name='message' rows='15' cols='40'>
</textarea><br>
<input type='submit' value='Send'>
</form>";
}
?>
非常感谢, 托米
答案 0 :(得分:1)
这是托管服务提供商的问题。 500是服务器错误而不是 编程,但你应该在
之前完成
将您的seconde echo更改为此
echo "<form method='post' action='".$_SERVER['PHP_SELF']."' name='email'>
Email : <input name='email' type='text'><br>
Subject: <input name='subject' type='text'><br>
Message:<br>
<textarea name='message' rows='15' cols='40'>
</textarea><br>
<input type='submit' name='email' value='Send'>
</form>";
代码将是
<?php
if (isset($_REQUEST['email']))
//if "email" is filled out, send email
{
//send email
$email = $_REQUEST['email'] ;
$subject = $_REQUEST['subject'] ;
$message = $_REQUEST['message'] ;
mail('tburn76@gmail.com', $subject,
$message, 'From:' . $email);
echo "Thank you for using our mail form";
}
else
//if "email" is not filled out, display the form
{
echo "<form method='post' action='".$_SERVER['PHP_SELF']."' name='email'>
Email : <input name='email' type='text'><br>
Subject: <input name='subject' type='text'><br>
Message:<br>
<textarea name='message' rows='15' cols='40'>
</textarea><br>
<input type='submit' name='email' value='Send'>
</form>";
}
?>
PS:我认为这不是代码错误,但这会对你有所帮助 祝好运 !