Google
  Web www.spinics.net

automactic email notification

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]


I have an all-in-one form which allows record edits, adds and deletes
in a mysql table.

I would like to add the ability to automatically send email update to
a distribution list whenever a record is edited, deleted, or added.

I won't be hosting my own mail server so instead I will be using remote SMTP.

The mail script I created works just fine I am just not sure how to
put this all together for the notifications when the table is altered.

Thank you in advance!

Mail Script:

<?php
 require_once "Mail.php";

 $from = "Someone <email@.com>";
 $to = "Someone Recipient <email@.com>";
 $subject = "Hi!";
 $body = "Hi,\n\nHow are you?";

 $host = "example.com";
 $port = "587";
 $username = "example";
 $password = "example";

 $headers = array ('From' => $from,
   'To' => $to,
   'Subject' => $subject);
 $smtp = Mail::factory('smtp',
   array ('host' => $host,
     'port' => $port,
     'auth' => true,
     'username' => $username,
     'password' => $password));

 $mail = $smtp->send($to, $headers, $body);

 if (PEAR::isError($mail)) {
   echo("<p>" . $mail->getMessage() . "</p>");
  } else {
   echo("<p>Message successfully sent!</p>");
  }
 ?>



Form Script:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd";>
<html>
<head>
        <title>ATC West Swap</title>
<script type='text/javascript' src='../js/jquery-1.2.3.js'></script>
<script type='text/javascript' src='../js/menu.js'></script>

<link rel="stylesheet" href="../css/style.css" type="text/css" media="screen" />


</style>
</head>
<body>
<div id="boundary">
<h1>West RF Engineering Dashboard</h1>
<ul id="nav">
    <li><a href="../index.php">Home</a></li>
    <li><a href="#">ATC West Swap</a>
      <ul>
            <li><a href="atcswap.php">Expiring Leases</a></li>
            <li><a href="lowmou.php">Low MOU</a></li>
      </ul>
    </li>
</ul>
<div id="content">

</div>
<p id="footer">Low MOU WEST</p>
<HR>
<?
$objConnect = mysql_connect("localhost","cstine","cstine") or
die(mysql_error());
$objDB = mysql_select_db("atc");

//*** Add Condition ***//
if($_POST["hdnCmd"] == "Add")
{
	$strSQL = "INSERT INTO lowmou ";
	$strSQL .="(SiteID,NewSiterraSiteID,ATCSiteID,CricketRegion,Comments,
				Progress,willsitebedecom,relocationTowerVendor) ";
	$strSQL .="VALUES ";
	$strSQL .="('".$_POST["txtAddSiteID"]."','".$_POST["txtAddNewSiterraSiteID"]."'
";
	$strSQL .=",'".$_POST["txtAddATCSiteID"]."' ";
	$strSQL .=",'".$_POST["txtAddCricketRegion"]."','".$_POST["txtAddComments"]."'
";
	$strSQL .=",'".$_POST["txtAddProgress"]."' ";
	$strSQL .=",'".$_POST["txtAddwillsitebedecom"]."','".$_POST["txtAddrelocationTowerVendor"]."')
";
	$objQuery = mysql_query($strSQL);
		
	if(!$objQuery)
	{
		echo "Error Save [".mysql_error()."]";
	}
	//header("location:$_SERVER[PHP_SELF]");
	//exit();
}

//*** Update Condition ***//
if($_POST["hdnCmd"] == "Update")
{
	$strSQL = "UPDATE lowmou SET ";
	$strSQL .="SiteID = '".$_POST["txtEditSiteID"]."' ";
	$strSQL .=",NewSiterraSiteID = '".$_POST["txtEditNewSiterraSiteID"]."' ";
	$strSQL .=",ATCSiteID = '".$_POST["txtEditATCSiteID"]."' ";
	$strSQL .=",CricketRegion = '".$_POST["txtEditCricketRegion"]."' ";
	$strSQL .=",Comments = '".$_POST["txtEditComments"]."' ";
	$strSQL .=",Progress = '".$_POST["txtEditProgress"]."' ";
	$strSQL .=",willsitebedecom = '".$_POST["txtEditwillsitebedecom"]."' ";	
	$strSQL .=",relocationTowerVendor =
'".$_POST["txtEditrelocationTowerVendor"]."' ";
	$strSQL .="WHERE SiteID = '".$_POST["hdnEditSiteID"]."' ";
	$objQuery = mysql_query($strSQL);
	if(!$objQuery)
	{
		echo "Error Update [".mysql_error()."]";
	}
	//header("location:$_SERVER[PHP_SELF]");
	//exit();
}

//*** Delete Condition ***//++++
if($_GET["Action"] == "Del")
{
	$strSQL = "DELETE FROM lowmou ";
	$strSQL .="WHERE SiteID = '".$_GET["srID"]."' ";
	$objQuery = mysql_query($strSQL);
	if(!$objQuery)
	{
		echo "Error Delete [".mysql_error()."]";
	}
	//header("location:$_SERVER[PHP_SELF]");
	//exit();
}

