I have this very easy form to store info in a database table but i would like to be emailed once somebody has entered the details, how would i do this please?

Form

<form action="insert.php" method="post">
  <div align="center">Firstname: 
    <input type="text" name="firstname" />
    Lastname: 
  <input type="text" name="lastname" />
    Email: 
  <input type="text" name="email" />
  <input type="submit" />
  </div>
</form>

Insert.php

<?php
$con = mysql_connect("x","x","x");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("x", $con);

$sql="INSERT INTO Persons (FirstName, LastName, Email)
VALUES
('$_POST[firstname]','$_POST[lastname]','$_POST[email]')";

if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }
echo "Thank you you will recieve information shortly";

mysql_close($con)
?>

Insert the following code right before echo "Thank you......

$to = "youremail@somewhere.com" //Your email address
$subject = "New Entry"; //Email subject
$message = "new details have been entered into the database" //Body of email
mail($to, $subject, $message);

Check http://php.net/manual/en/function.mail.php for complete info on the mail() function.

perfect thank you

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.