Email form does not only work on smartphones!

Asked

Viewed 121 times

0

Hey, guys! All right? This is my first post here. I’m in a bit of a silly problem, but three, four days ago! I started to develop recently and this is my first commercial project. It’s practically ready, but my email form isn’t working when the resolution is 360px (for smartphones). The funny thing is that it works for desktops, it works on laptops, tablets, but not for mobile. Another important information is that it is not local, it is already on server.

For the collection and sending of the information, I am using Phpmailer. I will pass the source codes 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>

SOURCE CODE MOBILE VERSION

    <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 like emails and passwords here from the code, but in this part, it’s all right. So much so that, as I said, for 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 then help me in this, I will be very grateful because this is all missing to finish the project.

Thanks a lot!

  • Post the section that triggers the sending of the email...

  • Sorry @Pra! I could only see your message now! So actually for the desktop version there is a navigation link "Contact.php" where the person enters and there, in addition to the Google Maps map, has a contact form. This one is working normally. I tested and rerouted the messages to my particular email and are coming in normally. For the "mobile" version, I left the contact form already in the "index" with the intention of being something more objective. And that’s the one that won’t go at all. When you click send, it’s like you refresh the page, but it doesn’t send.

  • @Andrébaill thanks for the answer, only that, in fact, it would be that part of phpmailer that sends, or am I wrong? Sorry my inexperience!

  • Good night! All jewels? Exact, @ːvː, is EXACTLY that. I did the following (I will list to not confuse): 1. The idea is to have a confirmation for both desktop and mobile. 2. The desktop version works. If you submit, it gives a refresh and in the div that is the form, it is replaced by a successfully sending phrase. 3. In the case of mobile, I had done the same thing, but that doesn’t happen. When you click on "send", it gives the refresh, but it’s as if you have pressed F5. Does not appear the sending phrase and also does not send.

  • (continuing the previous message) Yesterday I noticed something strange. For sending form data, I used the POST. Only on mobile, bizarrely, when you click "Send", it gives the refresh as I said, but it leaves the content in the browser’s address bar, as if it were a GET, but nowhere in the codes has the GET, especially for this. I only use the post. Since you are already helping me, to try to improve, I climbed the site on the server, if you want to take a look or do some test, feel free, the emails fall in my private email! www.sabconsel.com.br Valeu! :)

  • Your evil has come here! = D

  • Because it occurred to me that it might be some mail crash, some incompatibility. So I did a mobile action, only the codes are the same, actually. It was more to test, see if there could be any kind of incompatibility even. But the two are the same. I tried to leave the mail to both, but it didn’t work either. What intrigued me even more is this "GET" format in the address bar

  • Another email came with the blank fields [for information purposes only]

  • All right, I’ll do it! And I’ll leave it in the footer too or just in the same head?

  • I put everything in the <head> and, due to doubts, I left commented everything that was on the footer ;)

  • So, in theory it was not to influence, because theoretically, the form is passing the same information to the same place. I even use the same fields. He plays for the Slim Framework and this does the entire sending process using phpmailer. But honestly, I don’t rule that out! I think I’ll take a test then. In the mobile version, I wanted to make the site as direct as possible, but I will recreate the "contact" page and see if it works. If it works, besides my head give a final screw, ahaha, I will be very happy and I will put your name in the codes as thanks! kkkk

Show 6 more comments

1 answer

1


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

It is necessary also include the attribute formmethod="post", and dispense with the attribute method="post" in 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:

inserir a descrição da imagem aqui

References:

  • Dude, we’re almost there!! Through what you said, I remade some things here and now at least he sends the email, the only thing is that it sends with all the empty fields. But that I can see later!! I just wanted to thank you for ALL this attention and for all the willingness to help! THANK YOU very much!!! Good, whether it works or not, I see here you talk to give you a consiferação! Abração cara!! Ótimo quarta! = D

  • Man, thank you very, very, very much!!! It worked right here, finally!! You took a huge weight off my back! It’s my first commercial project, so imagine the pressure, ahahah (that’s because it’s a simple site!) As I said above, thank you for all the attention you’ve given! I hope one day I can reciprocate! And it’s already marked !! Thanks! = D

Browser other questions tagged

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