0
I have a problem with a website that is one page, and before I had this php:
<?php
if (isset($_POST["submit"])) {
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$from = '';
$to = '[email protected]';
$subject = $_POST['subject'];
$body ="De: $name\nMensagem:\n $message";
if (!$_POST['name']) {
$errName = 'Por favor insira o seu nome';
}
if (!$_POST['email'] || !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
$errEmail = 'Por favor insira um endereço de email válido';
}
if (!$_POST['subject']) {
$errSubject = 'Por favor insira o assunto da sua mensagem';
}
//Check if message has been entered
if (!$_POST['message']) {
$errMessage = 'Por favor escreva a sua mensagem';
}
if (!$errName && !$errEmail && !$errSubject && !$errMessage) {
if (mail ($to, $subject, $body, $email)) {
$result='<div class="alert alert-success">Obrigado sr/(a) '. $name .'! Entraremos em contacto consigo brevemente.</div>';
} else {
$result='<div class="alert alert-danger">Desculpa ocorreu um erro ao enviar a sua mensagem. Por favor tente mais tarde.</div>';
}
}
}
to send mails together with this form:
<div id="formul" class="row">
<div class="col-md-offset-1 col-md-10">
<form class="form-horizontal" role="form" method="post" action="index.php#formul">
<div class="form-group">
<div class="col-md-offset-2 col-md-8">
<input type="text" class="form-control" id="name" name="name" placeholder="Nome:" value="<?php echo htmlspecialchars($_POST['name']); ?>">
<?php echo "<p class='text-danger'>$errName</p>";?>
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-8">
<input type="email" class="form-control" id="email" name="email" placeholder="E-mail:" value="<?php echo htmlspecialchars($_POST['email']); ?>">
<?php echo "<p class='text-danger'>$errEmail</p>";?>
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-8">
<input type="text" class="form-control" name="subject" placeholder="Assunto:" value="<?php echo htmlspecialchars($_POST['subject']); ?>">
<?php echo "<p class='text-danger'>$errSubject</p>";?>
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-8">
<textarea class="form-control" rows="3" placeholder="Mensagem:" name="message"><?php echo htmlspecialchars($_POST['message']);?></textarea>
<?php echo "<p class='text-danger'>$errMessage</p>";?>
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-8">
<input id="submit" name="submit" type="submit" value="Enviar Mensagem" class="btn btn-theme btn-lg btn-block">
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-8">
<?php echo $result; ?>
</div>
</div>
</div>
</form>
</div>
</div>
It turns out that it stopped sending mails because I heard that Servers do not allow the mail() function, I’ve heard about phpmailer but I don’t understand how it works and I can’t get it to look like this before, someone, can help me?
The page keeps loading and does not send anything or give any error.. :/
– user53686