【发布时间】:2015-12-28 07:45:52
【问题描述】:
所以有一个表格,它只获取此人的电子邮件并将其发送到我分配的电子邮件地址。但是我想我以错误的方式编写了代码,因为我遇到了错误。我见过其他 stackoverflow 问题,但我不确定为什么这不起作用。 这是html中的表格。
<form style="margin-bottom:50px;" name="contactform" action="contact-form-handler.php" class="news-letter "method="post">
<div class="subscribe-hide">
<input type="text" name="email" class="form-control" placeholder="Email Address" >
<button type="submit" class="btn"><i class="fa fa-envelope"></i></button>
</div><!-- /.subscribe-hide -->
</form><!-- /.news-letter -->
这是另一个文件中的 PHP 代码。
<?php
$errors = '';
$myemail = 'masnadhossain@live.com';
empty($_POST['email']))
{
$errors .= "\n Error: all fields are required";
}
$email_address = $_POST['email'];
if (!preg_match(
"/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i",
$email_address))
{
$errors .= "\n Error: Invalid email address";
}
if( empty($errors))
{
$to = $myemail;
$email_subject = "Contact form submission";
$email_body = "You have received a new message. ".
" Here are the details:".
"Email: $email_address\n ";
$headers = "From: $myemail\n";
$headers .= "Reply-To: $email_address";
mail($to,$email_subject,$email_body,$headers);
//redirect to the 'thank you' page
header('Location: contact-form-thank-you.html');
}
?>
我得到的错误是服务器错误 500
【问题讨论】:
-
“因为我遇到了错误。”请编辑您的问题以包含错误。
-
@Epodax 我刚刚收到服务器错误 500
-
@Masnad Nihit : 找到日志文件,或者在 php.ini 中启用 php 错误
-
@PierreEmmanuelLallemant 问题是错误已经启用,但似乎无法捕获错误。
-
使用
try {} catch () {}php.net/manual/en/language.exceptions.php并在此报错