Using SendMail in Forms w/PHP HTML
am 22.04.2007 01:23:08 von jcageIs there any tutorials online for sending email through forms? I can
send an email as well as write to my MySQL database from home with the
following code but not at work. I think there might be something I'm
missing header-wise that keeps me from making this work on my work
system. I'm using Apache 1.3, PHP 4.1 (best the IT guys could do
though I'm using 5.x at home), and MySQL as the database. Thanks VERY
much for any help or pointers to a good tutorial. I'm trying to
provide an input form that writes to the database as well as emails
the recipient letting them know there's been activity. Thanks, John
My form PHP code is as follows:
Input form 1:
face=arial color=bright white> Your Name: $name Message For:$to Subject: Message:$text
Input form 2:
style="font-size:18">
align=center border=8">
require_once('generic_connect.php');
$DBName = "messages";
$table = "messages_tbl";
$id = $_POST['id'];
$date = $_POST['date'];
$name = $_POST['name'];
$subject = $_POST['subject'];
$to = $_POST['to'];
$text = $_POST['text'];
mysql_connect($DBhost,$DBuser,$DBpass) or die("Unable to connect
to database"); // make connection to database
mysql_select_db($DBName) or die("Unable to select database
$DBName"); // select database
$sqlquery = "INSERT INTO $table VALUES('$id', '$date', '$name',
'$subject', '$to', '$text')";
if ($results = mysql_query($sqlquery)) {
$to = stripslashes($to)."\r\n";
$subject = stripslashes($subject);
$text = stripslashes($text);
mail($to, $subject, $text, "From: admin@work.com");
}
mysql_close();
print "";
print "
Database";
print "Date: $date
$subject
";
?>