Okay, so I'm working on an online portfolio and I'm working on a mail form. It asks a name, email and an message. Then when pressing send it will send an email to me with all of that and redirect the user to another page. However somewhere it seems to die. While still redirecting the user to the form complete page.
<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>
and this is the PHP code, i's on the top of the document with no spaces anywhere after the ?> closes
<?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
{
}
?>