0

It is giving me this and not changing the header:

Warning: Cannot modify header information - headers already sent by (output started at /home/content/27/10711827/html/contact.php:2) in /home/content/27/10711827/html/contact.php on line 24

Here is the code.

<?php

if (empty($_POST) === false){
  $errors = array();
  $name = $_POST['name'];
  $email = $_POST['email'];
  $message = $_POST['message'];

  if (empty($name) === true || empty($email) === true || empty($message) === true){
    $error[] = 'Name, email and message is required!';
  } else{
    if (filter_var($email, FILTER_VALIDATE_EMAIL) === false){   
      $errors[] = 'That\'s not a valid email address';
    }
    if (ctype_alpha($name) === false){
      $errors[] = 'Name must only cotain letters';
    }

  }

  if(empty($errors) === true){
    mail('houseblendrecords@gmail.com', 'Contact form', '$message', 'From: ' . $email);
    header('Location: contact.php?sent');
    exit();
  }
}
CraigTeegarden
  • 8,173
  • 8
  • 38
  • 43

2 Answers2

3

This happens when your code has already produced some content by the time you're trying to send a header. Make sure that your code isn't producing any warnings. If you're sure that's not the case, make sure that there aren't any empty lines before the opening <?php tag.

sidoh
  • 580
  • 3
  • 12
0

If it is not an issue with white space before the opening <?php tag also check your file encoding. If your files are saved as UTF-8 make sure they are saved as UTF-8 without bom, or else resave it as ANSI.

Ken Herbert
  • 5,205
  • 5
  • 28
  • 37