Click here to Skip to main content
15,895,011 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Can anyone supply me with the correct coding that will allow my contact form, once filled in online, to send the data to an email as well as save on the database.

Below is my code that sends to the database, this is all I have.

PHP
<?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')");

header('Location: success.php');

?>


What I have tried:

I have tried numerous options but I am not to sure why it won't work.
Posted
Updated 28-Jun-16 17:01pm
Comments
Sergey Alexandrovich Kryukov 28-Jun-16 22:48pm    
What have you tried so far?
Please don't be surprised with my question. Yes, you've shown mySQL statement (but did not explain what's the problem), but your question was also about mailing. What have you done to send a mail?
—SA

1 solution

Please see my comment to the question. In second thought, maybe it's only good that you did not even try to send any mail. This is a very dangerous operation. (Surprised?)

You really need to understand very well what you are doing, otherwise your host is turned into a zombie sending spam, or something like that, and it can be done without much effort in no time. Please see my past answer: unable to send mail , it showing the error in below code.
See also: In what way $('#myelement').valid(); works.

As to sending e-mail, here is a couple of options which you could easily find out in original PHP documentation:
PHP: mail — Manual,
Manual :: sends a mail,
(see also https://pear.php.net/manual/en/about-pear.php).

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900