0

Hi i've created this contact form to send messages.
I've read it many times and i haven't found anything wrong. Any tip?
When i press "enviar" (send) nothing happens. I've createad a new form option field related to "subject" ("assunto").
ps.:plz ignore the "mail@mail.com.br", in my tests i'm using the real one.

Hope you can help!

This is the PHP code i've inserted before the form tag. It's a code i've seen here but i've changed it to work to my site.

<?php $page = 'Contact'; 


    $to = "mail@mail.com.br"; 
    //$subject = "Company - Contato"; 

    if (isset($_POST['submit'])) { 

        // Error Checking 
        $errors = array(); 

        // Name Check 
        if (empty($_POST['name'])) { 
            $errors[] = 'Preencha corretamente o campo nome.'; 
        } 

        // Email Check 
        if (empty($_POST['email'])) { 
            $errors[] = 'Preencha corretamente o campo email.'; 
        } 

        // Assunto Check 
        if (empty($_POST['assunto'])) { 
            $errors[] = 'Preencha corretamente o campo assunto.'; 
        } 

        // Message check 
        if (empty($_POST['message'])) { 
            $errors[] = 'Preencha corretamente o campo mensagem'; 
        } 

        // If no errors - send email 
        if (empty($errors)) { 

            $name           = htmlentities($_POST['name']); 
            $email          = htmlentities($_POST['email']); 
            $assunto        = htmlentities($_POST['assunto']); 

            $subject = 'Company - Contato'; 

            $headers  = "From: $email" . "\r\n"; 
            $headers .= "Reply-To: $email" . "\r\n"; 
            $headers .= "MIME-Version: 1.0\r\n"; 
            $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; 

            $message = $_POST['message'];

            $message = '<html><body>'; 
            $message .= "<br />"; 
            $message .= "<br />"; 
            $message .= '<div style="font: 14px Arial, sans-serif; color: #333;">'; 
            $message .= "<b>Nome:</b> $name" . "\r\n"; 
            $message .= "<br />"; 
            $message .= "<b>Email:</b> $email" . "\r\n"; 
            $message .= "<br />"; 
            $message .= "<b>Assunto:</b> $assunto" . "\r\n"; 
            $message .= "<br />"; 
            $message .= "<b>Mensagem:</b>"; 
            $message .= "<br />"; 
            $message .= $_POST['message']; 
            $message .= "<br />"; 
            $message .= '</div>'; 
            $message .= "</body></html>"; 

            // Send Email 
            mail($to,$subject,$message,$headers); 

            // Set sent variable to allow sent message to be displayed 
            $sent = 'Sent'; 

        } 

    } 
    ?> 

    <?php if (!empty($errors)) { ?> 
        <div class="error"> 
            <ul> 
                <?php 

                foreach ($errors as $error) { 
                    echo '<li>'.$error.'</li>'; 
                } 

                ?> 
            </ul> 
        </div> 
    <?php } ?> 

    <?php if(isset($sent)) { ?> 
        <div class="success"> 
            <p>Sua mensagem foi enviada com sucesso.</p>
        </div> 
    <?php } ?>



Below i've inserted the form itself. As you can see, i've used the same 'names', but it's not working. :/

    <form name="htmlformContato" class="form-horizontal"  action="" accept-charset="UTF-8" method="post">


    <div class="col-sm-6 col-xs-12">

              <div class="form-group col-sm-12">
              <label for="inputNome" class="control-label">Nome *</label>
              <input id="inputNome" type="text" class="form-control" name="name" value="<?php echo $_POST['name']; ?>" />
              </div> 

              <div class="form-group col-sm-12">
              <label for="inputEmail" class="control-label">Email *</label>
              <input id="inputEmail" type="text" class="form-control" name="email" value="<?php echo $_POST['email']; ?>" />
              </div>


              <div class="form-group col-sm-12">
              <label for="inputAssunto" class="control-label">Assunto *</label>
              <select class="form-control" name="assunto">
                <option value="SelecioneAssunto">Selecione o assunto</option>
                <option value="Duvidas">Dúvidas</option>
                <option value="Sugestoes">Sugestões</option>
                <option value="Reclamacoes">Reclamações</option>
                <option value="Outro">Outro</option>
              </select>
              </div>                                  

    </div>


    <div class="col-sm-6 col-xs-12">

              <div class="form-group col-sm-12">
              <label for="inputMensagem" class="control-label">Mensagem *</label>
              <textarea class="form-control" rows="9" id="inputMensagem" name="message"><?php echo $_POST['message']; ?></textarea>
              </div>

    </div>

    <div class="col-xs-12">

              <div class="form-group col-xs-12">          
              <button type="submit" class="btn btn-bodyupA">Enviar</button>          
              </div>

    </div>          

    </form>                                                     
Timothy Randall
  • 17,634
  • 1
  • 15
  • 27
Alexandre
  • 3
  • 2
  • This might be a silly question, but the server where you are hosting the website has PHP installed right? Have you checked your browsers inspector to further diagnose using the network / console tabs? – Timothy Randall Jan 31 '14 at 22:25

3 Answers3

4
<button type="submit" class="btn btn-bodyupA">Enviar</button>   

should be:

<input type="submit" value="Enviar" class="btn btn-bodyupA">   
John Conde
  • 217,595
  • 99
  • 455
  • 496
  • Actually the tag "button" is not the problem because it's a bootstrap tag. Anyway i've changed it for the input and anything happened. – Alexandre Jan 31 '14 at 22:03
  • @Alexandre Both ways nothing will happen because of the name attribute. Your block is surrounded by `if(isset($_POST['submit']))` but not field with submit name is present – Royal Bg Jan 31 '14 at 22:09
1

Doesn't matter if you use input or button as long as they have type="submit" but you have to set name since you have if (isset($_POST['whatevername'])) {

<button name="whatevername" type="submit" class="btn btn-bodyupA">Enviar</button>

or

<input name="whatevername" type="submit" class="btn btn-bodyupA" value="Enviar">

Either will work just fine.

Also <button> vs. <input type="button" />. Which to use?

Community
  • 1
  • 1
Ergec
  • 11,608
  • 7
  • 52
  • 62
  • I think he uses button, because he has CSS which apply rules to all HTML elements of type button, which I don't think will work if it's `input type=button`. Correct me if wrong – Royal Bg Jan 31 '14 at 22:19
  • @RoyalBg just wanted to clarify that they both work as expected and submit the form. – Ergec Jan 31 '14 at 22:22
  • Adding name solved the problem! :) Everything if fine now. Tested and working. Both option works, input or button. I've also changed the charset to UTF-8 so special characters could be used. Thanks everyone! – Alexandre Jan 31 '14 at 22:39
0

add name="submit"

<button type="submit" name="submit" class="btn btn-bodyupA">Enviar</button>  
Ant
  • 118
  • 3
  • Thought it was pretty self explanatory seeing how he has the name field in all his other form elements. – Ant Jan 31 '14 at 23:31