Failure in php form

Asked

Viewed 69 times

-1

Good afternoon, you guys. I have a problem with the site form. I cannot send and when you send, it does not send the contents of the message field. It follows the html and php code. the Link to the site is this here , I tried to put the code here but exceeded the character limit.

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 your help.

  • Put the html of the form you are using.

  • Have you ever var_dump the $_POST to see what is being received?

  • It’s good to know that if an answer solved your problem, mark it as accepted. See how in https://i.stack.Imgur.com/jx7Ts.png and why in https://pt.meta.stackoverflow.com/questions/1078/como-e-por-que-aceitar-uma-resposta/1079#1079

1 answer

4

It is not a flaw in the form!

The flaw is in how it retrieves message field in PHP

Do so:

 $msg = $_POST['custom_fields'];

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

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

  • When you put a "name" with [] square brackets it is sent as an array to the receiver. Square brackets handle the elements of the same name as an array.
  • When you send your form with the message field with the text Falha no formulário php da Julia Iracema Figueira it will be rescued in the following way in PHP: Array ( [155015] => Falha no formulário php da Julia Iracema Figueira )
  • So to recover that message is as described above!

Also, I see no need to send the message in array form, since there is only one field with this name. Simply in the form textarea name="custom_fields" and in PHP $_POST['custom_fields']


BONUS


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

Arrays can contain keys and values of all kinds in the same structure, because there is no typed Arrays. example in the ideone

  • I liked the bonus

Browser other questions tagged

You are not signed in. Login or sign up in order to post.