Failed php form

-1

Good afternoon, everyone. I have a problem with the site form. I can not send and when it sends, it does not send the contents of the message field. Follow the html and php code. the link to the site is here , I tried to put here the code but it exceeded the limit of characters.

Follow the form code.

<?php
      //1 – Definimos Para quem vai ser enviado o email
      $para = "[email protected]";
      //2 - resgatar o nome digitado no formulário e  grava na variavel $nome
      $nome = $_POST['name'];
      $email = $_POST['email'];
      $empresa = $_POST['company'];
      $telefone = $_POST['personal_phone']; 


      // 3 - resgatar o assunto digitado no formulário e  grava na variavel //$assunto
      $assunto = "Contato pelo site";
       //4 – Agora definimos a  mensagem que vai ser enviado no e-mail
      $mensagem = "<strong>Nome:  </strong>".$nome;
      $mensagem .="<strong>E-mail:  </strong>".$email;
      $mensagem .="<strong>Empresa:  </strong>".$empresa;
      $mensagem .="<strong>Telefone para contato:  </strong>".$telefone;
      $mensagem .= "<br><strong>Mensagem: </strong>".$_POST['custom_fields[155015]'];

    //5 – agora inserimos as codificações corretas e  tudo mais.
      $headers =  "Content-Type:text/html; charset=UTF-8\n";
      $headers .= "From: ".$para."\n"; //Vai ser //mostrado que  o email partiu deste email e seguido do nome
      $headers .= "X-Sender: smtp-relay.gmail.com\n"; //email do servidor //que enviou
      $headers .= "X-Mailer: PHP  v".phpversion()."\n";
      $headers .= "X-IP:  ".$_SERVER['REMOTE_ADDR']."\n";
      $headers .= "Return-Path:  ".$para."\n"; //caso a msg //seja respondida vai para  este email.
      $headers .= "MIME-Version: 1.0\n";

    mail($para, $assunto, $mensagem, $headers);  //função que faz o envio do email.
 ?>

Thanks for the help.

    
asked by anonymous 10.10.2018 / 18:49

1 answer

5

It's not a form fault!

Failure is in how it retrieves message field in PHP

Do this:

 $msg = $_POST['custom_fields'];

 $mensagem .= "<br><strong>Mensagem: </strong>".$msg[155015];
  

array in PHP is always associative, even if the index is numeric

  • When you place a "name" with brackets, it is sent in array form to the receiver. Brackets treat elements of the same name as an array.
  • When you submit your form with the message field with the text Falha no formulário php da Julia Iracema Figueira it will be rescued as follows in PHP: Array ( [155015] => Falha no formulário php da Julia Iracema Figueira )
  • So to recover this message is as described above!

Also, I do not see a need to send the message in array form, since there is only one field with this name . It would be enough in the textarea of form name="custom_fields" and in PHP $_POST['custom_fields']

BONUS

Associative arrays are structures where each element is identified by a unique key.

Arrays can contain keys and values of the most varied types in the same structure, because there are no typed Arrays. example in ideone

    
10.10.2018 / 21:01