I have been encountering a syntax error with php email forms for days now and not sure what is going on. I have written my own code and even used 3 different pre-written code and I keep seeing the same syntax error with the line that tells it what email the form details need to be sent to.
For the sake of posting I have changed the email on the line as not to display my own email
the line is
$myemail = "usersemail@testemail.com";//<-----Put Your email address here.
I have tried, gmail, hotmail, yahoo and for the sake of it even aol emails. I have had both "" and '' and keep ecnountering a syntax error on that line. I don't see what it is.
Here is the full code I am currently using
<?php
$errors = '';
$myemail = "usersemail@rocketmail.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'];
$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";
$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');
}
?>