PX : code

Submitting Forms through HTML E-mail by Shantanu Oak
Download this code


form.php (HTML form to be embedded in the e-mail)
    Please add the record here...
    <FORM name="myform" ACTION="http://www.shantanuoak.com/imp/process_form.php3" METHOD="POST">
    Your Name: <INPUT TYPE="TEXT" NAME="Name"><br>
    Your Surname: <INPUT TYPE="TEXT" NAME="Surname"><br>
    Flat Have at: <INPUT TYPE="TEXT" NAME="FlatHave"><br>
    Flat Want at: <INPUT TYPE="TEXT" NAME="FlatWant"><br>
    <INPUT TYPE="SUBMIT" VALUE="Add Record" NAME="sendit">
    <INPUT TYPE="SUBMIT" VALUE="Cancel" NAME="cancelit"><br>
    mail.php (send the mail to all the people in the database)
    <?php
    $i 
0
    
mysql_connect("host""login""password");
    
mysql_select_db("database");
    
$query "SELECT Receiver FROM Mailinglist";
    
$result mysql_query($query) or die("ERROR WHILE COLLECTING EMAILADDRESSES");
    while(list(
$Receiver) = mysql_fetch_row($result)) {
    
$filename "form.php";
    
$fp fopen($filename,"r");
    
$data fread($fp,filesize($filename));
    
$data .= "<INPUT TYPE=HIDDEN VALUE=$Receiver NAME=WHOIS>";
    
$subject "Survey";
    
$headers "From: shantanuo@yahoo.com\n"
    
$headers .= "Reply-To: shantanuo@yahoo.com\n"
    
$headers .= "Organization: Ok Software\n"
    
$headers .= "Content-Type: text/html; charset=iso-8859-1\n"
    
mail($Receiver$subject$data$headers);
    
$i $i 1;
    } 
    print(
"$i emails have been sent!");
    
?>
    process_form.php3 (save the survey results received)
    <html>
    <body>
    <h3>Thank you for your entry</h3>
    <?php
    mysql_connect
("host""username""password");
    
mysql_select_db("database");
    
mysql_query("INSERT INTO SurveyResult (Name, Surname, FlatHave, FlatWant, WHOIS) VALUES ('$Name', '$Surname', '$FlatHave', '$FlatWant', '$WHOIS')");
    
?>
    </body>
    </html>

Comments or questions?
PX is running PHP 5.2.17
Thanks to Miranda Productions for hosting and bandwidth.
Use of any code from PX is at your own risk.