I click submit to send email and it plays me on page 404.php

0

What happens: When I click the "Send" email button, it throws me to the 404.php screen, not entering my send_contact_form function, which is inside the function.php. This function is the one that makes the email shots, but it does not fall within that function I do not know why.

<?php /* Template Name: Contato */

get_header();
get_template_part( 'components/header/header', 'text' );
$options = get_option('theme_options');
?>

<div class="container">
     <div class="col-md-8 panel-custom">

        <div class="card container-quem_somos">

<?php if ( $_SERVER['REQUEST_METHOD'] == "POST" ){
    //função que envia um formulario p/ o email ( dentro de function.php)
    send_contact_form();

} else { ?>
            <form class="form-horizontal" method="post">
                <h4 class="content-header">Fale conosco</h4>
                <fieldset>
                    <div style="padding:30px 0 31px 0;" class="grey-text">
                        <span class="grey-text">
                            Fique à vontade para nos contatar a qualquer momento através de nosso formulário de contato. Caso prefira entrar em contato por outros meios, <u>verifique os telefones e endereços dos nossos escritórios</u>.
                        </span>
                        <div class="form-group">
                             <div class="col-lg-8">
                                 <label class="control-label label-text" for="inputName">Nome*</label>
                                 <input type="text" class="form-control input-custom" name="name" id="inputName" placeholder="" required>

                             </div>
                         </div>
                         <div class="form-group">
                             <div class="col-lg-8">
                                 <label class="control-label label-text" for="inputEmail">E-mail*</label>
                                 <input type="text" class="form-control input-custom" name="email" id="inputEmail" placeholder="" required>

                             </div>
                         </div>
                         <div class="form-group">
                             <div class="col-lg-8">
                                 <label class="control-label label-text" for="inputPhone">Telefone</label>
                                 <input type="tel" class="form-control input-custom" name="phone" id="inputPhone" placeholder="">
                             </div>
                         </div>
                         <div class="form-group">
                             <div class="col-lg-8">
                                 <label class="control-label label-text" for="inputMensagem">Mensagem</label>
                                 <textarea type="text" class="form-control input-custom" name="message" rows="3" id="inputMensagem" placeholder="" required></textarea>

                             </div>
                         </div>
                         <div class="form-group">
                             <div class="col-lg-8">
                                 <div class="more" style="text-align:left;margin-top:14px">
                                     <input type="submit" name="submit" style="width:120px"/>
                                 </div>
                            </div>
                        </div>

                    </div>
                </fieldset>
            </form>
<?php } ?>
        </div>
    </div>
</div>

<?php
get_footer();?>

send_contact_form function, which is inside funciton.php

function send_contact_form(){

    require(ABSPATH . WPINC . '/class-phpmailer.php');
    require(ABSPATH . WPINC . '/class-smtp.php');

    date_default_timezone_set('America/Sao_Paulo');//corrige hora local
    $siteurl = trailingslashit( get_option('home') );
    $mail = new PHPMailer();
    $mail->IsSMTP();
    $mail->CharSet='UTF-8';

    $mail->From = get_option('smtp_user');
    $mail->FromName = get_option('blogname');
    $mail->Subject = '['. get_option('blogname') .'] nova mensagem';
    $mail->AddReplyTo = $_POST['email'];
    $mail->Sender = get_option('smtp_user');
    //SMTP Config
    $mail->Host = get_option('smtp_host');
    //Descomente as opções abaixo se for usar SMTP autenticado. Lembre-se que isto requer que o e-mail seja do domínio do site.
    //$mail->SMTPAuth = true;
    //$mail->Username = get_option('smtp_user');
    //$mail->Password = get_option('smtp_pass');

    $mail->AddAddress( get_option('mail_from') );

    $message  = 'Prezado Administrador,' . "\r\n\r\n";
    $message .= 'Uma nova mensagem foi enviada em ' .date("d/m/Y \à\s H:i:s"). "\r\n\r\n";
    $message .= 'MENSAGEM:' . "\r\n";
    $message .= '------------------------' . "\r\n";

    /*****************************
    no array abaixo, coloque o nome dos campos que quer remover do corpo da mensagem
     *******************************/
   /* $campos_excluidos = array('submit');

    while(list($campo, $valor) = each($_POST)){
        if( !in_array( $campo, $campos_excluidos ) ){

            $message.= ucfirst($campo) .":  ". $valor . "\r\n\r\n";
        }

    }*/

    $message .= '-------------------------' . "\r\n\r\n";
    $message .= 'Atenciosamente,' . "\r\n";
    $message .= get_option('blogname') . "\r\n";
    $message .= $siteurl . "\r\n\r\n\r\n\r\n";

    $mail->Body = $message;

    // Send Email.
    if(!$mail->Send()){
        echo '<div class="msg_erro">
                <h3>Erro!</h3>
                <p>A mensagem não pôde ser enviada. Por favor, tente novamente.</p>
                <p>[ Erro: ' . $mail->ErrorInfo . ' ]</p>
              </div>';

    } else {
        echo '<div class="msg_sucesso">
                  <h3>Sucesso!</h3>
                  <p><strong>Sua mensagem foi enviada corretamente!</strong></p>                
              </div>';
    }

    $mail->ClearAllRecipients();
}
    
asked by anonymous 26.11.2016 / 19:42

1 answer

0

Your form is without the action="" attribute inside it, and the path to which the information will be sent is defined. ex: form method="POST" action="/function.php"

Well, it looks like your function.php will not work even though the action is assigned. The send_contact_form() function was created but there is no given calling to be executed.

    
27.11.2016 / 17:34