Hi i've created this contact form to send messages.
I've read it many times and i haven't found anything wrong. Any tip?
When i press "enviar" (send) nothing happens. I've createad a new form option field related to "subject" ("assunto").
ps.:plz ignore the "mail@mail.com.br", in my tests i'm using the real one.
Hope you can help!
This is the PHP code i've inserted before the form tag. It's a code i've seen here but i've changed it to work to my site.
<?php $page = 'Contact';
$to = "mail@mail.com.br";
//$subject = "Company - Contato";
if (isset($_POST['submit'])) {
// Error Checking
$errors = array();
// Name Check
if (empty($_POST['name'])) {
$errors[] = 'Preencha corretamente o campo nome.';
}
// Email Check
if (empty($_POST['email'])) {
$errors[] = 'Preencha corretamente o campo email.';
}
// Assunto Check
if (empty($_POST['assunto'])) {
$errors[] = 'Preencha corretamente o campo assunto.';
}
// Message check
if (empty($_POST['message'])) {
$errors[] = 'Preencha corretamente o campo mensagem';
}
// If no errors - send email
if (empty($errors)) {
$name = htmlentities($_POST['name']);
$email = htmlentities($_POST['email']);
$assunto = htmlentities($_POST['assunto']);
$subject = 'Company - Contato';
$headers = "From: $email" . "\r\n";
$headers .= "Reply-To: $email" . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message = $_POST['message'];
$message = '<html><body>';
$message .= "<br />";
$message .= "<br />";
$message .= '<div style="font: 14px Arial, sans-serif; color: #333;">';
$message .= "<b>Nome:</b> $name" . "\r\n";
$message .= "<br />";
$message .= "<b>Email:</b> $email" . "\r\n";
$message .= "<br />";
$message .= "<b>Assunto:</b> $assunto" . "\r\n";
$message .= "<br />";
$message .= "<b>Mensagem:</b>";
$message .= "<br />";
$message .= $_POST['message'];
$message .= "<br />";
$message .= '</div>';
$message .= "</body></html>";
// Send Email
mail($to,$subject,$message,$headers);
// Set sent variable to allow sent message to be displayed
$sent = 'Sent';
}
}
?>
<?php if (!empty($errors)) { ?>
<div class="error">
<ul>
<?php
foreach ($errors as $error) {
echo '<li>'.$error.'</li>';
}
?>
</ul>
</div>
<?php } ?>
<?php if(isset($sent)) { ?>
<div class="success">
<p>Sua mensagem foi enviada com sucesso.</p>
</div>
<?php } ?>
Below i've inserted the form itself. As you can see, i've used the same 'names', but it's not working. :/
<form name="htmlformContato" class="form-horizontal" action="" accept-charset="UTF-8" method="post">
<div class="col-sm-6 col-xs-12">
<div class="form-group col-sm-12">
<label for="inputNome" class="control-label">Nome *</label>
<input id="inputNome" type="text" class="form-control" name="name" value="<?php echo $_POST['name']; ?>" />
</div>
<div class="form-group col-sm-12">
<label for="inputEmail" class="control-label">Email *</label>
<input id="inputEmail" type="text" class="form-control" name="email" value="<?php echo $_POST['email']; ?>" />
</div>
<div class="form-group col-sm-12">
<label for="inputAssunto" class="control-label">Assunto *</label>
<select class="form-control" name="assunto">
<option value="SelecioneAssunto">Selecione o assunto</option>
<option value="Duvidas">Dúvidas</option>
<option value="Sugestoes">Sugestões</option>
<option value="Reclamacoes">Reclamações</option>
<option value="Outro">Outro</option>
</select>
</div>
</div>
<div class="col-sm-6 col-xs-12">
<div class="form-group col-sm-12">
<label for="inputMensagem" class="control-label">Mensagem *</label>
<textarea class="form-control" rows="9" id="inputMensagem" name="message"><?php echo $_POST['message']; ?></textarea>
</div>
</div>
<div class="col-xs-12">
<div class="form-group col-xs-12">
<button type="submit" class="btn btn-bodyupA">Enviar</button>
</div>
</div>
</form>