Blank, unanswered, email form - PHP

Asked

Viewed 170 times

0

Good afternoon, everyone,

I’m not an expert in php and I’m trying to make an email form, but when I click send it a blank screen appears, no errors and also no sent message, could anyone help me? Thank you. Code below

Form:

<div id="contact_form">
                     <div class="form-group">
                        <div class="row">
                           <div class="col-md-6">
                           <form action='/php/mail.php'>
                              <label>Nome<span class="required">*</span></label>
                              <input type="text" name="nome" class="form-control input-field" required=""> 
                           </div>
                           <div class="col-md-6">
                              <label>Cidade<span class="required">*</span></label>
                              <input type="text" name="cidade" class="form-control input-field" required=""> 
                           </div>
                        </div>
                        <div class="row">
                           <div class="col-md-12">
                              <label>Email<span class="required">*</span></label>
                              <input type="email" name="email" class="form-control input-field" required=""> 
                           </div>
                        </div>
                        <button type="submit" id="submit_btn" value="Submit" class="btn btn-primary">Enviar</button>
                     </div>

And php:

<?php
if (isset($_POST['BTEnvia'])) {

 //Variaveis de POST, Alterar somente se necessário 
 //====================================================
 $nome = $_POST['nome'];
 $cidade = $_POST['cidade'];
 $email = $_POST['email']; 
 //====================================================

 //REMETENTE --> ESTE EMAIL TEM QUE SER VALIDO DO DOMINIO
 //==================================================== 
 $email_remetente = "[email protected]"; // deve ser uma conta de email do seu dominio 
 //====================================================

 //Configurações do email, ajustar conforme necessidade
 //==================================================== 
 $email_destinatario = "[email protected]"; // pode ser qualquer email que receberá as mensagens
 $email_reply = "$email"; 
 $email_assunto = "Contato teste guru"; // Este será o assunto da mensagem
 //====================================================

 //Monta o Corpo da Mensagem
 //====================================================
 $email_conteudo = "Nome = $nome \n"; 
 $email_conteudo .= "Email = $email \n";
 $email_conteudo .= "Telefone = $cidade \n"; 
 //====================================================

 //Seta os Headers (Alterar somente caso necessario) 
 //==================================================== 
 $email_headers = implode ( "\n",array ( "From: $email_remetente", "Reply-To: $email_reply", "Return-Path: $email_remetente","MIME-Version: 1.0","X-Priority: 3","Content-Type: text/html; charset=UTF-8" ) );
 //====================================================

 //Enviando o email 
 //==================================================== 
 if (mail ($email_destinatario, $email_assunto, nl2br($email_conteudo), $email_headers)){ 
 echo "</b>E-Mail enviado com sucesso!</b>"; 
 } 
 else{ 
 echo "</b>Falha no envio do E-Mail!</b>"; } 
 //====================================================
} 
?>
  • The page /php/mail.php has more stuff, HTML etc.?

  • Hi Sam, yes, I just put in the same part of the form

  • Have you looked at the source code of the page what it shows? The form page is the same as where the form is sent?

  • I’ve seen it, nothing shows up.

2 answers

0

Add POST to method ( form tag property ), for example :

<form action='/php/mail.php' method="post">

For, in logic, no php file. you take the data with $_POST['nome_variavel'].

https://www.w3schools.com/tags/tag_form.asp

0

I believe the main error is in HTML. I noticed the missing tag closure form and the absence of the HTTP method type.

The default value of form for the HTTP method is GET

<div id="contact_form">
  <div class="form-group">
    <div class="row">
      <div class="col-md-6">
        <form action='/php/mail.php' method="POST">
          <div class="col-md-12">
            <label for="nome">Nome<span class="required">*</span></label>
            <input type="text" id="nome" name="nome" class="form-control input-field" required="">
          </div>
          <div class="col-md-6">
            <label for="cidade">Cidade<span class="required">*</span></label>
            <input type="text" id="cidade" name="cidade" class="form-control input-field" required="">
          </div>
          <div class="col-md-12">
            <label for="email">Email<span class="required">*</span></label>
            <input type="email" id="email" name="email" class="form-control input-field" required="">
          </div>
          <button type="submit" id="submit_btn" value="Submit" class="btn btn-primary">Enviar</button>
        </form>
      </div>
    </div>
  </div>
</div>

Browser other questions tagged

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