0

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');

}


?>
Zephyranthes
  • 55
  • 1
  • 7
  • …and the error is? – deceze Jul 18 '17 at 15:10
  • That is why I posted the code to see if anyody could see what it might be because I don't see one. Despite that though I keep getting told there is a syntax error on the myemail line... – Zephyranthes Jul 18 '17 at 15:14
  • What. Is. The. Exact. Error. Message?! – deceze Jul 18 '17 at 15:20
  • Parse error: syntax error, unexpected '$myemail' (T_VARIABLE) in /storage/ssd1/349/2269349/public_html/reserve_form.php on line 49 – Zephyranthes Jul 18 '17 at 15:21
  • See https://stackoverflow.com/a/18092267/476. Since it doesn't *look* like there's anything wrong, you may have an invisible character before that line: https://stackoverflow.com/a/18050072/476 – deceze Jul 18 '17 at 15:23
  • Thank you, I will look those over and see if I have any invisible characters I might not have know about. – Zephyranthes Jul 18 '17 at 15:27
  • It says "line 49" but the one you indicate is line 5. Is there some code you're not showing us? Or is this line 49 `$headers = "From: $myemail\n";`? – Jay Blanchard Jul 18 '17 at 16:02

0 Answers0