checkbox's to send to different email address
Posted: Wed May 21, 2008 6:51 am
As per the title, i am trying to design a contact form where users would select which department the email should be sent to after they select the appropriate checkbox.
i have created 2 mysql tables, 1 called categories, 1 called email_address.
The email_address table has a category id which relates to the categories table.
Instead of posting all the html,php i will only post part of the form:
How i thought it would work is that if the checkbox = 1 then send email to that email address and record the contact form into the database. But i'm not sure i've got the loop correct. Any help would be appreciated or if you could point me in the right direction.
i have created 2 mysql tables, 1 called categories, 1 called email_address.
The email_address table has a category id which relates to the categories table.
Instead of posting all the html,php i will only post part of the form:
Code: Select all
<input type="checkbox" name="test1" id="test1" value="1" <?php echo (isset($_POST["test1"]))? "checked" : ""; ?> />Code: Select all
<?php
include_once("../../../php_includes/includes.inc.php");
$page_title = "Send Message";
$errors = array();
if(isset($_POST["submit"])){
if(empty($_POST["message"])){
$errors[] = "The <strong>message</strong> can not be left empty";
}
if(!count($errors)){
$test1= (isset($_POST["test1"]))? 1 : 0;
$message = $DB -> make_safe($_POST["message"]);
$sql = "";
if($_POST["test1"] = 1){
$sql .= " AND email_address = " . $test1;
}
// Get details
$details_qry = "
SELECT
e.*,
c.*
FROM
email_address AS e
LEFT JOIN
category AS c
ON (c.category_id = e.category_id)
WHERE
e.email_address_id != 0
AND
" . $sql;
$qry = $DB -> query($details_qry);
$message = wordwrap(stripslashes($_POST["message"]), 70);
while($row = $DB -> fetch_array($qry)){
$DB -> query("
INSERT INTO
data (
test1,
message
) VALUES (
" . $test1 . ",
'" . $message . "'
)
");
if($test1){
$email_message = "Hello " . $first_name . "\n\n";
@mail($row["test1"], "From Me", $email_message, "From: info@emailaddress.com.", "-f" . $SETTINGS["from_email"]);
}
}
}
}
include_once("index.inc.html");
?>