Good afternoon, guys! I'm super beginner in programming and I'm trying to edit a template, but the contactform part is not working. If anyone can give me a light, I will be very grateful. Below the HTML:
Contact us
<form id="contactForm" action="sendemail.php" method="POST">
<div class="form-group">
<label for="InputName">Nome</label>
<input type="text" name="name" required="" class="form-control" id="InputName"
placeholder="Nome completo">
</div>
<div class="form-group">
<label for="InputEmail">Email</label>
<input type="email" name="email" required="" class="form-control" id="InputEmail"
placeholder="Email">
</div>
<div class="form-group">
<label for="InputSubject">Assunto</label>
<input type="text" name="subject" class="form-control" id="InputSubject"
placeholder="Assunto">
</div>
<div class="form-group">
<label for="message-text" class="control-label">Mensagem</label>
<textarea class="form-control" rows="4" required="" name="message" id="message-text"
placeholder="Escreva aqui sua mensagem"></textarea>
</div>
<button type="submit" class="btn btn-primary">Enviar</button>
</form>
And PHP:
session_cache_limiter( 'nocache' );
header( 'Expires: ' . gmdate( 'r', 0 ) );
header( 'Content-type: application/json' );
$to = '[email protected]'; //put your email here
$email_template = 'simple.html'; // will find it on email-templates/ directory
$subject = "SUBJECT";
$email = strip_tags($_POST['email']);
$name = strip_tags($_POST['name']);
$message = nl2br( htmlspecialchars($_POST['message'], ENT_QUOTES) );
$result = array();
if(empty($name)){
$result = array( 'response' => 'error', 'empty'=>'name', 'message'=>'<strong>Erro!</strong> Preencha seu nome.' );
echo json_encode($result );
die;
}
if(empty($email)){
$result = array( 'response' => 'error', 'empty'=>'email', 'message'=>'<strong>Erro!</strong> Preencha seu email.' );
echo json_encode($result );
die;
}
if(empty($message)){
$result = array( 'response' => 'error', 'empty'=>'message', 'message'=>'<strong>Erro!</strong> Sua mensagem está vazia.' );
echo json_encode($result );
die;
}
$headers = "From: " . $name . ' <' . $email . '>' . "\r\n";
$headers .= "Reply-To: ". $email . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=UTF-8\r\n";
$templateTags = array(
'{{subject}}' => $subject,
'{{email}}' =>$email,
'{{message}}' =>$message,
'{{name}}' =>$name
);
$templateContents = file_get_contents( dirname(__FILE__) . '/email-templates/'.$email_template);
$contents = strtr($templateContents, $templateTags);
if ( mail( $to, $subject, $contents, $headers ) ) {
$result = array( 'response' => 'success', 'message'=>'<strong>Sucesso!</strong> Email enviado.' );
} else {
$result = array( 'response' => 'error', 'message'=>'<strong>Erro!</strong> O email não pôde ser enviado.' );
}
echo json_encode( $result );
die;
Summary, I can not get HTML to pull PHP and submit the form. Only thing that appears is the PHP code itself. If anyone can help me, thank you very much