Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Contoh form kontak dengan PHP yang terkirim ke email
$statusMsg = '';
$msgClass = '';
// Get the submitted form data
$email = $_POST['email'];
$name = $_POST['name'];
$subject = $_POST['subject'];
$message = $_POST['message'];
// Cek apakah ada data yang belum diisi
if(!empty($email) && !empty($name) && !empty($subject) && !empty($message)){
if(filter_var($email, FILTER_VALIDATE_EMAIL) === false){
$statusMsg = 'Please enter your valid email.';
$msgClassk = 'errordiv';
// Pengaturan penerima email dan subjek email
$toEmail = ''; // Ganti dengan alamat email yang Anda inginkan
$emailSubject = 'Pesan website dari '.$name;
$htmlContent = '<h2> via Form Kontak Website</h2>
// Mengatur Content-Type header untuk mengirim email dalam bentuk HTML
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
// Header tambahan
$headers .= 'From: '.$name.'<'.$email.'>'. "\r\n";
// Send email
$statusMsg = 'Pesan Anda sudah terkirim dengan sukses !';
$msgClass = 'succdiv';
$statusMsg = 'Maaf pesan Anda gagal terkirim, silahkan ulangi lagi.';
$msgClass = 'errordiv';
$statusMsg = 'Harap mengisi semua field data';
$msgClass = 'errordiv';
<!DOCTYPE html>
<title>Kontak Form dengna PHP |</title>
.mainContent {
width: 35%;
margin: 2.5em auto;
background: #fff;
padding: 2.5em;
.contactFrm h4 {
font-size: 1em;
color: #252525;
margin-bottom: 0.5em;
font-weight: 300;
letter-spacing: 5px;
.contactFrm input[type="text"], .contactFrm input[type="email"] {
width: 70%;
outline: none;
font-size: 0.9em;
padding: .7em 1em;
border: 1px solid #000;
-webkit-appearance: none;
display: block;
margin-bottom: 1.2em;
.contactFrm textarea {
resize: none;
width: 93.5%;
font-size: 0.9em;
outline: none;
padding: .6em 1em;
border: 1px solid #000;
min-height: 10em;
-webkit-appearance: none;
.contactFrm input[type="submit"] {
outline: none;
color: #FFFFFF;
padding: 0.5em 0;
font-size: 1em;
margin: 1em 0 0 0;
-webkit-appearance: none;
background: #006faa;
transition: 0.5s all;
border: 2px solid #006faa;
-webkit-transition: 0.5s all;
transition: 0.5s all;
-moz-transition: 0.5s all;
width: 47%;
cursor: pointer;
.contactFrm input[type="submit"]:hover {
background: none;
color: #006faa;
p.succdiv{color: #008000;}
<div class="mainContent">
<h2>Kontak Form PHP / <small><a href=""></a></small></h2>
<div class="contactFrm">
<?php if(!empty($statusMsg)){ ?>
<p class="statusMsg <?php echo !empty($msgClass)?$msgClass:''; ?>"><?php echo $statusMsg; ?></p>
<?php } ?>
<form action="" method="post">
<input type="text" name="name" placeholder="Nama Anda" required="">
<h4>Email </h4>
<input type="email" name="email" placeholder="" required="">
<input type="text" name="subject" placeholder="Tulis subject" required="">
<textarea name="message" placeholder="Tulis pesan Anda disini" required=""> </textarea>
<input type="submit" name="submit" value="Submit">
<div class="clear"> </div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.