$strSQL = "SELECT * FROM lowmou";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
?>
<form name="frmMain" method="post" action="<?=$_SERVER["PHP_SELF"];?>">
<input type="hidden" name="hdnCmd" value="">
<table>
  <tr>
    <th>SiteID </th>
    <th>NewSiterraSiteID </th>
    <th>ATCSiteID </th>
    <th>CricketRegion </th>
    <th>Comments </th>
    <th>Progress</th>
    <th>Will site be decom?</th>
    <th>Relocation Tower Vendor</th>
	<th>Edit </th>
    <th>Delete </th>
  </tr>

<?
while($objResult = mysql_fetch_array($objQuery))
{
?>

  <?
	if($objResult["SiteID"] == $_GET["srID"] and $_GET["Action"] == "Edit")
	{
  ?>
  <tr>
    <td><div align="center">
		<input type="text" name="txtEditSiteID" size="5"
value="<?=$objResult["SiteID"];?>">
		<input type="hidden" name="hdnEditSiteID" size="5"
value="<?=$objResult["SiteID"];?>">
	</div></td>
    <td><input type="text" name="txtEditNewSiterraSiteID" size="10"
value="<?=$objResult["NewSiterraSiteID"];?>"></td>
    <td><input type="text" name="txtEditATCSiteID" size="10"
value="<?=$objResult["ATCSiteID"];?>"></td>
    <td><div align="center"><input type="text"
name="txtEditCricketRegion" size="5"
value="<?=$objResult["CricketRegion"];?>"></div></td>
    <td align="right"><input type="text" name="txtEditComments"
size="25" value="<?=$objResult["Comments"];?>"></td>
    <td align="right"><input type="text" name="txtEditProgress"
size="25" value="<?=$objResult["Progress"];?>"></td>
	<td align="right"><input type="text" name="txtEditwillsitebedecom"
size="5" value="<?=$objResult["willsitebedecom"];?>"></td>
	<td align="right"><input type="text"
name="txtEditrelocationTowerVendor" size="20"
value="<?=$objResult["relocationTowerVendor"];?>"></td>
    <td colspan="2" align="right"><div align="center">
      <input name="btnAdd" type="button" id="btnUpdate" value="Update"
OnClick="frmMain.hdnCmd.value='Update';frmMain.submit();">
	  <input name="btnAdd" type="button" id="btnCancel" value="Cancel"
OnClick="window.location='<?=$_SERVER["PHP_SELF"];?>';">
    </div></td>
  </tr>
  <?
	}
  else
	{
  ?>
  <tr>
    <td><div align="center"><?=$objResult["SiteID"];?></div></td>
    <td><?=$objResult["NewSiterraSiteID"];?></td>
    <td><?=$objResult["ATCSiteID"];?></td>
    <td><div align="center"><?=$objResult["CricketRegion"];?></div></td>
    <td align="right"><?=$objResult["Comments"];?></td>
    <td align="left"><?=$objResult["Progress"];?></td>
    <td><div align="center"><?=$objResult["willsitebedecom"];?></div></td>
    <td><?=$objResult["relocationTowerVendor"];?></td>
    <td align="center"><a
href="<?=$_SERVER["PHP_SELF"];?>?Action=Edit&srID=<?=$objResult["SiteID"];?>">Edit</a></td>
	<td align="center"><a href="JavaScript:if(confirm('Confirm
Delete?')==true){window.location='<?=$_SERVER["PHP_SELF"];?>?Action=Del&srID=<?=$objResult["SiteID"];?>';}">Delete</a></td>
  </tr>
  <?
	}
  ?>
<?
}
?>
  <tr>
    <td><div align="center"><input type="text" name="txtAddSiteID"
size="5"></div></td>
    <td><input type="text" name="txtAddNewSiterraSiteID" size="10"></td>
    <td><input type="text" name="txtAddATCSiteID" size="10"></td>
    <td><div align="center"><input type="text"
name="txtAddCricketRegion" size="5"></div></td>
    <td align="right"><input type="text" name="txtAddComments" size="40"></td>
    <td align="right"><input type="text" name="txtAddProgress" size="25"></td>
    <td><div align="center"><input type="text"
name="txtAddwillsitebedecom" size="5"></div></td>
    <td><input type="text" name="txtAddrelocationTowerVendor" size="25"></td>
    <td colspan="2" align="right"><div align="center">
      <input name="btnAdd" type="button" id="btnAdd" value="Add"
OnClick="frmMain.hdnCmd.value='Add';frmMain.submit();">
    </div></td>
  </tr>
</table>
</form>
<?
mysql_close($objConnect);
?>
</body>
</html>

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Plagiarism Notes]     [Postgresql]     [Yosemite News]

Powered by Linux