i have attached a php file to my website so that users can send me query mails with their details, it is sending all the data to my mail but shows an internal server error whenever it is being load after sending the message. This is my code:
This form is on every page on website
<form style="line-height:15px" name="contactform" action="send_form_email.php" method="post">
<input type="text" placeholder="Full Name" maxlength="50" class="txt" name="name" required><br><br>
<input type="text" placeholder="E Mail" class="txt" maxlength="80" name="email" required><br><br>
<textarea onkeyup="adjust_textarea(this)" placeholder="Message" class="txt" maxlength="1000" name="message" required></textarea><br><br>
<input type="text" placeholder="Phone No." class="txt" maxlength="30" name="phone" required><br><br><br>
<input type="submit" value="Send" class="btn">
</form>
send_form_email.php
<?php
$errors = '';
$myemail = 'legaladvisory@shagunmarriage.com';//<-----Put Your email address here.
if(empty($_POST['name']) ||
empty($_POST['email']) ||
empty($_POST['message']))
{
$errors .= "\n Error: all fields are required";
}
$name = $_POST['name'];
$phone = $_POST['phone'];
$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";
}
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\n $phone";
$headers = "From: $myemail\n";
$headers .= "Reply-To: $email_address";
mail($to,$email_subject,$email_body,$headers);
//redirect to the 'thank you' page
alert('Thankyou for contacting us');
header('Location: index.php');
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Contact form handler</title>
</head>
<body style="window.location='index.php'">
<!-- This page is displayed only if there is some error -->
<?php
echo nl2br($errors);
?>
</body>
</html>