I am trying to use the phpmail function to send an email to a user if their post was accepted. First I am capturing the user email in a query if a form is submitted, but I'm not sure how to implement the mail function. Should it be something like this?:
if(isset($_POST ['submit'])){
//Some query to get the user email address
$results = $dbh->prepare("select $user_email from wp_users where
wp_users.ID=$user_ID");
$to=$results;
$subject="Whatever you want your subject to be";
$headers = "From: [email protected]\r\n";
$headers .= "Reply-To: [email protected] \r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message= "WHATEVER MESSAGE";
mail ($to , $subject , $message, $headers);
echo "Your message has been sent";
$insrt = "INSERT INTO table(ID,
text,
VALUES (
:ID,
:text)";
$stmt = $dbh->prepare($insrt);
$stmt->bindParam(':ID', $user_ID, PDO::PARAM_INT);
$stmt->bindParam(':text', $_POST['post_text'], PDO::PARAM_STR);
$stmt->execute();
}
select $user_emailsend mail to $results?????you wana send email to mysql query?