PHP form is sending duplicate messages

Asked

Viewed 49 times

0

I have a form for sending emails and although it is working - when sending the message - it presents a problem where when receiving these messages in the recipient’s email, it comes duplicated.

One message arrives normal with all fields filled and the other comes with empty fields.

Can you help me in what may be happening?

The code is this below:

<?php
  ini_set("SMTP", "localhost");
  $nome = $_POST['nome'];
  $email = $_POST['email'];
  $telefone = $_POST['telefone'];
  $mensagem = $_POST['mensagem'];

  $dpto = "[email protected]";
  $Titulo = "MENSAGEM ENVIADA PELO FORMULÁRIO DO SITE";
  $Destinatario = "$dpto";
  $mensagem1 = "
  Nome: $nome
  E-mail: $email
  Telefone: $telefone
  $mensagem";
  mail("$Destinatario","$Titulo","$mensagem1","From:$email");
?>
  • How are you calling this code? is using ajax? or a simple form?

  • Hi Wictor. I am using a simple form: <form action="<? $PHP_SELF; ? >" method="POST">

  • PHP itself is working correctly, I did a test here and received the mail straight.

  • Truth Leo ... is right. I just don’t understand why I get the duplicate message

  • so it’s nothing with PHP, I didn’t get duplicate

  • Try replacing $PHP_SELF with $_SERVER["PHP_SELF"]

  • I will then see outside of PHP what it can be. Thank you very much Leo for taking the test and for your return !!

  • Obrigado Wictor !!

  • even though this variable $PHP_SELF has not been declared, the code works the same way

  • Yes you can @Leocaracciolo. Later I will see better what may have been and leave reply here from the solution. Thanks again !!

  • Fernanda, what form of verification do you use to enter this sending code? (e.g.., isset to see if the variables coming from the form have data).

Show 6 more comments
No answers

Browser other questions tagged

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