Contact form 2018

Asked

Viewed 46 times

0

Good afternoon, you guys! I’m super beginner in programming and I’m trying to edit a template, but the contactform part isn’t working. If anyone can shed some light on this, I’d be very grateful. Below the HTML:

Get in touch

                <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’t get HTML to pull PHP and send the form. Only thing that appears is the PHP code itself. If anyone can help me, I’d really appreciate it

  • Check that your code does not contain tags <?php and ?> which must be at the beginning and end of the document, respectively

  • In addition to being among the PHP tags themselves, your application must be running on a web server with PHP support. Open the file under the protocol file:// will not work - or server that does not support PHP.

  • the script starts with <?php and ends with ? >. I work with Hostinger, I believe it has support because on another site I used a php template and worked well.

  • Another site is another site. How is the setup for this specific?

  • The problem is that the web server is not interpreting php code...

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.