0
I’ve been finding a problem in making a contact form, because I’m not succeeding and I don’t know why it doesn’t work.
Follow applied code:
HTML
<form name="sentMessage" id="contactForm" method="POST" action="contact_me.php" novalidate>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<input type="text" class="form-control" placeholder="SEU NOME*" id="name" required data-validation-required-message="Seu nome faltou.">
<p class="help-block text-danger"></p>
</div>
<div class="form-group">
<input type="email" class="form-control" placeholder="SEU E-MAIL*" id="email" required data-validation-required-message="Por favor, adicione um email.">
<p class="help-block text-danger"></p>
</div>
<div class="form-group">
<input type="tel" class="form-control" placeholder="SEU TELEFONE*" id="phone" required data-validation-required-message="Por favor, adicione um telefone.">
<p class="help-block text-danger"></p>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<textarea class="form-control" placeholder="SUA MENSAGEM*" id="message" required data-validation-required-message="Por favor, adicione uma mensagem."></textarea>
<p class="help-block text-danger"></p>
</div>
</div>
<div class="clearfix"></div>
<div class="col-lg-12 text-center">
<div id="success"></div>
<button type="submit" class="btn btn-xl anime">ENVIAR MENSAGEM</button>
</div>
</div>
</form>
PHP
<?php
if (!$_POST['submit'])
{
$quebra_linha = "\n";
$emailsender = "[email protected]";
$nomeremetente = $_REQUEST['name'];
$emaildestinatario = "[email protected]";
$assunto = "[CONTATO] SITE RESPONSAVEL";
$mensagem = $_REQUEST['message'];
$email = $_REQUEST['email'];
$phone = $_REQUEST['phone'];
$mensagemHTML = ' Olá,
tenho uma nova mensagem para você diretamente do site!
Nome: '.$nomeremetente.' Assunto: '.$empresa.' E-mail: '.$email.' Telefone: '.$phone.' Mensagem: '.$mensagem.'';
$headers = "MIME-Version: 1.1".$quebra_linha;
$headers = "Content-type: text/html; charset=iso-8859-1".$quebra_linha;
$headers = "From: ".$emailsender.$quebra_linha;
$headers = "Reply-To: ".$emailsender.$quebra_linha;
if (mail($emaildestinatario, $assunto, $mensagemHTML, $headers, "-r". $emailsender)) {
echo "";
echo "";
} else {
echo "";
}
}
?>
Apparently the action=""
is not redirecting when I press the button submit
. I tried with Phpmailer too, but I find the same problem.
The index was saved as index.php and I tried using PHP_SELF
, but I wasn’t very successful either.
What error do you see? Or you’re not passing values?
– Max Rogério
Tip: In PHP there is a constant called
PHP_EOL
which can be used for line breaking.– Woss
No error is shown as it does not redirect to action;
– Pedro Perez
Considering the existence of attributes
data-validation-required-message
you must be using some JS library to validate the form. If so, what is it? Generally these libraries acting on the eventsubmit
form and, if somehow you are returningfalse
, the request is cancelled.– Woss
!$_POST['submit']
? Would not beif($_POST['submit'])
orif(isset($_POST['submit']))
? See in the browser F12 which is the answer and if the request is sent as you want, so you can isolate the problem, whether it is in the client or the server.– Inkeliz
Of the one
name
to thesubmit
, and puts in theif(isset($_POST['nomedosubmit'])){echo "Passou";}
– Max Rogério
If you do not change the end of the browser url to contact_me.php, then there is javascript blocking the form submission as reported by @Andersoncarloswoss, if you change the url, then just follow the comments of Inkeliz, Max Rogério and replies sent.
– Antonio Alexandre