好的,我正在开发一个在线投资组合,而且我正在处理一个邮件表格。它会询问姓名,电子邮件和消息。然后当按下发送时,它会向我发送一封包含所有这些内容的电子邮件,并将用户重定向到另一个页面。然而它似乎在某处死亡。同时仍然将用户重定向到表单完整页面。
<form method="post" name="contactform" action="<?php $_SERVER['PHP_SELF'] ?>">
<input type="text" class="name" required maxlength="50" placeholder="Your name" name="name">
<input type="text" class="email" required maxlength="50" placeholder="Your email" name="email">
<textarea required maxlength="500" placeholder="Your message" name="message"></textarea><br><br>
<input name="submit" type="submit" name="submit" value="submit">
</form>
这是PHP代码,我在文档的顶部,在?&gt;之后的任何地方都没有空格。关闭
<?php
if(isset($_POST['submit']))
{
$errors = '';
$myemail = 'lucasvandongen10@gmail.com';//<-----Put Your email address here.
if(empty($_POST['name']) ||
empty($_POST['email']) ||
empty($_POST['message']))
{
$errors .= "\n Error: all fields are required";
}
else
{
}
$name = $_POST['name'];
$email_address = $_POST['email'];
$message = $_POST['message'];
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";
}
else
{
}
if( empty($errors))
{
$to = $myemail;
$email_subject = "Contact form submission: $name";
$email_body = "You have received a new message. "." Here are the details:\n Name: $name \n "."Email: $email_address\n Message: \n $message";
$headers = "From: <noreply@lucasvandongen.com>\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');
}
else
{
}
}
else
{
}
?>