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 "[email protected]", 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 = "[email protected]"; 
    //$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>                                                     
1
  • 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? Commented Jan 31, 2014 at 22:25

3 Answers 3

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

should be:

<input type="submit" value="Enviar" class="btn btn-bodyupA">   
Sign up to request clarification or add additional context in comments.

2 Comments

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 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
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?

3 Comments

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
@RoyalBg just wanted to clarify that they both work as expected and submit the form.
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!
0

add name="submit"

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

1 Comment

Thought it was pretty self explanatory seeing how he has the name field in all his other form elements.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.