• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 868
  • Last Modified:

Send email notification after database entry

I am setting up a guestbook function.

Currently someone fills in the guestbook form and the results go to the database. What I need is an email to be sent out to me letting me know that the databse has been updated.

Any ideas how to do this?


Here's my current code...



if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  $insertSQL = sprintf("INSERT INTO guestbook (name, `from`, message, live) VALUES (%s, %s, %s, %s)",
                       GetSQLValueString($_POST['name'], "text"),
                       GetSQLValueString($_POST['from'], "text"),
                       GetSQLValueString($_POST['message'], "text"),
                       GetSQLValueString($_POST['live'], "int"));
					   
		


  mysql_select_db($database_HolyCross, $HolyCross);
  $Result1 = mysql_query($insertSQL, $HolyCross) or die(mysql_error());

  $insertGoTo = "guestbookok.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
	
	
  }
  header(sprintf("Location: %s", $insertGoTo));
}

	
?>

Open in new window

0
BrighteyesDesign
Asked:
BrighteyesDesign
2 Solutions
 
aplusexpertCommented:
You can send mail from trigger after insert in table or you can also send mail from application after inserting data in to database.

Please refer this link.
http://scriptingmysql.wordpress.com/2011/09/30/sending-and-managing-email-accounts-in-a-mysql-database-using-perl/

Thanks.
0
 
Julian HansenCommented:
Take a look at phpMailer (http://code.google.com/a/apache-extras.org/p/phpmailer/downloads/list)

You can read more in this thread http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_27832908.html

Your mail code would be inserted as shown
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  $insertSQL = sprintf("INSERT INTO guestbook (name, `from`, message, live) VALUES (%s, %s, %s, %s)",
                       GetSQLValueString($_POST['name'], "text"),
                       GetSQLValueString($_POST['from'], "text"),
                       GetSQLValueString($_POST['message'], "text"),
                       GetSQLValueString($_POST['live'], "int"));
					   
		


  mysql_select_db($database_HolyCross, $HolyCross);
  $Result1 = mysql_query($insertSQL, $HolyCross) or die(mysql_error());

  $insertGoTo = "guestbookok.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
	
	
  }
// Do email bit here

  header(sprintf("Location: %s", $insertGoTo));
}
?>

Open in new window

0

Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now