title: Failed to send an email with php mail() function
body: <p>I am trying to send an HTML email to user after submitting a form but failed to send an email with PHP <code>mail()</code> function. I am working on the same thing from last 2 hours &amp; I couldn't find the solution. </p>
  
  <p>Below is my code, please give your suggestions.</p>
  
  <pre><code>&lt;?php
  $replyemail="sales@companyname.com";
  
  if (!isset($_POST['email']))
  {
   echo "&lt;script language=\"JavaScript\"&gt;&lt;!--\n ";
   echo "top.location.href = \"$valid_ref1\"; \n// --&gt;&lt;/script&gt;";
   exit;
  }
  
  function is_forbidden($str,$check_all_patterns = true)
  {
   $patterns[0] = 'Content-Type:';
   $patterns[1] = 'mime-version';
   $patterns[2] = 'multipart/mixed';
   $patterns[3] = 'Content-Transfer-Encoding';
   $patterns[4] = 'to:';
   $patterns[5] = 'cc:';
   $patterns[6] = 'bcc:';
   $forbidden = 0;
   for ($i=0; $i&lt;count($patterns); $i++)
    {
     $forbidden = eregi($patterns[$i], strtolower($str));
     if ($forbidden) break;
    }
   //check for line breaks if checking all patterns
   if ($check_all_patterns AND !$forbidden) $forbidden = preg_match("/(%0a|%0d|\\n+|\\r+)/i", $str);
   if ($forbidden)
   {
    echo "&lt;font color=red&gt;&lt;center&gt;&lt;h3&gt;STOP! Message not sent.&lt;/font&gt;&lt;/h3&gt;&lt;br&gt;&lt;b&gt;
          The text you entered is forbidden, it includes one or more of the following:
          &lt;br&gt;&lt;textarea rows=9 cols=25&gt;";
    foreach ($patterns as $key =&gt; $value) echo $value."\n";
    echo "Error";
    exit();
   }
   else return $str;
  }
  
  $email = is_forbidden($_POST["email"]);
  $contact = is_forbidden($_POST["contact"]);
  $comments = is_forbidden($_POST["comments"]);
  
  $ccemail = "From: $email" . "\r\n" .
  "CC: demo@companyname.com";
  
  $mailHeader = "MIME-Version: 1.0\r\n";
  $mailHeader .= "Content-type: text/html; charset=iso-8859-1\r\n";
  $mailHeader .= "From: " . $email . "\r\n";
  $mailHeader .= "Cc: demo@companyname.com\r\n";
  
  $themessage = 'Hello';
  
  mail("$replyemail","Thanks for Register","$themessage","$mailHeader");
  ?&gt;
  </code></pre>