I click on Ubmit to send email and he plays me on page 404.php

Asked

Viewed 74 times

0

What happens to you: When I click on the "Send" email button, it throws me to 404.php screen, not entering my function send_contact_form, which is inside Function.php. This function is the one that triggers emails, but does not fall within this function I don’t 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();?>

Function send_contact_form, 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();
}
  • places the code of send_contact_form(). Your form has no action so it should stay on the same page, something else is redirecting you to 404.

  • All right. It’s up there.

1 answer

0

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

Good and it looks like your Function.php won’t work even if the action is assigned. The function send_contact_form() was created but there is given to calling to be executed.

  • "Good and it looks like your Function.php won’t work even if the action is assigned. The send_contact_form() function was created but there is no calling given to be executed." I don’t understand.

  • Well you created the function "send_contact_form()" inside Function.php. When you send the form information to Function. he will return nothing. for there is no instruction that

Browser other questions tagged

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