1
I have faced a curious problem. I have drawn up a basic form in php
only to send email through the site. But I’m running some tests on the hosting service and I’ve been receiving several ghost emails before the test email.
I’ve researched to see if there’s something wrong with the code, but I believe as basic as it is, it’s okay. Someone can shed some light?
<?php
$msg=0;
@$msg= $_POST['msg'];?>
`<section class="form">
<?php if($msg=="enviado"): ?>
<h3>Mensagem enviada. Agradecemos seu contato!</h3>
<?php else: ?>
<form class="contact-form" action="contactForm.php" method="post">
<input type="text" id="name" name="name" placeholder="Nome completo">
<input type="text" id="mail" name="mail" placeholder="E-mail">
<input type="text" id="telephone" name="telephone" placeholder="Telefone">
<input type="text" id="company" name="company" placeholder="Sua empresa">
<input type="text" id="subject" name="subject" placeholder="Assunto">
<textarea id="message" name="message" placeholder="Deixe aqui sua mensagem!"></textarea>
<button class="btn btn-success" type="submit" name="submit">Enviar</button>
</form>
<?php endif; ?>
</section>`
<?php
$para= "[email protected]";
$assunto="Contato pelo Site.";
$name= $_POST['name'];
$mail= $_POST['mail'];
$telephone= $_POST['telephone'];
$company= $_POST['company'];
$subject= $_POST['subject'];
$msg= $_POST['message'];
$corpo= "<strong>Mensagem de contato!</strong><br><br>";
$corpo .= "<strong>Nome: </strong> $name<br><br>";
$corpo .= "<strong>E-mail: </strong> $mail<br><br>";
$corpo .= "<strong>Telefone: </strong> $telephone<br><br>";
$corpo .= "<strong>Empresa: </strong> $company<br><br>";
$corpo .= "<strong>Assunto: </strong> $subject<br><br>";
$corpo .= "<strong>Mensagem: </strong> $msg";
$header="Content-Type: text/html; charset= utf-8\n";
$header .="From: $mail Reply-to: $mail\n";
mail($para,$assunto,$corpo,$header);
header("location:index.php?msg=enviado");?>
doubt ever thought of using a framework like codeingiter? Te would solve a lot of aspects
– Gustavo Castro
What are these "ghost emails"?
– Sam
Isn’t it because the mail function will always be executed, even if you don’t click send? I think you have to have a condition first.
– Igor Henrique
@igorhenrique no, because the ghost emails appear along with the test email after clicking on Send.
– Juliano Eibel
@dvd When I click Send to a test email, I receive in my inbox the e-mail with Name, Asssunto, Email, etc filled as it was sent. But along with the test email comes two phantom emails, with no content filled.
– Juliano Eibel
Which comes first the filled or empty email?
– RpgBoss
@Rpgboss usually reach both voids before. There are times when two voids and two test equal.
– Juliano Eibel
is using sendmail?
– Igor Henrique
@igorhenrique no, only php’s mail function.
– Juliano Eibel
Why not use Php Mailer (https://github.com/PHPMailer/PHPMailer) ?
– Pedro Augusto