PHP MySQL After data insert send Email
insert.php
<form method="post" action="submitinsert.php">
name<input type="text" name="name"><br>
email<input type="email" name="email"><br>
<input type="submit" name="submit" value="submit">
</form>
submitinsert.php
<?php
$servername="localhost";
$username="root";
$password="";
$database="okmam";
//create connection$
$conn=new mysqli($servername, $username, $password, $database);
//check connection
if ($conn->connect_error)
{
die("connection failed: ".$conn->connect_error);
}
?>
<?php
$name=$_POST['name'];
$email=$_POST['email'];
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$sql = "INSERT INTO inserttest (name, email)
VALUES ('$name', '$email')";
if (mysqli_query($conn, $sql)) {
echo "New record created successfully";
if (mysqli_affected_rows($conn) == 1) { //If the Insert Query was successfull.
// Send the email:
$to="$email"; //change to ur mail address
$strSubject="OKMAM USERS | Email Verification";
$message = 'Hi, Please verify your email get activate your account.' ;
$message = '<p>Hi, Please verify your email get activate your account.</p>' ;
$message .= '<p>Click here : <a href="'.$link.'">'.$link.'</p>' ;
$headers = 'MIME-Version: 1.0'."\r\n";
//$headers .= 'Content-type: text/html; charset=iso-8859-1'."\r\n";
$headers .= "From: okmam <okmam1515@gmail.com>\r\n";
mail($to, $strSubject, $message, $headers);
// Flush the buffered output.
// Finish the page:
echo '<div class="success">Thank you for registering! A confirmation email has been sent to ' . $email . ' Please click on the Activation Link to Activate your account </div>';
} else { // If it did not run OK.
echo '<div class="errormsgbox">You could not be registered due to a system
error. We apologize for any
inconvenience.</div>';
}
}
else {
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}
mysqli_close($conn);
?>
</body>
</html>
download link
Comments
Post a Comment