login system in php email code example
Example 1: how to make a working login system using code
<!DOCTYPE html>
<html>
<head>
<title>Login</title>
<script>
firebase.initializeApp(firebaseConfig);
const auth = firebase.auth();
function signUp(){
var email = document.getElementById("email");
var password = document.getElementById("password");
const promise = auth.createUserWithEmailAndPassword(email.value, password.value);
promise.catch(e => alert(e.message));
alert("Signed Up");
}
function signIn(){
var email = document.getElementById("email");
var password = document.getElementById("password");
const promise = auth.signInWithEmailAndPassword(email.value, password.value);
promise.catch(e => alert(e.message));
}
function signOut(){
auth.signOut();
alert("Signed Out");
}
auth.onAuthStateChanged(function(user){
if(user){
var email = user.email;
alert("Signed in as " + email);
}else{
alert("No Active User");
}
});g
</script>
<style type="text/css">
body{
background-color: #55d6aa;
}
h1{
background-color: #ff4d4d;
margin: 10px auto;
text-align: center;
color: white;
}
#formContainer{
background-color: white;
box-shadow: 0 12px 16px 0 rgba(0,0,0,0.24), 0 17px 50px 0 rgba(0,0,0,0.19);
width: 25%;
height: 45;
margin: 10px auto;
}
#header{
width: 100%;
height: 10px;
background: black;
}
#email{
width: 70%;
height: 40px;
display:block;
margin: 25px auto;
border: none;
outline: none;
border-bottom: 2px solid black;
}
#password{
width: 70%;
height: 40px;
display: block;
margin: 10px auto;
border: none;
outline: none;
border-bottom: 2px solid black;
}
#signUp{
background-color: #ff4d4d;
color: white;
border: none;
font-weight: bold;
padding: 15px 32px;
border-radius: 10px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 13px;
margin-top: 20px;
margin-left: 50px;
}
#signIn{
background-color: #32ff7e;
color: white;
font-weight: bold;
border: none;
padding: 15px 35px;
border-radius: 10px;
text-align: center;
text-decoration: none;
font-size: 13px
}
#signOut{
background-color: #FFA500;
color: white;
border: none;
padding: 12px 32px;
border-radius: 10px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 13px;
margin-top: 9px;
margin-left: 74px;
font-weight: bold;
}
button: hover{
box-shadow: 0 12px 16px 0 rgba(0,0,0,0.24), 0 7px 50px 0 rgba(0,0,0,0,.19);
}
</style>
</head>
<body>
<h1>Login Here</h1>
<div id="formContainer">
<div id="header"> </div>
<input type="email" placeholder="Email" id="email">
<input type="password" placeholder="Password" id="password">
<button onclick="signUp()" id="signUp"> Sign Up </button>
<button onclick="signIn()" id="signIn"> Sign In </button>
<button onclick="signOut()" id="signOut"> Sign Out </button>
Continue</a>
</body>
</html>
Example 2: how to connect contact form to email in php
<html>
<head>
<title>PHP Contact Form</title>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<div class="form-container">
<form name="frmContact" id="" frmContact"" method="post"
action="" enctype="multipart/form-data"
onsubmit="return validateContactForm()">
<div class="input-row">
<label style="padding-top: 20px;">Name</label> <span
id="userName-info" class="info"></span><br /> <input
type="text" class="input-field" name="userName"
id="userName" />
</div>
<div class="input-row">
<label>Email</label> <span id="userEmail-info"
class="info"></span><br /> <input type="text"
class="input-field" name="userEmail" id="userEmail" />
</div>
<div class="input-row">
<label>Subject</label> <span id="subject-info"
class="info"></span><br /> <input type="text"
class="input-field" name="subject" id="subject" />
</div>
<div class="input-row">
<label>Message</label> <span id="userMessage-info"
class="info"></span><br />
<textarea name="content" id="content"
class="input-field" cols="60" rows="6"></textarea>
</div>
<div>
<input type="submit" name="send" class="btn-submit"
value="Send" />
<div id="statusMessage">
<?php
if (! empty($message)) {
?>
<p class='<?php echo $type; ?>Message'><?php echo $message; ?></p>
<?php
}
?>
</div>
</div>
</form>
</div>
<script src="https://code.jquery.com/jquery-2.1.1.min.js"
type="text/javascript"></script>
<script type="text/javascript">
function validateContactForm() {
var valid = true;
$(".info").html("");
$(".input-field").css('border', '#e0dfdf 1px solid');
var userName = $("#userName").val();
var userEmail = $("#userEmail").val();
var subject = $("#subject").val();
var content = $("#content").val();
if (userName == "") {
$("#userName-info").html("Required.");
$("#userName").css('border', '#e66262 1px solid');
valid = false;
}
if (userEmail == "") {
$("#userEmail-info").html("Required.");
$("#userEmail").css('border', '#e66262 1px solid');
valid = false;
}
if (!userEmail.match(/^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/))
{
$("#userEmail-info").html("Invalid Email Address.");
$("#userEmail").css('border', '#e66262 1px solid');
valid = false;
}
if (subject == "") {
$("#subject-info").html("Required.");
$("#subject").css('border', '#e66262 1px solid');
valid = false;
}
if (content == "") {
$("#userMessage-info").html("Required.");
$("#content").css('border', '#e66262 1px solid');
valid = false;
}
return valid;
}
</script>
</body>
</html>
Example 3: how to connect contact form to email in php
<?php
if(!empty($_POST["send"])) {
$name = $_POST["userName"];
$email = $_POST["userEmail"];
$subject = $_POST["subject"];
$content = $_POST["content"];
$toEmail = "admin@phppot_samples.com";
$mailHeaders = "From: " . $name . "<". $email .">\r\n";
if(mail($toEmail, $subject, $content, $mailHeaders)) {
$message = "Your contact information is received successfully.";
$type = "success";
}
}
require_once "contact-view.php";
?>