PHP mail does not send the email

0

I have encountered a problem in making a contact form because I am not succeeding and I do not know why it does not work.

Following 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 submit button. I tried with PHPMailer too, but I encounter the same problem. The index was saved as index.php and I tried to use PHP_SELF , but I did not get much success either.

    
asked by anonymous 21.02.2017 / 16:11

2 answers

4

There is no input with a submit name in your HTML. Soon, the if will never be executed. In fact, none of its inputs have the "name" attribute. The capture of a field sends via post is done through the name of this field. Example

<form method="post>
   <input type="text" name="nome_do_campo"/>
   <input type="submit" value="Enviar"/>
</form> 

PHP would catch the above field this way:

<?php
$campo = $_POST['nome_do_campo'];
?>

<?php
//Se quisermos executar o código só se o POST tiver sido feito:
if(isset($_POST['nome_do_campo']))
{
   $campo = $_POST['nome_do_campo'];
}
?>
    
21.02.2017 / 18:21
0

OPERA SUMMARY:

  

In PHP, take the deny sign (exclamation point) before $ _POST.

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

HTML Code Changes:

  

Give name for all inputs so that PHP can get HTML form data

<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*" name="name" 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*" name="email" 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*" name="phone" 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*" name="message" 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>
        <input type="submit" name="submit" value="vete" class="btn btn-xl anime">
    </div>
</div>
</form>
    
22.02.2017 / 03:14