V
V
Vadim Kershner2018-02-22 17:01:45
PHP
Vadim Kershner, 2018-02-22 17:01:45

Help with php contact form?

Hello, there is a feedback form. For some reason, it does not send the entered data to the specified email. Though the form fulfills data acceptance. Please tell me what is the reason.

<?php
$data = json_decode($_REQUEST['json']);

$to="[email protected]"; // Your Email

$subject="Сообщение с сайта";

$date=date("l, F jS, Y");
$time=date("h:i A");

$total = count($data);
$valida = true;
$type = 'contact';
$email = '';

for ($i = 0; $i < $total; $i++){
  
  if($data[$i]->name == 'type'){ $type = $data[$i]->value; }
  if($data[$i]->name == 'email'){ $email = $data[$i]->value; }

  if ($data[$i]->required and strlen($data[$i]->value) < 3){
    
    echo "<div class='alert alert-danger'>
      <a class='close' data-dismiss='alert'>×</a>
      <strong>Warning!</strong> Please fill the ".$data[$i]->name." field.
    </div>";
    $valida = false;
    break;
  }

  if ($data[$i]->validate){
    $val = validate($data[$i]);

    if(!$val[0]){
      echo "<div class='alert alert-danger'>
          <a class='close' data-dismiss='alert'>×</a>
          <strong>Warning!</strong> ".$val[1]."
        </div>";
      $valida = false;
      break;
    }
  }
}

if ($valida) {
  $msg  = "";
  $msg .= "Message sent from website on date:  $date, hour: $time.<br/><br/>";
  
  for ($i = 0; $i < $total; $i++){
    $msg .= "<strong>".$data[$i]->name."</strong>: ".$data[$i]->value."<br/>";
  }

  if ($type == 'contact'){
    mail($to,$subject,$msg,"From:".$email);
    
  } else {
    //...
  }
  
  echo "<div class='alert alert-success'>
    <a class='close' data-dismiss='alert'>×</a>
    <strong>Спасибо за сообщение!</strong>
  </div>";
}

function validate(){
  //...
  return array(true, '');
}
?>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Lander, 2018-02-22
@woodoos

Most likely, the mail function is disabled.
Are you running locally or hosted?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question