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

BrighteyesDesignAsked:
Who is Participating?
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.