0

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)
?>
2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by mpc123
0

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.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.