-1
My goal is to create a contact form, where the user entered his name, email and message. The moment you clicked on "send message" I, being an administrator, would receive an email, with the user’s data and the corresponding message. At the moment, the message sends, but sends empty for example:
Responda a:
Nome do Utilizador:
Email do Utilizador
Mensagem do Utilizador:
When sending the message there is also another problem that appears a new page, with the same form but without css, I do not know what is due
//Formulário contactos.php
<div class="col-md-7 mb-5 site-animate">
<form action="index.php?cmd=contform" method="post">
<div class="form-group">
<label for="name" class="sr-only">Nome</label>
<input type="text" class="form-control" id="NomeM" placeholder="Nome">
</div>
<div class="form-group">
<label for="email" class="sr-only">Email</label>
<input type="text" class="form-control" id="EmailMen" placeholder="Email">
</div>
<div class="form-group">
<label for="message" class="sr-only">Mensagem</label>
<textarea name="message" id="Mensagem" cols="30" rows="10" class="form-control" placeholder="Escreva a sua mensagem"></textarea>
</div>
<div class="form-group">
<input type="submit" name="submit" class="btn btn-primary btn-lg" value="Enviar Mensagem">
</div>
</form>
</div>
//Ficheiro contform.php
<?php
$sql="select * from Mensagem ";
$res=$lig->query($sql);
$lin = $res->fetch_array();
$NomeM = $_POST['NomeM'];
$Email = $_POST['EmailMen'];
$Mensagem = $_POST['Mensagem'];
$email_from = '[email protected]';
$email_subject = "New Form Submission";
$email_body = "Nome do Utilizador:" .$lin['NomeM']."\n".
"Email do Utilizador:".$lin['EmailMen']."\n".
"Mensagem do Utilizador:".$lin['Mensagem']."\n";
$to = "[email protected]";
$headers = "De: $email_from \r\n";
$headers .= "Responda a: ".$lin['EmailMen']."\r\n";
mail($to,$email_subject,$email_body,$headers);
header("Location: Contactos/contactos.php");
?>
And what is the value of your variable
$lin
? Stick to the verb is and not which should be.– Woss
The $Lin variable does not have a value, it is simply used to fetch data from my database
– Someone
Someone, exactly. Is she searching the data correctly? What is the result of
var_dump($lin)
? What are the latest messages in your server’s error log and what are your PHP error display settings?– Woss
Does not return any error to me, nor does it display any error message
– Someone
And what is the return of
var_dump
? About the errors, checked the log file or only on screen?– Woss
None, I simply checked on the screen, I have no log file
– Someone
If
var_dump
You haven’t returned anything, there’s something very wrong there and maybe that’s why you’re sending it all blank. If the variable has no value, you have nothing to send in the email.– Woss
Take the opportunity to read how to properly configure your development environment to properly display error messages: https://answall.com/q/106562/5878
– Woss
I noticed that you are using Mysqli to search for information in the database, in which case I suggest you see this tutorial if applicable. http://blog.thiagobelem.net/gui-pratico-de-mysqli-no-php You must create the
query
, then prepare it to run, as you are not passing parameters, you can skip the part of thebind_param
, Next you need theexecute
and finally thefetch
.– Franck Costa
Thank you, I’ll try!
– Someone
I have already analyzed the document and still do not know how to correct my mistake
– Someone