Hi guys,

I read about this problem but can't figure what should I change.
Can you please help?

Here's my code:

<?php
// Title: Contact Form - Dolce Forno GB
// Updated: 9/8/2012
//  Author: Veronika Horvathova
//Validation code
if (empty($_POST) === false) {
    $errors = array();
    //variables
    $name      = $_POST['name'];
    $email     = $_POST['email'];
    $phone     = $_POST['phone'];
    $subject   = $_POST['subject'];
    $message   = $_POST['message'];
    //All field are required
    if (empty($name) === true || empty($email) === true || empty($phone) === true || empty($subject) === true || empty($message) === true ){
        $errors[] = 'Please fill in all the fields.';
    }
        else {
            //This regex allows only: a-z,A-Z, space, comma, full stop, apostrophe, dash
            if (!preg_match("/^[a-zA-Z\s,.'-]+$/", $name)) { 
                $errors[] = 'Invalid name.'; 
                /*die ("Invalid name."); */
            }
            //var_filter php function
            if (filter_var($email, FILTER_VALIDATE_EMAIL) === false) {
                $errors[] = 'Invalid email address.'; 
            }
            //This regex allows only: 0-9, space, dash, brackets, min-max length: 10-15
            if (!preg_match("/^[0-9\s]{10,15}$/", $phone)){
                $errors[] = 'Invalid phone number.';
            }
        }
    if (empty($errors) === true) {
        mail('veve.horvathova@gmail.com', $subject, $message, 'From: ' . $name, $email);
        header('Location:http://www.dolcefornogb.com/mail.php?sent');
        exit ();
        }
}   
?>

<DCOTYPE html>
<html>
<head>
</head>
<body>
    <?php
    if (isset($_GET['sent']) === true) {
        echo '<p>Thanks for contacting us!</p>';
    }
    else {
        if (!empty($errors)){
            echo    '<ul>';

            foreach ($errors as $error){
                echo '<li>', $error,'</li>';

            echo    '</ul>';
            }
        }
    ?>
            <form action="mail.php" method="post">

            <p>  <label for="name">Name 
            <span class="small">Add your name </span></label> 
            <input type="text" name="name" id="name" placeholder="James Bond"
            <?php 
            if(isset($_POST['name']) === true){
                echo 'value="', strip_tags($_POST['name']),'"';
            }
            ?>
            >
            </p>
            <p>  <label for="email">E-mail address
            <span class="small"> Add your e-mail</span></label> 
            <input type="text" name="email" id="email"
            <?php 
            if(isset($_POST['email']) === true){
                echo 'value="', strip_tags($_POST['email']),'"';
            }
            ?>          
            >
            </p>
            <p><label for="phone">Phone<span class="small"> Add your phone number</span></label> 
            <input type="text" name="phone" id="phone"
            <?php 
            if(isset($_POST['phone']) === true){
                echo 'value="', ($_POST['phone']),'"';
            }
            ?>
            >
            </p>
            <p><label for="suject">Subject </label> 
            <input type="text" name="subject" id="subject"
            <?php 
            if(isset($_POST['subject']) === true){
                echo 'value="', strip_tags($_POST['subject']),'"';
            }
            ?>
            >
            </p>
            <p><label for="message">Message:</label>
            <textarea name="message" id="messgae" rows="10" cols="50"> 
            <?php 
            if(isset($_POST['message']) === true){
                echo strip_tags($_POST['message']);
            }
            ?></textarea> 
            </p>
            <p><label for="call">Request Phone Call</label>
            Yes:<input type="radio" value="Yes" name="call">
            No:<input type="radio" value="No" name="call">
            </p>
            <p class="buttons">
            <input type="submit" value="Send"> <input type="reset" value="Clear">
            </p>
            </form>
    <?php        
    }
    ?>
</body>
</html>

it either you have an empty space or a cahracter already echoed before the redirection call

call ob_start at top file

ob_start();

or increase output_buffering value in file php.ini

Hi,

I'm just a beginner. So if you could explain the ob_start() function and where should I put in my code that would be awesome.
Thanks!

Also i am sure if this would have the affect but your DOCTYPE is mis spelt

<DCOTYPE html>
<html>

ob_start()

It'll keep data in buffer until server process finished before send it to client

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.