/    Sign up×
Community /Pin to ProfileBookmark

Email notification for guestbook

Hi guys,

I have this brilliant guestbook script which I have been using for ages, its pretty standard, I would like to be emailed with a simple notification just to say someone has made a comment, it doesnt matter about the content of the email, just need to no where in the script the mail() function should go, below is my entire page containing the guestbook.

Thank for any help!

[code=php]<?php
// include the database configuration and
// open connection to database
include ‘config.php’;
include ‘opendb.php’;

// how many guestbook entries to show per page
$rowsPerPage = 3;

// by default we show first page
$pageNum = 1;

if(isset($_GET[‘page’]))
{
$pageNum = $_GET[‘page’];
}

$offset = ($pageNum – 1) * $rowsPerPage;

// prepare the query string
$query = “SELECT id,
comments,
DATE_FORMAT(entry_date, ‘%d.%m.%Y’) “.
“FROM ryan “.
“ORDER BY id DESC “.
“LIMIT $offset, $rowsPerPage”;

// check if the form is submitted
if(isset($_POST[‘btnSign’]))
{
// get the input from $_POST variable
// trim all input to remove extra spaces
$message = trim($_POST[‘mtxMessage’]);

// escape the message ( if it’s not already escaped )
if(!get_magic_quotes_gpc())
{
$message = addslashes($message);
}

// prepare the query string
$query = “INSERT INTO ryan (comments, entry_date) ” .
“VALUES (‘$message’, current_date)”;

// execute the query to insert the input to database
// if query fail the script will terminate
mysql_query($query) or die(‘Error, query failed. ‘ . mysql_error());

// redirect to current page so if we click the refresh button
// the form won’t be resubmitted ( as that would make duplicate entries )
header(‘Location: ‘ . $_SERVER[‘REQUEST_URI’]);

// force to quite the script. if we don’t call exit the script may
// continue before the page is redirected
exit;
}
?>

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd”>
<html>
<head>
<link rel=”stylesheet” media=”screen” type=”text/css” href=”main.css” />
<link rel=”stylesheet” href=”css/lightbox.css” type=”text/css” media=”screen” />
<script type=”text/javascript” src=”screendetect.js”></script>
<script type=”text/javascript” src=”expandcollapse.js”></script>
<script type=”text/javascript” src=”js/prototype.js”></script>
<script type=”text/javascript” src=”js/scriptaculous.js?load=effects,builder”></script>
<script type=”text/javascript” src=”js/lightbox.js”></script>
<script type=”text/javascript” src=”validate.js”></script>
<noscript>
<link rel=”stylesheet” href=”noscript.css” type=”text/css” media=”screen” />
</noscript>
<script language=”JavaScript”>
/*
This function is called when
the ‘Sign Guestbook’ button is pressed
Output : true if all input are correct, false otherwise
*/
function checkForm()
{
// the variables below are assigned to each
// form input
var gmessage;
with(window.document.guestform)
{
gmessage = mtxMessage;
}

// alert the visitor if message is empty
else if(trim(gmessage.value) == ”)
{
alert(‘Please enter your message’);
gmessage.focus();
return false;
}
else
{
// when all input are correct
// return true so the form will submit
return true;
}
}

/*
Strip whitespace from the beginning and end of a string
Input : a string
Output : the trimmed string
*/
function trim(str)
{
return str.replace(/^s+|s+$/g,”);
}
</script>
</head>
<title>Elite Web-Creation</title>
<body>
<h1 id=”logo”>Elite Web-Creation</h1>
<br />
<br />
<noscript>
<?php require(“noscript2.php”);?>
</noscript>
<a href=”signout.php”>
<div id=”s01″ onmouseover=”return toggleMe(’01’)” onmouseout=”return toggleMe (’01’)”>Welcome</div></a>
<div id=”s02″ onmouseover=”return toggleMe(’02’)” onmouseout=”return toggleMe (’02’)”>Site Stats</div>
<div id=”s03″ onclick=”return toggleMe(’05’)” onmouseover=”return toggleMe(’03’)” onmouseout=”return toggleMe (’03’)”>Comment</div>
<div id=”s04″ onmouseover=”return toggleMe(’04’)” onmouseout=”return toggleMe (’04’)”>Replies</div>
<a href=”design1.png” rel=”lightbox[D]” title=”Design 1″>
<div id=”s05″ onmouseover=”return toggleMe(’06’)” onmouseout=”return toggleMe (’06’)”>Designs</div></a>
<div class=”scenter” id=”comment”></div>

