Email form does not work on smartphones only!

0

Hello everyone! All right? This is my first post here. I have a silly problem, but there are three, four days! I started to develop recently and this is my first commercial project. It's pretty much done, but my email form is not working when the resolution is 360px (for smartphones). The funny thing is that it works for desktops, works on notebooks, tablets, but not mobile phones. Another important information is that it is not local, it is already on server.

For collecting and submitting information, I'm using PHPMailer. I'll pass the source code to please take a look!

In addition to PHPMailer, I'm also using the slim Framework v2 and bootstrap 3.

CONTACT FORM - DESKTOPS

 <div class="contato-Coluna1 col-sm-4 col-md-4 col-lg-4">
        <h4>ENTRE EM CONTATO</h4>
        <hr>

        <form action="mail" method="POST">
              <div class="form-group">
                <input type="text" class="form-control" name="campoNome" placeholder="Nome: ">                 
              </div>

              <div class="form-group">                  
                <input type="text" class="form-control" name="campoCidade" placeholder="Cidade: ">
              </div>

              <div class="form-group">                  
                <input type="email" class="form-control" name="campoEmail" placeholder="Email: ">
              </div>

              <div class="form-group">                  
                <input type="number" class="form-control" name="campoTelefone" placeholder="Telefone: ">
              </div>

              <div class="form-group">
                  <label for="comment">Deixe sua mensagem:</label>
                  <textarea class="form-control" rows="5" name="campoMensagem"></textarea>
              </div>                  

              <button type="submit" class="btn btn-primary" id="btnEnviarForm">Enviar</button>
        </form>
    </div>

MOBILE SOURCE CODE

    <div class="mobileContato visible-xs visible-sm">
    <h4 class="text-center">ENTRE EM CONTATO</h4>
        <hr>

        <form action="mail" method="POST">
              <div class="form-group">
                <input type="text" class="form-control" name="campoNome" placeholder="Nome: ">                 
              </div>

              <div class="form-group">                  
                <input type="text" class="form-control" name="campoCidade" placeholder="Cidade: ">
              </div>

              <div class="form-group">                  
                <input type="email" class="form-control" name="campoEmail" placeholder="Email: ">
              </div>

              <div class="form-group">                  
                <input type="number" class="form-control" name="campoTelefone" placeholder="Telefone: ">
              </div>

              <div class="form-group">
                  <label for="comment">Deixe sua mensagem:</label>
                  <textarea class="form-control" rows="5" name="campoMensagem"></textarea>
              </div>                  

              <button type="submit" class="btn btn-primary" id="btnEnviarForm">Enviar</button>
        </form>
</div>

PHPMAILER CONFIGURATION (I removed the information as emails and passwords here from the code, but in that part, everything is correct. So much so, as I said, to desktop it sends).

$app->post(
'/mail',
function () {

    $nome = $_POST['campoNome'];
    $cidade = $_POST['campoCidade'];
    $email = $_POST['campoEmail'];
    $tel = $_POST['campoTelefone'];
    $msg = $_POST['campoMensagem'];

    $mensagem = "<strong>Nome: </strong>" . $nome . "<br>";
    $mensagem .= "<strong>Cidade: </strong>" . $cidade . "<br>";
    $mensagem .= "<strong>Email: </strong>" . $email . "<br>";
    $mensagem .= "<strong>Telefone: </strong>" . $tel . "<br><br>";
    $mensagem .= "<strong>Mensagem: </strong>" . "<br>" . $msg;

    require_once("class/class.phpmailer.php");

    $mail = new PHPMailer(true);

    $mail->IsSMTP();

    try {
         $mail->Host = '' ; // Endereço do servidor SMTP (Autenticação, utilize o host smtp.seudomínio.com.br)
         $mail->SMTPAuth   = true;  // Usar autenticação SMTP (obrigatório para smtp.seudomínio.com.br)
         $mail->Port       = 587; //  Usar 587 porta SMTP
         $mail->Username = ''; // Usuário do servidor SMTP (endereço de email)
         $mail->Password = ''; // Senha do servidor SMTP (senha do email usado)

         //Define o remetente
         // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=    
         $mail->SetFrom('', ''); //Seu e-mail
         $mail->AddReplyTo('', ''); //Seu e-mail
         $mail->Subject = '' . $nome;//Assunto do e-mail

        //Define os destinatário(s)
         //=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
         $mail->AddAddress('', '');

         //Define o corpo do email
         $mail->MsgHTML('corpo do email'); 

         $mail->Body = $mensagem;

         $mail->Send();


         //caso apresente algum erro é apresentado abaixo com essa exceção.
        } catch (phpmailerException $e) {
            echo $e->errorMessage(); //Mensagem de erro costumizada do PHPMailer
          }
});

If you can help me with this, I'll be very grateful that you're only missing this to finalize the project.

Thanks everyone!

    
asked by anonymous 19.11.2017 / 19:42

1 answer

1

There is a conflict between forms on the page. When you submit the second form, you are actually submitting the first form. To avoid this, use the HTML5 formaction attribute on each button submit of each form.

You must also include the formmethod="post" attribute, and dispense the method="post" attribute in the tag <form> :

<form>
    <button formmethod="post" formaction="pagina1.php" type="submit">Enviar</button>
</form>

<form>
    <button formmethod="post" formaction="pagina2.php" type="submit">Enviar</button>
</form>

Compatibility:

References:

22.11.2017 / 04:09