HomePHP Page 3 - User Management in a PHP Invoicing System
Emailing reminders - PHP
In this fourth and final article covering the creation of a PHP invoicing system, we're going to put together the user management section. In this section we will be able to view all available users and do all the associated things like deleting or updating user details. We are also going to be able to add new users.
When a invoice remains unpaid for a set amount of time you can send an email as a reminder to the client. This option is available when you view the list of unpaid invoices. So, create a new PHP document and save it as emailInv.php. Then add the following code:
Code 8 emailInv.php
<? ob_start(); include "config.php"; $query="SELECT email FROM client where id='".$u_id."'"; $result1 = mysql_query($query); if (!$result1) { $error = mysql_error(); }else{ while ($row = mysql_fetch_array($result1)) { $em= $row["email"]; } } $query="SELECT * FROM invoices where invno='".$u_id."'"; $results=mysql_query($query); if(!$results){ exit(mysql_error()); } while ($row = mysql_fetch_array($results)) { $invNo=$row["invno"]; $dte=$row["inv_date"]; $dte=date("d/m/Y"); } $query_invdetails = "SELECT * FROM clientinv WHERE finv='".$invNo'"; if(!$result_invdetails= mysql_query($query_invdetails)){ echo mysql_error(); }else{ $num_invdetails = mysql_num_rows($result_invdetails); $invdetails=mysql_fetch_assoc($result_invdetails);} $emailAd=your@emailaddress; $subj="RE: Overdue Invoice Reminder."; $mess="Product Description: $invdetails['descr']crn"; $mess .="Invoice Number: $invNorn"; $mess .= "Invoice Date: $dtern"; $mess .="Total (incl. VAT): $invdetails['totwVAT']rn"; $mess .="If you have any queries or problems please do not hesitate to contactrn"; $mess .=" your@emailaddress "; $from=" your@emailaddress $to=$em ;//Client email address if (mail($to,$subj,$mess,$from)){ header("location:Main.php?act=success"); }else{ echo "Could not send mail. Please check your mail settings"; } ?>
A client ID is sent to this script from the unpaid.php page and is then used to retrieve the email address and other information of the client. The script runs three queries; each of them retrieves data related to a particular invoice. The first query interrogates the client table and retrieves the client email address. The second query retrieves the invoice number and the date of the invoice. And finally, the third query retrieves the invoice description and cost. This information is then used to create an email message, and then sent off.