Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

How do I store data on database and send data to specific email

naydukenayduke South AfricaPosts: 1

Needs to store data on database and send data to specific email

I have managed to get my newsletter and contact form to send and store data to a database. Now I need to know how to get the same data to send to a specific mail at the same time.

Could someone please check my code below and tell me if this should work? How would I test if its working on localhost using xampp

My PHP code:

 <?php
/* Database config */
$db_host        = 'localhost';
$db_user        = 'root';
$db_pass        = '';
$db_database    = 'maxipakdb'; 
/* End config */

$mysqli = new mysqli($db_host, $db_user, $db_pass, $db_database);


/* check connection */
if (mysqli_connect_errno()) {printf("Connect failed: %s\n",             
mysqli_connect_error());}

$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];

// Perform queries 

mysqli_query($mysqli, "INSERT INTO maxicontact (id,name,email,message) 
VALUES (NULL,'$name','$email','$message')");

// Email 
$to = 'nadineduke28@gmail.com';
$subject = "My Subject";
$message = "Name: $name\
Email: $email\
Message:  $message";
$headers = "From: $email";

// Send the mail using PHPs mail() function
mail($to, $subject, $message, $headers);

header('Location: success.php');

?>

Best Answer

Sign In or Register to comment.