Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Kenny Smith

Suspended
Original poster
Dec 6, 2022
5
2
I'm trying to implement a form submission feature on my website using PHP, but I'm getting the following error: 'PHP Parse error: syntax error, unexpected '$_POST' (T_VARIABLE) in /path/to/file.php on line 12'. Here is the relevant code:
Code:
if (isset($_POST['submit'])) {
  $name = $_POST['name'];
  $email = $_POST['email'];
  $message = $_POST['message'];
 
  $formcontent="From: $name \n Message: $message";
  $recipient = "myemail@example.com";
  $subject = "Contact Form";
  $mailheader = "From: $email \r\n";
  mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
  echo "Thank You!";
}
I'm not sure what's causing this error. Can anyone help me figure out what's going wrong and how I can fix it?"
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.