<div id=”01″ class=”sright” style=”display:none”>
<b>You are signed in</b><hr>
Hi <?php echo $user; ?>,
<br />
Welcome to your personal report page. This page allows you to
monitor the progress of your website.
We are constantly working on your website so make sure you
keep checking its progress. Under Site Stats is a link to your website.
There is also other technical information you may want to know.
<br />
<br />Please click the welcome button to sign out.</div>

<div id=”02″ class=”sright” style=”display:none”>
<b>Site Stats</b><hr>
Your web site:<a class=”2″ href=”http://www.gradacad.co.uk”>www.gradacad.co.uk</a>
<br>Click the Site Stats button to open your domain.
<br>
<br>Currently your site has taken: 3 hours
<br>
<br>
Your domain: Has been registered and is configured.
<br>
<br></div>

<div id=”06″ class=”sright” style=”display:none”>
<b>Latest Designs</b><hr>
In response to your feedback I have created some variations of design 1
(design 1.1 &amp; 1.2) by incorporating the navigational bar from design 2.
I have also created a design that is a mix between design 1 and design 2.
<br /><br />I am aware you had the idea of using a grass background on your site so
I have added a varation of design 1.2 with a grass background to see if you like
it.
<br /><br />When commenting about the designs please use the below terms, (these are
also specified below the images)
<br />
<a href=”design 1.1.png”>Design 1.1</a><br />
<a href=”design 1.2.png” rel=”lightbox[D]” title=”Design 1.2″>Design 1.2</a><br />
<a href=”design 1.21.png” rel=”lightbox[D]” title=”Design 1.21″>Design 1.21</a><br />
<a href=”design 1.3.png” rel=”lightbox[D]” title=”Design 1.3″>Design 1.3</a></div>

<div id=”03″ class=”sright” style=”display:none”>
<b>Comment</b><hr>
If you would like to make a comment about the progession of your
website please click the comment button and fill out the form.
Click it again to hide the comment box.</div>

<div id=”04″ class=”sright” style=”display:none”>
<b>Replies from your designer</b><hr>
<?php

// =======================
// Show guestbook entries
// =======================

// how many guestbook entries to show per page
$rowsPerPage = 3;

// by default we show first page
$pageNum = 1;

// if $_GET[‘page’] defined, use the value as page number
if(isset($_GET[‘page’]))
{
$pageNum = $_GET[‘page’];
}

// counting the offset ( where to start fetching the entries )
$offset = ($pageNum – 1) * $rowsPerPage;

// prepare the query string
$query = “SELECT id, comments, DATE_FORMAT(entry_date, ‘%d.%m.%Y’) “.
“FROM ryan “.
“ORDER BY id DESC “. // using ORDER BY to show the most current entry first
“LIMIT $offset, $rowsPerPage”; // LIMIT is the core of paging

// execute the query
$result = mysql_query($query) or die(‘Error, query failed. ‘ . mysql_error());

// if the guestbook is empty show a message
if(mysql_num_rows($result) == 0)
{
?>
<p><br>
<br>You have not yet posted any comments</p>
<?php
}
else
{
// get all guestbook entries
while($row = mysql_fetch_array($result))
{
// list() is a convenient way of assign a list of variables
// from an array values
list($id, $message, $date) = $row;

// change all HTML special characters,
// to prevent some nasty code injection
$name = htmlspecialchars($name);
$message = htmlspecialchars($message);

// convert newline characters ( n OR r OR both ) to HTML break tag ( <br> )
$message = nl2br($message);
?>
Comment : <?=$message;?>
<br><?=$date;?>
<br><br>
<?php
}
?>

<?php
}
?>
</div>

<div id=”05″ class=”cbox” style=”display:none”>
<b>Make a comment</b><hr>
<form method=”post” name=”guestform” action=”at this page”>
<div width=”38%”>Comment:<br />
<textarea name=”mtxMessage” cols=”30″ rows=”5″ id=”mtxMessage”></textarea><br />
<input name=”btnSign” id=”buttonc” type=”submit” value=”Add Comment” onClick=”return checkForm();”>
</form></div></div>
</body>
</html>[/code]

to post a comment
PHP

0Be the first to comment 😎

×

Success!

Help @Dark_Light2 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.29,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...