I am working on a simple form only 2 fields. Name and Email. What I have succeded in doing so far is.
- I have the form send the data to a mysql database.
- I can query the database in total and also query the database based on a form entry.
- I have tested and I can send email using a basic mail script or from a form.
Where I am running to an issue is I need the data to also be sent to the submitter along with a third field from the database whish is the auto-encrement primary key as their member number. My question is how can I send email based on the database entry.
ie; Thank you "Submitter Name" for joining your Member ID is "Primary Key". This is my current code.
Index.html
<form method="post" action="doit.php">
Name<input name="Name" type="text" /><br>
Email<input name="Email" type="text" /><br>
<input name="Submit" type="submit" value="submit" />
</form>
doit.php
<?php
$con = mysqli_connect('localhost','DB_Username','DB_Password');
if(!$con)
{
echo 'Not Connected To Server';
}
if(!mysqli_select_db($con,'DB_Name'))
{
echo 'Database Not Selected';
}
$Name = $_POST['Name'];
$Email = $_POST['Email'];
$sql = "INSERT INTO Table_name (Name,Email) VALUES ('$Name','$Email')";
if(!mysqli_query($con,$sql))
{
echo 'Not Inserted';
}
else
{
echo 'Inserted';
}
header ("refresh:2; url=auto-response.php");
?>
auto-response.php
<?php
if ($_SERVER["REQUEST_METHOD"}=="POST") {
$connnection=mysqli_connect("localhost","DB_username","DB_password","DB_Name");
// Check connection
if ($connection) {
echo "connection successfull! <br>;"
} else {
die("connection failed. Reason ". mysqli_connect_err())
}
{
$Email=$_POST["Email"];
$Name=$_POST["Name"];
$ID=$_POST["ID"];
$sql="SELECT ID,Email,Name FROM Table_Name WHERE Email='".$Email."'";
$result = mysqli_query($connection,$sql);
$to = 'Email';
$subject = 'Thank you For Joining';
$message = 'Thank you for joining "Email" Your Member ID is "ID"';
$headers = 'From: dsarmy@thedarksideshop.com' . "
" .
'Reply-To: dsarmy@thedarksideshop.com' . "
" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>