PHP - cannot modify header information - headers already sent by (output started at
<p>I am working with PHP and I got this message </p>

<blockquote>
  <p>cannot modify header information - headers already sent by (output
  started at</p>
</blockquote>

<p>after executing a code which looks like this: </p>

<pre><code>&lt;?php
    if (condition) {

        if (condition) {
            //Statement
        }

        $to = $_POST['email'];
        $subject = "Registration Confirmation";

        $message = '
                &lt;html&gt;
                    &lt;head&gt;
                        &lt;title&gt;'.$subject.'&lt;/title&gt;
                    &lt;/head&gt;
                &lt;/html&gt;
            ';

        // Always set content-type when sending HTML email
        $headers = "MIME-Version: 1.0" . "\r\n";
        $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";

        // More headers
        $headers .= 'From: &lt;contact@ghanalifestore.com&gt;' . "\r\n";

        mail($to,$subject,$message,$headers);

        header('Location: reset.php?username='.$username);
        exit();

    }else {
        //statement
    }
</code></pre>

<p>Based on this answer <a href="https://stackoverflow.com/a/8028987/6125193">from Stackoverflow</a>, I think the error is coming from the HTML code in the variable <code>$message</code>. I don't really know how I can modify the content of that variable to avoid the error.</p>

<p>Kindly help me solve this problem.</p>