Gmail Tutorials
Gmail Tutorials
Page 1
Page 2
Gmail tutorial
Index.css..4
Home.css......................................................................................8
Connection.php...25
Function.php26
Registration script27
Login script...36
Show user profile name / photo script41
How to search emails script.44
How to compose email script48
How to view inbox email script53
How to view full email script.57
How to reply email script..67
How to download email file script.70
How to delete email script 77
How to draft email script...82
How to view draft email script..87
How to view outbox email script91
Follow more tutorials at www.23tutorials.com
Page 3
Index.css
This css is for styling the index.php page.
body{
margin-left:-0%;
margin-top:0%;
margin-right:-0%;
background-color:#dddddd;
}
#index_page_header{
position:fixed;
background-color:blue;
width:1280px;
height:80px;
top:-21px;
left:0px;
z-index: 2;
}
#registration_div{
background-color:;
width:304px;
height:420px;
position:absolute;
Page 4
top:95px;
font-weight:bold;
left:7px;
border:1px solid white;
border-radius:5px;
}
h1{
color:white;
}
h2{
position:absolute;
color:green;
font-size:17px;
left:40px;
top:-12px;
}
.reg{
position:relative;
left:3px;
border-radius:4px;
border:0px;
height:30px;
width:295px;
}
#submit_bitton{
position:relative;
Page 5
background-color:blue;
left:80px;
top:-35px;
border-radius:4px;
border:0px;
height:30px;
width:125px;
color:white;
}
#login_div{
background-color:;
position:absolute;
top:0px;
margin-left:327px;
width:200px;
border:0px solid white;
}
#login_email{
position:relative;
left:3px;
border-radius:0px;
border:0px;
height:25px;
width:298px;
}
#login_password{
Page 6
position:relative;
top:2px;
left:3px;
border-radius:0px;
border:0px;
height:25px;
width:298px;
}
#login_button{
position:absolute;
background-color:blue;
left:0px;
top:60px;
border-radius:0px;
border:1px solid grey;
height:23px;
width:55px;
color:white;
}
Page 7
Home.css
This home.css page is used to style the home.php page.
/* div containing profile picture */
.profile-photo{
position:absolute;
top:84px;
left:10px;
width:150px;
height:140px;
background-color:white;
border:1px solid #cce;
border-radius:6px;
}
/* profile name */
#profile_name{
position:relative;
top:-27px;
left:2px;
font-size:17px;
}
/* profile picture */
.profile_pic{
Page 8
position:absolute;
top:4px;
left:4px;
width:142px;
height:132px;
border-radius:6px;
}
Page 9
width: 180px;
text-align: center;
top:-2px;
border:1px solid black;
}
.fileUpload input.upload {
position: absolute;
top: 0;
right: 0;
margin: 0;
padding: 0;
font-size: 20px;
cursor: pointer;
opacity: 0;
filter: alpha(opacity=0);
height: 100%;
text-align: center;
}
.custom-span{ font-family: Arial; font-weight: bold;font-size: 100px; color: #FE57A1}
#uploadFile{border: none;margin-left: 10px; width: 200px;}
.custom-para{font-family: arial;font-weight: bold;font-size: 24px; color:#585858;}
#photo_text{
position:absolute;
width:350px;
height:36px;
left:147px;
Page 10
top:75px;
font-size:16px;
}
#photo_comment{
position:absolute;
left:150px;
top:30px;
font-size:20px;
}
#submit_photo{
position:absolute;
width:340px;
height:50px;
left:155px;
top:120px;
font-size:24px;
background-color:white;
border:0px solid black;
color:white;
}
.preview
{
position:absolute;
left:185px;
top:-52px;
border:0px solid black;
Page 11
#preview
{
position:absolute;
top:60px;
color:#cc0000;
font-size:12px
}
/* end of div for syling uploading forms like youtube */
.left-bar-links{
position:absolute;
width:160px;
height:120px;
left:10px;
top:240px;
font-size:17px;
background-color:#dddddd;
border:0px solid #ccc;
color:black;
}
.left-bar-links a {
text-decoration:none;
color:black;
}
Page 12
#noticeboard{
width:780px;
height:35px;
border:0px solid #cce;
background-color:;
position:absolute;
left:20px;
top:0px;
}
.content{
width:380px;
margin:0 auto;
position:absolute;
top:37px;
left:190px;
}
#searchid
{
position:absolute;
width:480px;
border:1px solid #cce;
padding:10px;
font-size:14px;
Page 13
border-radius:5px;
}
#result
{
position:absolute;
width:480px;
padding:10px;
display:none;
top:37px;
border-top:1px;
overflow:hidden;
border:1px #CCC solid;
background-color:#cce;
}
.compose-message-header{
position:absolute;
background-color:white;
-webkit-box-shadow: 0 3px 8px rgba(0, 0, 0, .25);
overflow: visible;
top:84px;
margin-left:210px;
width:500px;
border-radius:3px;
border:;
padding:1px;
height:30px;
Page 14
.compose-message-header-text{
position:relative;
left:10px;
top:-21px;
font-size:15px;
}
.receiver_email_form{
position:absolute;
background-color:white;
-webkit-box-shadow: 0 3px 8px rgba(0, 0, 0, .25);
overflow: visible;
top:126px;
margin-left:210px;
width:500px;
border-radius:3px;
border:1px solid #cce;
padding:1px;
height:33px;
line-height: 1.42857143;
-webkit-box-shadow: inset 0 1px 1px rgba(0,0,0,.075), 0 0 8px rgba(102, 175, 233, .6);
box-shadow: inset 0 1px 1px rgba(0,0,0,.075), 0 0 8px rgba(102, 175, 233, .6);
}
Page 15
.message_subject{
position:absolute;
background-color:white;
-webkit-box-shadow: 0 3px 8px rgba(0, 0, 0, .25);
overflow: visible;
top:172px;
margin-left:210px;
width:500px;
border-radius:3px;
border:1px solid #cce;
padding:1px;
height:33px;
line-height: 1.42857143;
-webkit-box-shadow: inset 0 1px 1px rgba(0,0,0,.075), 0 0 8px rgba(102, 175, 233, .6);
box-shadow: inset 0 1px 1px rgba(0,0,0,.075), 0 0 8px rgba(102, 175, 233, .6);
}
.message-div{
position:absolute;
background-color:white;
-webkit-box-shadow: 0 3px 8px rgba(0, 0, 0, .25);
overflow: visible;
top:219px;
margin-left:210px;
width:500px;
border-radius:3px;
Page 16
}
.upload_file{
position:absolute;
top:459px;
margin-left:210px;
background-color:white;
}
Page 17
.submit-button{
background-color:blue;
position:absolute;
top:490px;
margin-left:210px;
width:90px;
height:40px;
border:1px solid #ccc;
border-radius:5px;
color:white;
}
.inbox-message-div{
background-color:white;
border: 2px solid #ccc;
-webkit-box-shadow: 0 3px 8px rgba(0, 0, 0, .25);
overflow: visible;
position: relative;
top:123px;
margin-left:210px;
width:500px;
border-radius:3px;
font-size:13px;
-webkit-box-shadow: inset 0 1px 1px rgba(0,0,0,.075), 0 0 8px rgba(102, 175, 233, .6);
box-shadow: inset 0 1px 1px rgba(0,0,0,.075), 0 0 8px rgba(102, 175, 233, .6);
}
Page 18
.sender-email{
position:absolute;
top:-13px;
margin-left:10px;
font-size:14px;
text-decoration:underline;
}
.draft_email{
position:absolute;
top:3px;
margin-left:423px;
font-size:13px;
text-decoration:none;
}
.delete_email{
position:absolute;
top:42px;
margin-left:423px;
font-size:13px;
text-decoration:none;
}
.email-subject{
position:absolute;
top:9px;
margin-left:20px;
Page 19
font-size:14px;
text-decoration:none;
}
.email-file{
position:absolute;
top:21px;
margin-left:423px;
font-size:14px;
text-decoration:none;
}
.download-file{
position:absolute;
top:11px;
margin-left:385px;
font-size:12px;
text-decoration:none;
}
.email_date{
position:absolute;
top:-10px;
margin-left:425px;
font-size:11px;
text-decoration:underline;
}
.email_text{
border:0px solid #ccc;
Page 20
position:relative;
top:30px;
margin-left:29px;
color:grey;
border-radius:0px;
font-size:16px;
padding-bottom:23px;
}
.inbox-message-div a{
text-decoration:none;
color:grey;
}
.reply-message-div{
position:absolute;
background-color:white;
-webkit-box-shadow: 0 3px 8px rgba(0, 0, 0, .25);
overflow: visible;
top:235px;
margin-left:210px;
width:500px;
border-radius:3px;
border:1px solid #cce;
padding:1px;
height:153px;
line-height: 1.42857143;
Page 21
-webkit-box-shadow: inset 0 1px 1px rgba(0,0,0,.075), 0 0 8px rgba(102, 175, 233, .6);
box-shadow: inset 0 1px 1px rgba(0,0,0,.075), 0 0 8px rgba(102, 175, 233, .6);
}
.reply-message-body-container{
position:absolute;
background-color:white;
color:black;
width:498px;
border-radius:0px;
border:0px solid #cce;
padding:0px;
height:151px;
top:2px;
left:2px;
padding:1px;
font-family: "lucida grande",tahoma,verdana,arial,sans-serif;
}
.reply-submit-button{
background-color:blue;
position:absolute;
top:400px;
margin-left:210px;
width:90px;
height:40px;
border:1px solid #ccc;
border-radius:5px;
Page 22
color:white; }
.reply-email-text{
position:absolute;
top:206px;
margin-left:212px;
font-size:12px;
}
/* styling the edit info page */
.edit-info-div{
position:absolute;
background-color:white;
-webkit-box-shadow: 0 3px 8px rgba(0, 0, 0, .25);
overflow: visible;
top:124px;
margin-left:210px;
width:500px;
border-radius:3px;
border:;
padding:1px;
height:270px;
}
.edit_account_form
{
width:300px;
height:30px;
Page 23
#submit_button
{
position:relative;
width:120px;
height:50px;
left:104px;
top:-9px;
border-radius:5px;
border:1px solid #cce;
background-color:#f4f8fb;
color:blue;
font-size:29px;
}
#position_edit_form{
position:relative;
left:24px;
top:39px;
Page 24
connection.php
This php file connects this tutorial to the database.
<?php
$mysql_hostname= "localhost";
$mysql_user = "root";
$mysql_password = "";
$mysql_database = "learn"; //database name, you can change to yours
$prefix = "";
$bd = mysql_connect($mysql_hostname, $mysql_user,
$mysql_password) or die("Could not connect database");
mysql_select_db($mysql_database, $bd) or die("Could not select
database");
?>
Page 25
function.php
This php file stores the login user session.
<?php
include("connection.php");
if(isset($_SESSION["SESS_MEMBER_ID" ] ) ) {
$result = mysql_query("SELECT member_id FROM `member`
WHERE `member_id`='".
$_SESSION["SESS_MEMBER_ID"]." ' LIMIT 1");
if(mysql_num_rows($result)) {
$row = mysql_fetch_array($result);
$_SESSION["logged"] = $row["member_id"];
}
}
?>
Registration script
Follow more tutorials at www.23tutorials.com
Page 26
This is the registration form where user can sign up to have an email
account.
Below is the database where all the user information will be kept.
CREATE TABLE IF NOT EXISTS `member` (
`member_id`int(11) NOT NULL AUTO_INCREMENT,
`firstname` varchar(30) NOT NULL,
`secondname` varchar(30) NOT NULL,
`email` varchar(30) NOT NULL,
`sex` varchar(100) NOT NULL,
`password` varchar(30) NOT NULL,
`profile_picture` varchar(30) NOT NULL,
`day` varchar(100) NOT NULL,
`month` varchar(30) NOT NULL,
`year` varchar(100) NOT NULL,
PRIMARY KEY (`member_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=6 ;
Next create a page called index.php which will contain the registration
page.
Page 27
<!DOCTYPE >
<HTML >
<head>
<!-- Below is the external css for styling the index page-->
<link rel="stylesheet" type="text/css" href="css/index.css"/>
<!-- Below is the external jquery file. please you can use yours if you have it or you can
download it from the email framework in the home page. -->
<script type="text/javascript" src="script/jquery-1.8.0.min.js"></script>
<script type="text/javascript">
//private message search engine modal box
$(function(){
$('#input_text').keyup(function(){
var a = $('#input_text').val();
//the check.php file is below after the index.php file.
$.post('check.php', {"email": a },
function(data){
$('#preview').html(data);
});
});
});
</script>
</head>
<body>
<html>
Follow more tutorials at www.23tutorials.com
Page 28
<nav id="index_page_header">
</nav>
<div id="registration_div">
<h2>Register to upload your videos</h1> <br>
<form name="myForm" action="exec.php" onsubmit="return(validate());" method="post">
<br>
<input type="text" name="firstname" placeholder="FIRST NAME" class="reg"><br>
<br>
<input type="text" name="secondname" placeholder="SECOND NAME" class="reg"><br>
<br>
<input type="text" name="email" placeholder="USERNAMES" class="reg"
id="input_text"><br>
<br>
<td><input type="password" name="password" placeholder="PASSWORD" class="reg"><br>
<br>
<input type="password" name="retype" placeholder="RE-TYPE PASSWOED"
class="reg"><br><br>
Male<input type="radio" name="sex" value="male">
Female<input type="radio" name="sex" value="female"><br><br>
<font color="green">Born on</font><br>
Day<select name="day">
<option>1</option>
<option>2</option>
<option>3</option>
</select>
Month<select name="month">
<option>January</option>
<option>February</option>
<option>March</option>
<option>April</option>
<option>May</option>
<option>June</option>
Follow more tutorials at www.23tutorials.com
Page 29
<option>July</option>
<option>August</option>
<option>September</option>
<option>October</option>
<option>November</option
<option>December</option>
</select>
Year<select name="year" >
<option>1924</option>
<option>1923</option>
<option>1922</option>
</select><br/><br>
<br>
<input type="hidden" name="profile_picture" value="p.jpg">
<td><input name="submit" type="submit" value="Submit" id="submit_bitton"/></td>
</form>
</div>
<div id="preview" style="width:340px; font-size:14px; border:0px solid black;
position:absolute; top:230px; left:321px;">
</div>
</body>
</html>
Next is the php file call "check.php" php file used to live search if email
exists already? The Jquery script for the email live search is above is above.
<?php
include('connection.php');
$var= $_POST['email'];
$email = '@gmail.com';
Page 30
$femail = "[email protected]";
$smail= "$femail";
if(strpos($var, '@'))
{
echo"<p style='color:;'> Please don't add <span style='color:green;'> @</span> in your
email. It is not accepted.<br>
Input only the names which will be used for your email.</p>";
}else
{
echo"<p style='color:;'> Your prospect email is <span
style='color:green;'>$smail</span></p>";
$query = mysql_query("SELECT * FROM member WHERE email='$femail'");
if(mysql_num_rows($query) > 0)
{
echo"<p style='color:red;'> This <span style='color:green;'>$smail</span> email already
exist. </p>";
}else
{
echo"<p style='color:red;'> This <span style='color:green;'>$smail</span> email has not
be taken.</p>";
}
}
?>
Next is the php file call "exec.php" which insert the registered user
information into the database.
Page 31
<?php
//below variables are being assign to names of input fields in the registration form.
session_start();
include('connection.php');
$firstname=$_POST['firstname'];
$secondname=$_POST['secondname'];
$email=$_POST['email'];
$sex=$_POST['sex'];
$password=$_POST['password'];
$photo=$_POST['profile_picture'];
$day=$_POST['day'];
$month=$_POST['month'];
$year=$_POST['year'];
$fmail = "[email protected]";
$smail= "$fmail";
if(strpos($email, '@'))
{
//if the user email contains @ it will rejects the email. The user should enter only
usernames which will be converted into an email
echo"<p style='color:;'> Please don't add <span style='color:green;'> @</span> in your
email. It is not accepted.<br>
Input only the names which will be used for your email.</p>";
}else
{
echo"<p style='color:;'> Your prospect email is <span
Follow more tutorials at www.23tutorials.com
Page 32
style='color:green;'>[email protected]</span></p>";
$query = mysql_query("SELECT * FROM member WHERE email='$smail'");
if(mysql_num_rows($query) > 0)
{
echo"<p style='color:red;'> This <span style='color:green;'>[email protected]</span>
email already exist. </p>";
}else
{
//Below insert the registered user information into the database when it has passed the
above validation.
mysql_query("INSERT INTO member(firstname, secondname, email, sex, password,
profile_picture, day, month, year)
VALUES( '$firstname', '$secondname', '$smail', '$sex', '$password', '$photo', '$day',
'$month', '$year')");
header("location:home.php");
mysql_close($con);
//Create query
$qry="SELECT * FROM member WHERE email='$smail' AND password='$password'";
$result=mysql_query($qry);
//Check whether the query was successful or not.
if($result)
{
if(mysql_num_rows($result) > 0)
{
//register Successful
Page 33
session_regenerate_id();
$member = mysql_fetch_assoc($result);
$_SESSION['SESS_MEMBER_ID'] = $member['member_id'];
$_SESSION['SESS_FIRST_NAME'] = $member['email'];
$_SESSION['SESS_LAST_NAME'] = $member['password'];
session_write_close();
exit();
}
}
}
}
?>
Next is the home.php page where when the user has sign up or login,
it will take him into the home.php page where he can send and receive
emails, search for emails and edit account. please take note that the
home.php page will be used throughout the upcoming steps in this
tutorial.
//Below is the home page that the newly register user will be taken after registration is
complete. // include the below php script at the top of the <!DOCTYPE> in the home.php
page
<?php
session_start();
include("connection.php"); //connect to the database
include("function.php"); //This is the include file above indicated above
?>
Follow more tutorials at www.23tutorials.com
Page 34
<!DOCTYPE >
<HTML >
<head >
</head >
<body >
welcome to 23tutorials.com social network learning script for newbie programmers.
Hopes you enjoyed this tutorial.
Follow all the above email tutorials and you will benefit and learn new trick to create your
own social network. Thanks
</body >
</html >
Login script
This is the login form where user can login. Below is the database where
all the user information is kept which will be used for the login process.
Follow more tutorials at www.23tutorials.com
Page 35
Next create a page called index.php which will contain the login
form in the page.
Below is the index.php having the login form
<!DOCTYPE >
<HTML >
<head>
Page 36
<!-- Below is the external css for styling the index page-->
<link rel="stylesheet" type="text/css" href="css/index.css"/>
</head>
<body>
<html>
<nav id="index_page_header">
<div id="login_div">
<form name="loginform" action= "loginscript.php" method="post">
<input type="text" name= "login_email" placeholder="email" id="login_email"> <br>
<input type="text" name="login_password" placeholder="password" id="login_password">
<input type="submit" name="login_button" value="login" id="login_button">
<?php
if( isset($_SESSION['ERRMSG_ARR']) && is_array($_SESSION['ERRMSG_ARR']) &&
count($_SESSION['ERRMSG_ARR']) >0 ) {
echo'<ul class="err">';
foreach ($_SESSION['ERRMSG_ARR'] as $msg) {
echo'<li>',$msg,'</li>';
}
echo'</ul>';
unset($_SESSION['ERRMSG_ARR']);
}
?>
</form>
</div>
Follow more tutorials at www.23tutorials.com
Page 37
</nav>
</body>
</html>
Next is the php file call "loginscript.php" which will login the registered
user into the database which he will be taken to the home.php page.
<?php
//Start session
session_start();
//Include database connection details
require_once('connection.php');
//Array to store validation errors
$errmsg_arr = array();
//Validation error flag
$errflag = false;
//Function to sanitize values received from the form. Prevents SQL injection
function clean($str) {
$str = @trim($str);
if (get_magic_quotes_gpc()) {
$str = stripslashes($str);
}
return mysql_real_escape_string($str);
}
//Sanitize the POST values
$email = clean($_POST['login_email']);
$password = clean($_POST['login_password']);
//Input Validations
if ($email == '') {
$errmsg_arr[] = 'email missing';
$errflag = true;
} if ($password == '') {
$errmsg_arr[]= 'Password missing';
$errflag = true;
}
//If there are input validations, redirect back to the login form
if ($errflag) {
$_SESSION['ERRMSG_ARR'] = $errmsg_arr;
session_write_close();
header("location: index.php");
Follow more tutorials at www.23tutorials.com
Page 38
exit();
}
//Create query
$qry="SELECT * FROM member WHERE email='$email' AND password='$password' ";
$result=mysql_query($qry);
//Check whether the query was successful or not
if ($result) {
if (mysql_num_rows($result) > 0) {
//Login Successful
session_regenerate_id();
$member = mysql_fetch_assoc($result);
$_SESSION['SESS_MEMBER_ID'] = $member['member_id'];
$_SESSION['SESS_FIRST_NAME'] = $member['email'];
$_SESSION['SESS_LAST_NAME'] = $member['password'];
session_write_close();
header("location: home.php");
exit();
} else {
//Login failed
$errmsg_arr[] = 'email and password not found';
$errflag = true;
if ($errflag) {
$_SESSION['ERRMSG_ARR'] = $errmsg_arr;
session_write_close();
header("location: index.php");
exit();
}
}
} else {
die("Query failed");
}
?>
Next is the home.php page where when the user has sign up or login, it
will take him into the home.php page where he can send and receive
emails, search for emails and edit account. plesae take note that the
home.php page will be used throughout the upcoming steps in this
tutorial.
Follow more tutorials at www.23tutorials.com
Page 39
//Below is the home page that the login user will be taken after login is
completed. // include the below php script at the top of the <!
DOCTYPE> in the home.php page
<?php
session_start();
include("connection.php");//connect to the database
include("function.php");//This is the include file above indicated above
?>
<!DOCTYPE >
<HTML >
<head >
</head >
<body >
welcome to 23tutorials.com social network learnig script for newbies programmers.
Hopes you enjoyed this tutorial.
Follow all the above video social network tutorials and you will benefit and learn new trick
to create your own social network. Thanks
</body >
</html >
Page 40
This is the view profile names and photo script where the login user can
view his profile names and photo.
Below is the database for the storing the uploaded profile names and
photo.
CREATE TABLE IF NOT EXISTS `member` (
`member_id`int(11) NOT NULL AUTO_INCREMENT,
`firstname` varchar(30) NOT NULL,
`secondname` varchar(30) NOT NULL,
`email` varchar(30) NOT NULL,
`sex` varchar(100) NOT NULL,
`password` varchar(30) NOT NULL,
`profile_picture` varchar(30) NOT NULL,
`day` varchar(100) NOT NULL,
`month` varchar(30) NOT NULL,
`year` varchar(100) NOT NULL,
PRIMARY KEY (`member_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=6 ;
Next create a page called home.php that shows the profile names and
picture.
<?php
session_start();
Follow more tutorials at www.23tutorials.com
Page 41
Page 42
{
echo "<tr>";
echo "<img src='uploads/".$row['profile_picture']."' class='profile_pic'>";
echo "<td>" . $row['firstname'] .' '. $row['secondname'] . "</td >";
echo "</tr>";
}
echo "</table>";
?>
</div>
</body>
</html>
Page 43
This is the search emails script where the login user can search for emails he wan t to mails to.
Below is the database for the storing the uploaded profile names and photo.
CREATE TABLE IF NOT EXISTS `member` (
`member_id`int(11) NOT NULL AUTO_INCREMENT,
`firstname` varchar(30) NOT NULL,
`secondname` varchar(30) NOT NULL,
`email` varchar(30) NOT NULL,
`sex` varchar(100) NOT NULL,
`password` varchar(30) NOT NULL,
`profile_picture` varchar(30) NOT NULL,
`day` varchar(100) NOT NULL,
`month` varchar(30) NOT NULL,
`year` varchar(100) NOT NULL,
PRIMARY KEY (`member_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=6 ;
Next create a page called home.php that contains the search form that
will show the result of the search emails.
Page 44
<?php
session_start();
include ("connection.php"); // connect to the database
include("function.php");
?>
<!DOCTYPE >
<HTML >
<head>
<!-- Below is the external css for styling the index page-->
<link rel="stylesheet" type="text/css" href="css/home.css"/>
<link rel="stylesheet" type="text/css" href="css/index.css"/>
<link href="css/font-awesome.css" rel="stylesheet">
<!-- Below is the external jquery file. please you can use yours if you have it. -->
<script type="text/javascript" src="script/jquery-1.8.0.min.js"></script>
<script type="text/javascript" src="script/jquery.form.js"></script>
<script type="text/javascript">
$(function(){
$(".search").keyup(function()
{ var searchid = $(this).val();
var dataString = 'search='+ searchid;
if(searchid!='')
{
type: "POST",
url:"search.php",
data: dataString,
cache: false,
success: function(html)
{
$("#result").html(html).show();
}
});
}return false;
});
jQuery("#result").live("click",function(e){
var $clicked = $(e.target);
var $name = $clicked.find('.name').html();
Follow more tutorials at www.23tutorials.com
Page 45
Page 46
Create a file called search.php which will search the emails from the
database.
<?php
include('connection.php');
if($_POST)
{
$query = mysql_real_escape_string($_POST['search']);
$sql = mysql_query("SELECT * FROM `member` WHERE `email` LIKE '%$query%' LIMIT 0,
5 ") or die (mysql_error());
$num_of_row = mysql_num_rows($sql);
if ($num_of_row > 0 ) {
while($row = mysql_fetch_array($sql))
{
$id = $row['member_id'];
echo "<p style='color:blue; text-decoration:none;'> ". $row['email']."</p>";
echo "<hr width='600px' style='color:white;'>";
}
}
else
{
echo "<font color='red' size='4' >No email found!</font>";
}
}
?>
Page 47
Next create a page called home.php that contains form for sending
emails.
Page 48
<?php
session_start();
include ("connection.php"); // connect to the database
include("function.php");
?>
<!DOCTYPE >
<HTML >
<head>
<!-- Below is the external css for styling the index page-->
<link rel="stylesheet" type="text/css" href="css/home.css"/>
<link href="css/font-awesome.css" rel="stylesheet">
</head>
<body>
<nav id="index_page_header">
</nav>
<!-- Below is the form for sending email and attatch file. -->
<form action="send-mail.php" enctype="multipart/form-data" method="POST"
name="message_form" onsubmit="return(validate());">
<input name="MAX_FILE_SIZE" type="hidden" value="1000000">
<input type="text" name="receiver_email" placeholder="Send message to"
class="receiver_email_form">
<input type="text" name="topic" placeholder="Subject" class="message_subject">
<div class="message-div">
<textarea class="message-body-container" name="email_body" placeholder="Type your
Follow more tutorials at www.23tutorials.com
Page 49
Create a file called send-mail.php which will insert the email the login
user sends into the database.
<?php
session_start();
include("connection.php");
include("function.php");
$mail = $_POST["email_body"];
$receiver = $_POST['receiver_email'];
$subject = $_POST["topic"];
$member_id = $_SESSION["logged"];
$sender_email = $_email["logged"];
$send_file = $_FILES['file']['name'];
if( $send_file == "" )
{
$query = mysql_query("INSERT INTO
emails(sender_id,date,sender_email,receiver_email,subject,file_name,email_body)
VALUES('$member_id',NOW(),'$sender_email','$receiver','$subject','$send_file','$mail') ");
echo "<script type=\"text/javascript\">
alert(\"You sent this message\");
window.location='home.php';
Follow more tutorials at www.23tutorials.com
Page 50
</script>";
}else{
$path = "files/"; //the files is the name of the folder to store the file attach or send to an email.
$valid_formats = array("docx", "pdf", "gif", "bmp" , "JPG" , "PNG" , "GIF","jpg", "png","sql");
$send_file = $_FILES['file']['name'];
list($txt, $ext) = explode(".", $send_file);
if(in_array($ext,$valid_formats))
{
$tmp = $_FILES['file']['tmp_name'];
if(move_uploaded_file($tmp, $path.$send_file))
{
$query=mysql_query("INSERT INTO
emails(sender_id,date,sender_email,receiver_email,subject,file_name,email_body)
VALUES('$member_id',NOW(),'$sender_email','$receiver','$subject','$send_file','$mail') ") or
die(mysql_error());
} else
{
echo "<script type=\"text/javascript\">
alert(\"photo uploaded failed\");
window.location='home.php';
</script>";
}
{
echo "<script type=\"text/javascript\">
alert(\"You sent this message\");
window.location='home.php';
</script>";
}
} else{
echo "<script type=\"text/javascript\">
alert(\"This $send_file file is invalid\");
Follow more tutorials at www.23tutorials.com
Page 51
window.location='home.php';
</script>";
}
}
?>
Page 52
This is the view profile names and photo script where the login
user can view his profile names and photo.
Below is the database for the storing the inbox emails
(messages).
CREATE TABLE IF NOT EXISTS `emails` (
`email_id` int(11) NOT NULL AUTO_INCREMENT,
`sender_id` int(11) NOT NULL,
`receiver_id` int(11) NOT NULL,
`sender_email` varchar(5000) NOT NULL,
`receiver_email` varchar(5000) NOT NULL,
`subject` varchar(5000) NOT NULL,
`file_name` varchar(5000) NOT NULL,
`email_body` varchar(5000) NOT NULL,
`date` date NOT NULL,
PRIMARY KEY (`email_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=9;
Next create a page called home.php that shows the inbox message (emails received by the login
users).
<?php
session_start();
include ("connection.php"); // connect to the database
Follow more tutorials at www.23tutorials.com
Page 53
include("function.php");
?>
<!DOCTYPE >
<HTML >
<head>
<!-- Below is the external css for styling the index page-->
<link rel="stylesheet" type="text/css" href="css/home.css"/>
<link href="css/font-awesome.css" rel="stylesheet">
</head>
<body>
<nav id="index_page_header">
</nav>
<!-- Below is the php script which selects the login user inbox emails (The user can see all the
messages it receives). These inbox emails are not completed the user has to clicked the email to
view the full emails.-->
<?php
$user_email = $_email["logged"];
$email = mysql_query("SELECT * FROM `emails` WHERE `receiver_email`='$user_email'
ORDER BY date DESC");
$num_rows =mysql_numrows($email);
if ($num_rows != 0 ) {
while($row = mysql_fetch_array($email))
{
$email_file = $row["file_name"];
$email_text = $row["email_body"];
$mail = substr($email_text , 0, 15);
Follow more tutorials at www.23tutorials.com
Page 54
if($email_file)
{
echo"<div class='inbox-message-div'>";
echo'<p class="sender-email"><span style="color:red;"> From:</span> '.
$row["sender_email"].'</p>';
echo'<p class="email-subject"><span style="color:green;"> Subject:</span> '.
$row["subject"].'</p> ';
echo'<p class="draft_email" ><a href="insert_draft.php?email_id='.$row["email_id"].'"><i
class="icon icon-save"></i> draft email</a></p>';
echo'<p class="email-file"> <span style="color:green;"><i class="icon icon-file"></i> sent a
file</span> </p> ';
echo'<p class="email_date"> '.$row["date"].'</p> ';
echo"<p class='email_text'> <a href='view_email.php?email_id=".$row['email_id']."'>
$mail......</p></a>";
echo"</div>";
} else
{
echo"<div class='inbox-message-div'>";
echo'<p class="sender-email"><span style="color:red;"> From:</span> '.
$row["sender_email"].'</p>';
echo'<p class="draft_email" ><a href="insert_draft.php?email_id='.$row["email_id"].'"><i
class="icon icon-save"></i> draft email</a></p>';
echo'<p class="email-subject"><span style="color:green;"> Subject:</span> '.
$row["subject"].'</p> ';
echo'<p class="email_date"> '.$row["date"].'</p> ';
echo"<p class='email_text'> <a href='view_email.php?email_id=".$row['email_id']."'>
$mail......</p></a>";
echo'<p class="delete_email" ><a href="delete-mail.php?email_id='.$row["email_id"].'"><i
Follow more tutorials at www.23tutorials.com
Page 55
Page 56
This is the view full email script where the login user can view the
complete email content when he clicks any email on the inbox.
Below is the database for the storing the inbox emails (messages).
CREATE TABLE IF NOT EXISTS `emails` (
`email_id` int(11) NOT NULL AUTO_INCREMENT,
`sender_id` int(11) NOT NULL,
`receiver_id` int(11) NOT NULL,
`sender_email` varchar(5000) NOT NULL,
`receiver_email` varchar(5000) NOT NULL,
`subject` varchar(5000) NOT NULL,
`file_name` varchar(5000) NOT NULL,
`email_body` varchar(5000) NOT NULL,
`date` date NOT NULL,
PRIMARY KEY (`email_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=9;
Next create a page called home.php that shows the inbox message
(emails received by the login users).
Page 57
<?php
session_start();
include ("connection.php"); // connect to the database
include("function.php");
?>
<!DOCTYPE >
<HTML >
<head>
<!-- Below is the external css for styling the index page-->
<link rel="stylesheet" type="text/css" href="css/home.css"/>
<link href="css/font-awesome.css" rel="stylesheet">
</head>
<body>
<nav id="index_page_header">
</nav>
<!-- Below is the php script which selects the login user inbox emails (The user can see all the
messages it receives). -->
<?php
$user_email = $_email["logged"];
$email = mysql_query("SELECT * FROM `emails` WHERE `receiver_email`='$user_email'
ORDER BY date DESC");
$num_rows =mysql_numrows($email);
if ($num_rows != 0 ) {
while($row = mysql_fetch_array($email))
{
$email_file = $row["file_name"];
Follow more tutorials at www.23tutorials.com
Page 58
$email_text = $row["email_body"];
$mail = substr($email_text , 0, 15);
if($email_file)
{
echo"<div class='inbox-message-div'>";
<!-- Below is the link that contains incomplete emails that end with when click it will take the
user to the view_email.php page where he wil see the full email.-->
echo"<p class='email_text'> <a href='view_email.php?email_id=".$row['email_id']."'>
$mail......</p></a>";
echo"</div>";
} else
{
echo"<div class='inbox-message-div'>";
<!-- Below is the link that contains incomplete emails when click it will take the user to the
view_email.php page where he will see the full email.-->
echo"<p class='email_text'> <a href='view_email.php?email_id=".$row['email_id']."'>
$mail......</p></a>";
echo"</div>";
}
}
} else {
echo"<div class='inbox-message-div'>";
echo"<p class='sender-email'> No message received yet.</p>";
echo"</div>";
}
?>
</body>
</html>
Page 59
<?php
session_start();
include ("connection.php"); // connect to the database
include("function.php");
//Below is the id (number) of the email that was clicked from the inbox page.
$email_id = $_GET["email_id"];
?>
<!DOCTYPE >
<HTML >
<head>
<link rel="stylesheet" type="text/css" href="css/home.css"/>
<link href="css/font-awesome.css" rel="stylesheet">
</head>
<body>
<nav id="index_page_header">
</nav>
Follow more tutorials at www.23tutorials.com
Page 60
<!-- Below is the php script which selects the completed email messages that was clicked from
the inbox.(The user can see all the messages it receives). -->
<?php
$email = mysql_query("SELECT * FROM `emails` WHERE `email_id`='$email_id' ");
while($row = mysql_fetch_array($email))
{
$email_file = $row["file_name"];
if($email_file)
{
echo"<div class='inbox-message-div'>";
echo'<p class="sender-email"><span style="color:red;"> From:</span> '.
$row["sender_email"].'</p>';
echo'<p class="email-subject"><span style="color:green;"> Subject:</span> '.
$row["subject"].'</p> ';
echo'<p class="email_date"> '.$row["date"].'</p> ';
echo'<p class="email_text" ><a href="view_email.php?email_id='.$row["email_id"].'">
'.$row["email_body"].'
</p></a>';
echo"</div>";
} else
{
echo"<div class='inbox-message-div'>";
echo'<p class="sender-email"><span style="color:red;"> From:</span> '.
$row["sender_email"].'</p>';
Follow more tutorials at www.23tutorials.com
Page 61
Page 62
Page 63