View Single Post
Old 10-01-2021, 06:42 PM  
Publisher Bucks
Confirmed User
 
Industry Role:
Join Date: Oct 2018
Location: New Orleans, Louisiana. / Newcastle, England.
Posts: 1,126
Submission to SQL Database & Send Email?

How would I go about changing my submission.php coding so that when someone sends info across to the database, it also sends me an email to let me know?

This is my submission.php file contents presently:

Quote:
<?php
$link = mysqli_connect("localhost", "database", "password", "username");

// Check connection
if($link === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}

// Escape user inputs for security
$title = mysqli_real_escape_string($link, $_REQUEST['title']);
$recipe = mysqli_real_escape_string($link, $_REQUEST['recipe']);
$description = mysqli_real_escape_string($link, $_REQUEST['description']);
$category = mysqli_real_escape_string($link, $_REQUEST['category']);
$name = mysqli_real_escape_string($link, $_REQUEST['name']);
$email = mysqli_real_escape_string($link, $_REQUEST['email']);

// Attempt insert query execution
$sql = "INSERT INTO Directory (title, recipe, description, category, name, email) VALUES ('$title', '$recipe', '$description', '$category', '$name', '$email')";
if(mysqli_query($link, $sql)){
echo "Records added successfully.";
} else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}

// Close connection
mysqli_close($link);
?>4
Am I able to just fuck with the code from my feedback form code and append it onto the end of the code in submission.php above?

Quote:
<?php
if(isset($_POST['email'])) {

// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "[email protected]";
$email_subject = "New Recipe Submission";

}
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
?>
Any pointers in the right direction would be appreciated
Publisher Bucks is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote