Hello,
I have a form that retrieve the data from the database, which it depends on the expenses ID, then I want to send email to the employee to notification him that his expenses claim has rejected. The problem is on the phpmailer that does not take the value of employee email. The code in the below shows how I get the data from the database and sending email to the employee.
<?php
// Call the session for the employee no.
//connect to the database
$connect = mysql_connect("******","*****","********") or die ("Could not connect");
mysql_select_db("*******") or die ("Could not find the database");
//Get the expenses ID and select data from the database
if(isset($_GET['exp_id'])) {
$exp_id = $_GET['exp_id'];
$sql = mysql_query("SELECT e.emp_no, e.emp_mail, e.emp_name, d.emp_no, x.exp_id, d.exp_id
FROM employee e, details d, expenses_claim x
Where x.exp_id = '$exp_id' AND e.emp_no = d.emp_no AND x.exp_id =d.exp_id");
// fetch the data into variables
while($row = mysql_fetch_assoc($sql)){
$exp_id = $row['exp_id'];
$emp_no = $row['emp_no'];
$emp_name = $row['emp_name'];
$emp_email = $row['emp_mail'];
}
// if the employee wrote description, send an email to the employee for notification that the expenses claim declined
if(isset($_POST['description'])){
$description = strip_tags($_POST['description']);
require("class.phpmailer.php"); // path to the PHPMailer class
$mail = new PHPMailer();
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Mailer = "smtp";
$mail->Host = "smtp.gmail.com";
$Mail->SMTPDebug = 2; // 2 to enable SMTP debug information
$mail->Port = 587;
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->SMTPSecure = 'tls';
$mail->Username = "********"; // SMTP username
$mail->Password = "*******"; // SMTP password
$Mail->Priority = 1; // Highest priority - Email priority (1 = High, 3 = Normal, 5 = low)
$Mail->CharSet = 'UTF-8';
$Mail->Encoding = '8bit';
$mail->AddAddress($emp_email);
$mail->Subject = "Your expenses claim no. $exp_id declined";
$mail->Body = $description;
$mail->WordWrap = 50;
if(!$mail->Send()) {
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
} else {
header("Location:list.php");
}
}
}
// close the database connection
mysql_close($connect);
?>
And this code for the HTML form:
<form name="declineform" method="post" action="decline.php">
<font size="4">Employee no: <?php echo $emp_no; ?></font> <p></p><p><p/>
<font size="4">Employee name: <?php echo $emp_name; ?></font> <p></p><p><p/>
Reason of decline the expenses:
<textarea name="description" id = "description" maxlength="1000" cols="50" rows="10"></textarea><p></p>
<br/>
<input type="submit" name = "submit" value="Send">
</form>