You will need to double check all variable names and data being passed below, as this is just an example and probably not functional as-is.
Create yourself a function in a common file, for example (say this is "functions.php"):
<?php
function send_email ($to, $from, $subject, $body) {
/* you'll want to modify the above variables to match what you need in the function */
$to = "from@from.com";
$from = "receive <to@to.com>";
$name = $_POST['webmaster'];
$email = $_POST['email@email.com'];
$msg = $_POST['msg'];
//generic subject
$subject = "Student Adding";
//header
$header = 'From: '. $from . "\r\n" . 'Content-Type: text/html; charset=ISO-8859-1';
//email
$htmlEmail = "
<html>
<head>
</head>
<body>
<font face='Arial' style='font-size:14px;'></font><br>
<font face='Arial' style='font-size:14px;'>A Student was added by ".$_SESSION['username']."
</font><br><br>
</body>
</html>";
//php mail function
mail($to, $subject, $htmlEmail, $header);
}
?>
Then change the code that does the insert up a bit:
<?php
session_start();
require "dbc.php";
require "functions.php";
if (isset($_POST['submit'])) {
$sname = mysql_real_escape_string($_POST['shostfamilyid']);
if ($sname && $ssurname && $sgender && $saddress && $sdob && $sblood && $spassport && $shobby1 && $shobby2 && $schildren && $sanimals) {
$query = mysql_query("INSERT INTO student VALUES ('','$sname','$ssurname','$sgender','$saddress','$semail','$sdob','$stelephone','$sdiet','$sallergy','$smed','$sblood','$spassport','$shobby1','$shobby2','$shobby3','$ssiblings','$schildren','$srequests','$sanimals','$agent','')");
if ($query) {
send_email ($to, $from, $subject, $body); /* modify these as well */
header("location: successstudent2.php");
exit();
} else {
echo "Check All Required Fields Are Completed";
}
}
}
?>