In: Computer Science
PHP
The database should have at least two tables with, at minimum, the following fields:
Table customers: Fields: |
Table billing: Fields: |
customer_ID |
customer_ID |
customer_L_Name |
customer_L_Name |
customer_F_Name |
service |
customer_Title (Mr, Ms, Dr. etc,) |
customer_bill |
street_Address |
amt_paid |
city_State_Zip |
bill_date |
customer_Phone |
date_paid |
customer_Email |
Create a PHP page that will extract a customer’s bill amount and the amount paid. Then it will calculate the amount due. If the amount due is greater than 0, an email should be generated and sent to the customer with that amount in the message. If the amount due is zero or there is a credit, generate a thank-you email that thanks the customer for his or her payment and expresses Lee’s wishes for continued business with this customer. Name the main page sendBill.php and be sure to include all the necessary accompanying files when you submit your work.
I have done in my system
with the details provided my you
My database name is " chg" with two tables "customers" and "billing"
screenshot of customers table
screenshot of billing table
Now the Sceenshot of sendbill.php page which will send mail to every customer as per your criteria automatically
Now i am sharing the code:
======================================
<html>
<head>
<title>
Send Bill
</title>
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script
src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
</head>
<body>
<div
class="container">
<h2>Customer Bill
Details </h2>
<p> it will send
email automatically when page reloads</p>
<table class="table
table-hover">
<thead>
<tr>
<th>Customer
ID</th>
<th>Customer L
Name</th>
<th>Bill
Amount</th>
<th>Bill
Paid</th>
<th>Bill
Due</th>
</tr>
</thead>
<tbody>
<?php
//data fetched
portion
$servername =
"localhost";
$username =
"root";
$password =
"";
$dbname =
"chg";
// Create
connection
$conn = new
mysqli($servername, $username, $password, $dbname);
// Check
connection
if
($conn->connect_error) {
die("Connection failed: " .
$conn->connect_error);
}
$sql = "SELECT *
FROM billing";
$result =
$conn->query($sql);
if
($result->num_rows > 0) {
// output data of each
row
while($row =
$result->fetch_assoc()) {
$cid=
$row["customer_ID"];
$clname=
$row["customer_L_Name"];
$cbill=
$row["customer_bill"];
$cpaid=
$row["amt_paid"];
$cdue=
$cbill-$cpaid;
?>
<tr>
<td><?php echo
$cid; ?></td>
<td><?php echo
$clname; ?></td>
<td><?php echo
$cbill; ?></td>
<td><?php echo
$cpaid; ?></td>
<td><?php echo
$cdue; ?></td>
</tr>
<?php
//mailing
portion
$sql = "SELECT
customer_Email FROM customers where
customer_ID=".$cid;
$result =
$conn->query($sql);
if
($result->num_rows > 0) {
// output data of each
row
while($row =
$result->fetch_assoc()) {
$em=$row["customer_Email"];
}}
if($cdue=0)
{
$mail_sub="Thanks
for you payment ";
$header =
"MIME-Version: 1.0" . "\r\n";
$header .=
"Content-type:text/html;charset=UTF-8" . "\r\n";
$message = 'Thanks for your
payment. and your payment due is Zero. Thanks
You';
$flag=mail($em,$mail_sub,$message,$header);
}
else
if($cdue>0)
{
$mail_sub="Thanks for you
payment ";
$header =
"MIME-Version: 1.0" . "\r\n";
$header .=
"Content-type:text/html;charset=UTF-8" . "\r\n";
$message = 'Dear Customer
ID '.$cid.' This is a gentle reminder that Your Amount Due
Rs.'.$cdue.'/- Please Pay Your Due Asap';
$flag=mail($em,$mail_sub,$message,$header);
}
}
} else {
echo "0
results";
}
$conn->close();
?>
</tbody>
</table>
</div>
</body>
</html>
<?php
echo
"<script>window.alert('MAil
Sent')</script>";
?>
================================
thank you