0

Don't know why i'm getting this error for my contact form i'm new to php. Hope you can help me with this

Parse error: syntax error, unexpected 'if' (T_IF) on line 2

Code:

<? php
    if (isset($_POST['submit'])) { 
       $name = $_POST['name'];
       $mailFrom = $_POST['email'];
       $Phone = $_POST['phone'];
       $Message = $_POST['message'];
       $Select = $_POST['project'];
       $mailTo = "info@amaravathiestates.in";
       $headers ="From: ".$mailFrom;$txt = "You have received an email from " .$name ".\n\n" .$Message ".\n\n" "Phone Number:" .$Phone ".\n\n" "Project Visit:" .$Select;
       mail($mailTo,$txt,$headers);
       header("Location: Contact-Us.html");
    };

1 Answers1

0

You forgot " in $mailTo = "info@amaravat";

No gap needs to be in between <? and php

As well as use exit(); after header redirects, otherwise any code below it will execute even after redirection happen.(will create a big security loophole)

Code needs to be:-

<?php
if (isset($_POST['submit'])) { 
    $name = $_POST['name'];
    $mailFrom = $_POST['email'];
    $Phone = $_POST['phone'];
    $Message = $_POST['message'];
    $Select = $_POST['project'];
    $mailTo = "info@amaravat"; //forgot "
    $headers ="From: ".$mailFrom;
    $txt = "You have received an email from " .$name ".\n\n" .$Message ".\n\n" "Phone Number:" .$Phone ".\n\n" "Project Visit:" .$Select;
    mail($mailTo,$txt,$headers);
    header("Location: Contact-Us.html");
    exit(); // use exit() to stop code execution
}
Alive to die - Anant
  • 70,531
  • 10
  • 51
  • 98