I have a simple php email script which collects the email address and subject from a form.
When the form is submitted, I want an email to be sent to the address supplied by the user as well as a text field that is in my database.
I have everything working but I am not sure how to reference the actual database cell with the info.
I want the variable $message to come from my database, I already have the connections to the database and table working.
When I submit, the script sends the email correctly minus the $message from the database. ( thats what i need help with)
Code: Select all
/*
$email = $HTTP_POST_VARS['email'];
$subject= $HTTP_POST_VARS['subject'];
$message = HOW DO I WRITE THIS TO GET MY DATA FROM THE DATABASE?
/* PHP form validation: the script checks that the Email field contains a valid email address and the Subject field isn't preg_match performs a regular expression match. It's a very powerful PHP function to validate form fields and other strings - see PHP manual for details. */
if (!preg_match("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/", $email)) {
echo "<h4>Invalid email address</h4>";
echo "<a href='javascript:history.back(1);'>Back</a>";
} elseif ($subject == "") {
echo "<h4>No subject</h4>";
echo "<a href='javascript:history.back(1);'>Back</a>";
}
/* Sends the mail and outputs the "Thank you" string if the mail is successfully sent, or the error string otherwise. */
elseif (mail($email,$subject,$message)) {
echo "<h4>Thank you for sending email</h4>";
} else {
echo "<h4>Can't send email to $email</h4>";
}Thanks