For some reason, my db variables don't show up in the email. I know I'm connecting, because I tried printing them out to the page and that worked. Here's my script:
?php
function mailer_header()
{
?>
<HEAD><TITLE>Tip Me</TITLE></HEAD>
<BODY>
<?php
}
function mailer_footer()
{
?>
</BODY>
<?php
}
function error_message($msg)
{
mailer_header();
print "<SCRIPT>alert(\"Error: $msg\");history.go(-1)</SCRIPT>";
mailer_footer();
exit;
}
function user_message($msg)
{
mailer_header();
"<SCRIPT>alert(\"$msg\");history.go(-1)</SCRIPT>";
mailer_footer();
exit;
}
function mail_form()
{
global $PHP_SELF;
?>
<FORM METHOD=POST ENCTYPE="MULTIPART/FORM-DATA" ACTION="<?php print $PHP_SELF ?>">
<INPUT TYPE="hidden" NAME="action" VALUE="send_mail">
<TABLE BORDER=0>
<TR>
<TD>To:</TD>
<TD><INPUT NAME="mail_to" SIZE=25></TD>
</TR>
<TR>
<TD>From:</TD>
<TD><INPUT NAME="mail_from" SIZE=25></TD>
</TR>
<TR>
<TD COLSPAN=2><INPUT TYPE="SUBMIT" VALUE="Send" NAME="submit"></TD>
</TR>
</TABLE>
</FORM>
<?php
}
function send_mail()
{
global $mail_to, $mail_from, $mail_body, $mail_subject;
$mail_parts["mail_to"] = $mail_to;
$mail_parts["mail_from"] = $mail_from;
$mail_parts["mail_subject"] = $mail_subject;
$mail_parts["mail_body"] = $mail_body;
if(my_mail($mail_parts))
print "Successfully sent the email.";
else print "An unknown error occurred while attempting to send the email.";
}
function my_mail($mail_parts)
{
db connection
include "../Includes/db_conn.inc";
$query = "SELECT * FROM members WHERE id='$id';";
$result = mysql_query($query, $db);
$query_data = mysql_fetch_array($result, MYSQL_ASSOC);
$firstname = stripslashes($query_data["firstname"]);
$lastname = stripslashes($query_data["lastname"]);
$message = "Here is the contact info:\n";
$message .=$firstname.$lastname."\n";
$mail_to = $mail_parts["mail_to"];
$mail_from = $mail_parts["mail_from"];
$mail_subject = "I have a tip for you.";
$mail_body = $message;
if (empty($mail_to)) error_message("Empty to field!");
$mail_to = str_replace(";", ",", $mail_to);
$mail_headers = '';
if (!empty($mail_from)) $mail_headers .= "From: $mail_from\n";
$mail_subject = stripslashes($mail_subject);
$mail_body = stripslashes($mail_body);
return mail($mail_to,$mail_subject,$mail_body,$mail_headers);
}
switch ($action)
{
case "send_mail":
mailer_header();
send_mail();
mailer_footer();
break;
case "mail_form":
mailer_header();
send_form();
mailer_footer();
break;
default:
mailer_header();
mail_form();
mailer_footer();
break;
}
?>