简体   繁体   中英

PHP MySQL - Send email alert when a new record is added but

I need to send an email alert when a new record is added but the table also has input fields and i dont need an alert when a user edits those input field.

I have a database that is used for equipment delivery dates. A user will schedule a delivery for a piece of equipment and then enter the date into a back-end database(SQL Server).

I created a php application that looks at the backend database and puts the total number of deliveries on a jquery calendar.

在此输入图像描述

When the user clicks on a particular day on the calendar, it pulls up a table that shows the following:

Date
Equipment
Customer

I then created a mysql table which pushes that information into my local msyql table with the following fields:

AssignedPerson
Status
Comments

The user can then make their notes to the delivery.

The problem is sometimes the delivery dates change or a new delivery is added and we're not aware unless we constantly check the php app.

I want to send an alert when a new record is added but i dont need an alert when a user updates the table.

Here's the code i have for when a user updates the table. Again i only when an alert for when a new record is added to the mysql table from SQL backend database:

    include('./PHPMailer-master/class.phpmailer.php');

    servername_wamp = "localhost";
    $username_wamp = "root";
    $password_wamp = "";



           if(isset($_POST['id']))
           {
            $id=mysql_escape_String($_POST['id']);
            $AssignedPerson=mysql_escape_String($_POST['AssignedPerson']);
            $ShipDate=mysql_escape_String($_POST['ShipDate']);
            $Status=mysql_escape_String($_POST['Status']);
            $Numofmachines=mysql_escape_String($_POST['Numofmachines']);
            $Model=mysql_escape_String($_POST['Model']);


            $a = mysql_connect($servername_wamp, $username_wamp, $password_wamp) or die(mysql_error());
            $b = mysql_select_db('orders', $a) or die(mysql_error());

            $result2 = mysql_query("SELECT * FROM orders WHERE OrderNumber='$OrderNumber' LIMIT 1",$a) or die(mysql_error());
            $rs=mysql_fetch_row($result2);
       if ($rs) {


if (($rs['ShipDate_log']=='')&&($Status=='Assigned')) {
$sd=", ShipDate_log='".$ShipDate."'";


    $message1982 = "
            <ul>

            <li> <strong>ID:</strong> $id  </li>
            <li> <strong><font color='red'>Tech:</font></strong> $AssignedPerson   </li>
            <li> <strong>Ship Date:</strong> $ShipDate </li>
            <li> <strong>Customer:</strong> $Customer </li>
            <li> <strong>Status:</strong> $Status </li>
            <li> <strong>Sales Rep:</strong> $SalesRep  </li>
            <li> <strong>Order Number:</strong> $OrderNumber</li>
            <li> <strong>Number Of Machines:</strong> $Numofmachines </li>


            </ul>
            "; 







$mail             = new PHPMailer(); // defaults to using php "mail()"
$body             = $message1982;
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = false; // authentication enabled

$mail->Host = "10.10.10.38";
$mail->Port = 25; // or 587
$mail->IsHTML(true);

$mail->SetFrom("nservice2@everyone.com");
$address = "bot@everyone.com";
$mail->AddAddress($address, "John");
$mail->Subject    = ''. $Customer. ' Ticket Assigned';

$mail->MsgHTML($body);






if(!$mail->Send()) {
  echo "Mailer Error: " . $mail->ErrorInfo;
} else {
  echo "Message sent!";
}

A lot of people add columns like created_at and updated_at . When creating a record, you can assign both of these columns the same value. If these values are equal, it's a brand new record. If they're different, then it is an existing record that has been updated.

在插入过程中创建一个与google邮件服务或任何其他选择连接的小脚本,并使用创建的预定义电子邮件发送电子邮件,以便将电子邮件发送到所需的电子邮件地址,例如每次插入新记录时都会发送新电子邮件从x@gmail.com到xxx@xxx.xx,其中x是发送的电子邮件,xxx是接收者。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM