Contact form does not work

Asked

Viewed 252 times

3

I’m having the following problems in the form I’ve assembled:

  • The form is not sent to the email.
  • After clicking on Ubmit, pressing to reload the page gives the conflict of "Confirm the resubmit of the form".

That is the Code:

<div class="form-dicas">
    <div class="sombra"></div>

    <div class="wrp-dicas clearfix">
        <div id="dicas" class="dicas">
            <img class="botao-fechar-x" src="images/botao-x.png">
            <?php
                if (isset($_POST['submit'])) {

                    unset($_POST['submit']);

                    $name        =   $_POST['name'];
                    $email       =   $_POST['email'];
                    $facebook    =   $_POST['facebook'];
                    $twitter     =   $_POST['twitter'];
                    $msg         =   $_POST['msg'];

                    $headers  = "From: ".$email."\r\n";
                    $headers .= "MIME-Version: 1.0";
                    $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";

                    $subject  = "Formulário de - ".$name;

                    $corpo  = "Nome: " . $name . "\n";
                    $corpo .= "Email: " . $email . "\n";
                    $corpo .= "Facebook: " . $facebook . "\n";
                    $corpo .= "twitter: " . $twitter . "\n";
                    $corpo .= "Mensagem: " . $msg . "\n";

                    $email_to = '[email protected]';
                    mail($email_to, $subject, $corpo, $headers);
                }
            ?>
            <form action="" method="post">
                <ul>
                    <li class="name">
                        <label for="name">Nome:</label>
                        <input required id="name" name="name" type="text" />
                    </li>
                    <li class="facebook">
                        <label for="facebook">Facebook (opcional):</label>
                        <input id="facebook" name="facebook" type="text" />
                    </li>
                    <li class="twitter">
                        <label for="twitter">Twitter (opcional):</label>
                        <input id="twitter" name="twitter" type="text" />
                    </li>
                    <li class="email">
                        <label for="email">E-mail:</label>
                        <input required id="email" name="email" type="text" />
                    </li>
                    <li class="msg">
                        <label for="msg">Mensagem:</label>
                        <textarea required id="msg" name="msg" type="text"></textarea>
                    </li>
                    <li class="submit">
                        <input id="send_form" type="submit" name="submit" value="Enviar" />
                    </li>
                </ul>
            </form>
        </div><!-- div wrp-dicas -->
    </div><!-- div sombra -->
</div><!-- div form-dicas -->

There’s also a little bit of jquery, which I think is irrelevant, but here it is:

<script type="text/javascript">
    var $j = jQuery.noConflict();
    $j(document).ready(function() {

        $j(".clique-aqui").click(function() {
            $j(".form-dicas").fadeIn('slow');
        });

        $j(".botao-fechar-x").click(function() {
            $j(".form-dicas").fadeOut("slow");
        });

        $j(document).bind('keydown', function(e) { 
            if (e.which == 27) {
                $j(".form-dicas").fadeOut("slow");
            }
        }); 
    });
</script>

I’m using the xampp to test this form, could help me in what I did wrong?

Thanks!

  • The email server has been configured in windows?

  • @rray How so? I’m at work and had a functional form tested with shampoo here recently but it’s been lost and I’m trying to redo it. I tested with my personal email and worked the old form.

1 answer

2


The problem is in the XAMP configuration, I suggest testing on a server outside the localhost, if possible. But if you want to keep it there you have to change the settings:

PHP.INI:

  • C: xampp php.ini

    1. Remove the ; before the extension=php_openssl.dll
    2. Find the [mail function] and change them to:
SMTP = smtp.gmail.com
smtp_port = 465
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"
mail.add_x_header=Off
sendmail_from = [email protected]

sendmail.ini

  • C: xampp sendmail sendmail.ini

    1. Edit the following lines:
smtp_server=smtp.gmail.com
smtp_port=465
smtp_ssl=ssl
error_logfile=error.log
debug_logfile=debug.log
[email protected]
auth_password=sua_senha
pop3_server=
pop3_username=
pop3_password=
[email protected]
force_recipient=
hostname=smtp.gmail.com

I think this will solve!

  • Thanks even! But if I test just putting inside wordpress, the form would work?

  • I think it would work normally, but Wordpress has a function of its own, called wp_mail(), see http://codex.wordpress.org/Function_Reference/wp_mail. But, I think it would be okay to use mail().

Browser other questions tagged

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