i didnt get mail from php contact form. wht is the error in the code below?

if(isset($_POST['email'])) {
    $email_to = "cprabha@hotmail.com";
    $email_subject = "Enquiry from Brandsterlab";
    function died($error) {
        // your error code can go here
        echo "We are very sorry, but there were error(s) found with the form you submitted. ";
        echo "These errors appear below.<br /><br />";
        echo $error."<br /><br />";
        echo "Please go back and fix these errors.<br /><br />";
    // validation expected data exists
    if(!isset($_POST['name']) ||
        !isset($_POST['email']) ||
        !isset($_POST['webdesign']) ||
        !isset($_POST['ecommerce']) ||
            !isset($_POST['customweb']) ||
            !isset($_POST['mobile']) ||
            !isset($_POST['branding']) ||
            !isset($_POST['saab']) ||
            !isset($_POST['mercedes1']) ||
            !isset($_POST['mercedes2']) ||
            !isset($_POST['mercedes3']) ||
            !isset($_POST['mercedes4']) ||
        !isset($_POST['message'])) {
        died('We are sorry, but there appears to be a problem with the form you submitted.');      
    $name = $_POST['name']; // d
   $email_from = $_POST['email']; // d
    $webdesign = $_POST['webdesign']; // d
    $ecommerce = $_POST['ecommerce'];
      $customweb = $_POST['customweb'];
      $mobile = $_POST['mobile'];
      $branding = $_POST['branding'];
      $saab = $_POST['saab'];
      $mercedes1 = $_POST['mercede s1'];
      $mercedes2 = $_POST['mercedes2'];
      $mercedes3 = $_POST['mercedes3'];
      $mercedes4 = $_POST['mercedes4'];      // not d
    $message = $_POST['message']; // d
    $error_message = "";
    $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
  if(!preg_match($email_exp,$email_from)) {
    $error_message .= 'The Email Address you entered does not appear to be valid.<br />';
    $string_exp = "/^[A-Za-z .'-]+$/";
  if(!preg_match($string_exp,$name)) {
    $error_message .= 'The Name you entered does not appear to be valid.<br />';
  if(!preg_match($string_exp,$webdesign)) {
    $error_message .= 'The webdesign you entered does not appear to be valid.<br />';
       if(!preg_match($string_exp,$customweb)) {
    $error_message .= 'The customweb you entered does not appear to be valid.<br />';
       if(!preg_match($string_exp,$branding)) {
    $error_message .= 'The branding you entered does not appear to be valid.<br />';
       if(!preg_match($string_exp,$saab)) {
    $error_message .= 'The saab you entered does not appear to be valid.<br />';      
       if(!preg_match($string_exp,$mercedes1)) {
    $error_message .= 'The mercedes1 you entered does not appear to be valid.<br />';      
       if(!preg_match($string_exp,$mercedes2)) {
    $error_message .= 'The mercedes2 you entered does not appear to be valid.<br />';            
       if(!preg_match($string_exp,$mercedes3)) {
    $error_message .= 'The mercedes3 you entered does not appear to be valid.<br />';            
       if(!preg_match($string_exp,$mercedes4)) {
    $error_message .= 'The mercedes4 you entered does not appear to be valid.<br />';                  
  if(strlen($message) < 2) {
    $error_message .= 'The message you entered do not appear to be valid.<br />';
  if(strlen($error_message) > 0) {
    $email_message = "Form details below.\n\n";
    function clean_string($string) {
      $bad = array("content-type","bcc:","to:","cc:","href");
      return str_replace($bad,"",$string);
    $email_message .= "Name: ".clean_string($name)."\n";
    $email_message .= "Email: ".clean_string($email)."\n";
      $email_message .= "Project Category & Budget: ".clean_string($webdesign)."\n";
      $email_message .= "Project Category & Budget: ".clean_string($ecommerce)."\n";
      $email_message .= "Project Category & Budget: ".clean_string($customweb)."\n";
      $email_message .= "Project Category & Budget: ".clean_string($mobile)."\n";
      $email_message .= "Project Category & Budget: ".clean_string($branding)."\n";
      $email_message .= "Budget: ".clean_string($saab)."\n";
      $email_message .= "Budget: ".clean_string($mercedes1)."\n";
      $email_message .= "Budget: ".clean_string($mercedes2)."\n";
    $email_message .= "Budget: ".clean_string($mercedes3)."\n";
    $email_message .= "Budget: ".clean_string($mercedes4)."\n";
    $email_message .= "Message: ".clean_string($message)."\n";
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);  

      //<!-- place your own success html below -->
      echo "Thank you for contacting us. We will be in touch with you very soon.<br /><br />";

huo minnaphp developerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dillyn BarberCIOCommented:
Does the server have a working and running SMTP server that you have hooked into it? PHP can't just send an email like that unless SMTP is already configured.

You need to include the PHPMailer library (https://github.com/PHPMailer/PHPMailer) with the script like this:
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

require 'path/to/PHPMailer/src/Exception.php';
require 'path/to/PHPMailer/src/PHPMailer.php';
require 'path/to/PHPMailer/src/SMTP.php';

Open in new window

Then add the following code after that:
$mail->SMTPDebug = 2; //Alternative to above constant
$mail->isSMTP();  // tell the class to use SMTP
$mail->SMTPAuth   = true;                // enable SMTP authentication
$mail->Port       = 25;                  // set the SMTP port
$mail->Host       = "mail.yourhost.com"; // SMTP server
$mail->Username   = "name@yourhost.com"; // SMTP account username
$mail->Password   = "your password";     // SMTP account password

Open in new window

The code provided will have debugging on and can then tell you what your SMTP errors are and you can go from there.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Dillyn BarberCIOCommented:
No one has followed up since the initial suggestion. Question has become abandoned.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.