mnftg64 Posted September 3, 2008 Share Posted September 3, 2008 Is it possible to create a form where the "sendto" e-mail value is given by a value selected by the form user? On my form I have a list of groups to get involved in and if a person selects group1, I want the e-mail to go to the leader of group1 and if the person selects group 2, I want the e-mail to go to the leader of group 2. I am using a multiple select box for the group selection. Link to comment https://forums.phpfreaks.com/topic/122547-complicated-php-form-help/ Share on other sites More sharing options...
swamp Posted September 3, 2008 Share Posted September 3, 2008 Post your code, its easy to do but alot easier with your code Link to comment https://forums.phpfreaks.com/topic/122547-complicated-php-form-help/#findComment-632732 Share on other sites More sharing options...
mnftg64 Posted September 3, 2008 Author Share Posted September 3, 2008 I did not write this code, I have little to no knowledge of actual PHP coding, I just happened to have a very specific need of which I couldn't find a pre-written code to do for me. <?php $MailToAddress = "[email protected]"; $redirectURL = "thankyou3.html"; $MailSubject = "Small Group: New Contact"; $sendHTML = FALSE; $serverCheck = TRUE; $w4fver = "2.2"; $ip = ($_SERVER['HTTP_X_FORWARDED_FOR'] == "" ? $_SERVER['REMOTE_ADDR'] : $_SERVER['HTTP_X_FORWARDED_FOR']); //function blockIP function blockip($ip) { $handle = @fopen("blockip.txt", 'a'); @fwrite($handle, $ip."\n"); @fclose($handle); } $w4fx = stristr(file_get_contents('blockip.txt'),getenv('REMOTE_ADDR')); if ($serverCheck) { if (preg_match ("/".str_replace("www.", "", $_SERVER["SERVER_NAME"])."/i", $_SERVER["HTTP_REFERER"])) { $w4fy = TRUE; } else { $w4fy = FALSE; } } else { $w4fy = TRUE; } if (($w4fy === TRUE) && ($w4fx === FALSE)) { $w4fMessage = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\"><html>\n<head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\"></head><body><font face=3Dverdana size=3D2>"; if (count($_GET) >0) { reset($_GET); while(list($key, $val) = each($_GET)) { $GLOBALS[$key] = $val; if (is_array($val)) { $w4fMessage .= "<b>$key:</b> "; foreach ($val as $vala) { $vala =stripslashes($vala); $vala = htmlspecialchars($vala); if (trim($vala)) { if (stristr($vala,"Content-Type:") || stristr($vala,"MIME-Version") || stristr($vala,"Content-Transfer-Encoding") || stristr($vala,"bcc:")) { blockip($ip); die("ILLEGAL EXECUTION DETECTED!"); } } $w4fMessage .= "$vala, "; } $w4fMessage .= "<br>\n"; } else { $val = stripslashes($val); if (trim($val)) { if (stristr($val,"Content-Type:") || stristr($val,"MIME-Version") || stristr($val,"Content-Transfer-Encoding") || stristr($val,"bcc:")) { blockip($ip); die("ILLEGAL EXECUTION DETECTED!"); } } if (($key == "Submit") || ($key == "submit")) { } else { if ($val == "") { $w4fMessage .= "$key: - <br>\n"; } else { $w4fMessage .= "<b>$key:</b> $val<br>\n"; } } } } // end while }//end if else { reset($_POST); while(list($key, $val) = each($_POST)) { $GLOBALS[$key] = $val; if (is_array($val)) { $w4fMessage .= "<b>$key:</b> "; foreach ($val as $vala) { $vala =stripslashes($vala); $vala = htmlspecialchars($vala); if (trim($vala)) { if (stristr($vala,"Content-Type:") || stristr($vala,"MIME-Version") || stristr($vala,"Content-Transfer-Encoding") || stristr($vala,"bcc:")) {blockip($ip); die("ILLEGAL EXECUTION DETECTED!"); } } $w4fMessage .= "$vala, "; } $w4fMessage .= "<br>\n"; } else { $val = stripslashes($val); if (trim($val)) { if (stristr($val,"Content-Type:") || stristr($val,"MIME-Version") || stristr($val,"Content-Transfer-Encoding") || stristr($val,"bcc:")) {blockip($ip); die("ILLEGAL EXECUTION DETECTED!"); } } if (($key == "Submit") || ($key == "submit")) { } else { if ($val == "") { $w4fMessage .= "$key: - <br>\n"; } else { $w4fMessage .= "<b>$key:</b> $val<br>\n"; } } } } // end while }//end else $w4fMessage .= "<font size=3D1><br><br>\n Sender IP: ".$ip."</font></font></body></html>"; $w4f_what = array("/To:/i", "/Cc:/i", "/Bcc:/i","/Content-Type:/i","/\n/"); $name = preg_replace($w4f_what, "", $name); $email = preg_replace($w4f_what, "", $email); if (!$email) {$email = $MailToAddress;} $mailHeader = "From: $name <$email>\r\n"; $mailHeader .= "Reply-To: $name <$email>\r\n"; $mailHeader .= "Message-ID: <". md5(rand()."".time()) ."@". ereg_replace("www.","",$_SERVER["SERVER_NAME"]) .">\r\n"; $mailHeader .= "MIME-Version: 1.0\r\n"; if ($sendHTML) { $mailHeader .= "Content-Type: multipart/alternative;"; $mailHeader .= " boundary=\"----=_NextPart_000_000E_01C5256B.0AEFE730\"\r\n"; } $mailHeader .= "X-Priority: 3\r\n"; $mailHeader .= "X-Mailer: PHP/" . phpversion()."\r\n"; $mailHeader .= "X-MimeOLE: Produced By Web4Future Easiest Form2Mail $w4fver\r\n"; if ($sendHTML) { $mailMessage = "This is a multi-part message in MIME format.\r\n\r\n"; $mailMessage .= "------=_NextPart_000_000E_01C5256B.0AEFE730\r\n"; $mailMessage .= "Content-Type: text/plain; charset=\"ISO-8859-1\"\r\nContent-Transfer-Encoding: quoted-printable\r\n\r\n"; $mailMessage .= trim(strip_tags($w4fMessage))."\r\n\r\n"; $mailMessage .= "------=_NextPart_000_000E_01C5256B.0AEFE730\r\n"; $mailMessage .= "Content-Type: text/html; charset=\"ISO-8859-1\"\r\nContent-Transfer-Encoding: quoted-printable\r\n\r\n"; $mailMessage .= "$w4fMessage\r\n\r\n"; $mailMessage .= "------=_NextPart_000_000E_01C5256B.0AEFE730--\r\n"; } if ($sendHTML === FALSE) { $mailHeader .= "Content-Type: text/plain; charset=\"ISO-8859-1\"\r\nContent-Transfer-Encoding: quoted-printable\r\n\r\n"; $mailMessage .= trim(strip_tags($w4fMessage))."\r\n\r\n"; } if (!mail($MailToAddress, $MailSubject, $mailMessage,$mailHeader)) { echo "Error sending e-mail!";} else { header("Location: ".$redirectURL); } } else { echo "<center><font face=verdana size=3 color=red><b>ILLEGAL EXECUTION DETECTED!</b></font></center>";} ?> Link to comment https://forums.phpfreaks.com/topic/122547-complicated-php-form-help/#findComment-632740 Share on other sites More sharing options...
swamp Posted September 3, 2008 Share Posted September 3, 2008 And the form? Link to comment https://forums.phpfreaks.com/topic/122547-complicated-php-form-help/#findComment-632741 Share on other sites More sharing options...
mnftg64 Posted September 3, 2008 Author Share Posted September 3, 2008 I tried labeling the mutli-selectbox after the variable the script may be looking for, but that didn't work. <form id="smallgroupform" name="smallgroupform" method="post" action="scripts/smallgroupscript.php"> <div align="left">Small Groups<br /> </div> <label></label> <p align="left">Name <input type="text" name="Name" /> <br /> <br /> E-Mail <input type="text" name="Email" /> <br /> <br /> Phone <input type="text" name="Phone" /> (not required)</p> <p align="left">Who's Small Group are you interested in joining? <select name="$MailToAddress[]" id="$MailToAddress[]" multiple> <option value="None" selected="selected">None</option> <option value="[email protected]">Rebecca & Kristin</option> <option value="[email protected]">Elizabeth & Emily</option> <option value="[email protected]">Jenny & Jen</option> <option value="[email protected]">Rachel & Abigail</option> <option value="[email protected]">Chris & Tim</option> <option value="[email protected]">Caleb & Billy</option> <option value="[email protected]">Zeph & Mark</option> <option value="[email protected]">Jesus & Dan</option> <option value="[email protected]">Mike (Truth Project)</option> </select> <br /> <label></label> </p> <p align="left"> </p> <p align="left"><br /> <label></label> </p> <p align="left"> <label> <input type="submit" name="Submit" id="Submit" value="Submit" /> </label> <label> <input type="reset" name="Reset" id="Reset" value="Reset" /> </label> <br /> </p> </form> Link to comment https://forums.phpfreaks.com/topic/122547-complicated-php-form-help/#findComment-632742 Share on other sites More sharing options...
swamp Posted September 3, 2008 Share Posted September 3, 2008 You almost had it mate, just needed to add: $MailToAddress = $_POST['MailToAddress']; which gets the field called MailToAddress from the form. Then call the name of the field in the form MailToAddress. form: <form id="smallgroupform" name="smallgroupform" method="post" action="scripts/smallgroupscript.php"> <div align="left">Small Groups<br /> </div> <label></label> <p align="left">Name <input type="text" name="Name" /> <br /> <br /> E-Mail <input type="text" name="Email" /> <br /> <br /> Phone <input type="text" name="Phone" /> (not required)</p> <p align="left">Who's Small Group are you interested in joining? <select name="MailToAddress" id="MailToAddress" multiple> <option value="None" selected="selected">None</option> <option value="[email protected]">Rebecca & Kristin</option> <option value="[email protected]">Elizabeth & Emily</option> <option value="[email protected]">Jenny & Jen</option> <option value="[email protected]">Rachel & Abigail</option> <option value="[email protected]">Chris & Tim</option> <option value="[email protected]">Caleb & Billy</option> <option value="[email protected]">Zeph & Mark</option> <option value="[email protected]">Jesus & Dan</option> <option value="[email protected]">Mike (Truth Project)</option> </select> <br /> <label></label> </p> <p align="left"> </p> <p align="left"><br /> <label></label> </p> <p align="left"> <label> <input type="submit" name="Submit" id="Submit" value="Submit" /> </label> <label> <input type="reset" name="Reset" id="Reset" value="Reset" /> </label> <br /> </p> </form> php script: <? $MailToAddress = $_POST['MailToAddress']; $redirectURL = "thankyou3.html"; $MailSubject = "Small Group: New Contact"; $sendHTML = FALSE; $serverCheck = TRUE; $w4fver = "2.2"; $ip = ($_SERVER['HTTP_X_FORWARDED_FOR'] == "" ? $_SERVER['REMOTE_ADDR'] : $_SERVER['HTTP_X_FORWARDED_FOR']); //function blockIP function blockip($ip) { $handle = @fopen("blockip.txt", 'a'); @fwrite($handle, $ip."\n"); @fclose($handle); } $w4fx = stristr(file_get_contents('blockip.txt'),getenv('REMOTE_ADDR')); if ($serverCheck) { if (preg_match ("/".str_replace("www.", "", $_SERVER["SERVER_NAME"])."/i", $_SERVER["HTTP_REFERER"])) { $w4fy = TRUE; } else { $w4fy = FALSE; } } else { $w4fy = TRUE; } if (($w4fy === TRUE) && ($w4fx === FALSE)) { $w4fMessage = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\"><html>\n<head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\"></head><body><font face=3Dverdana size=3D2>"; if (count($_GET) >0) { reset($_GET); while(list($key, $val) = each($_GET)) { $GLOBALS[$key] = $val; if (is_array($val)) { $w4fMessage .= "<b>$key:</b> "; foreach ($val as $vala) { $vala =stripslashes($vala); $vala = htmlspecialchars($vala); if (trim($vala)) { if (stristr($vala,"Content-Type:") || stristr($vala,"MIME-Version") || stristr($vala,"Content-Transfer-Encoding") || stristr($vala,"bcc:")) { blockip($ip); die("ILLEGAL EXECUTION DETECTED!"); } } $w4fMessage .= "$vala, "; } $w4fMessage .= "<br>\n"; } else { $val = stripslashes($val); if (trim($val)) { if (stristr($val,"Content-Type:") || stristr($val,"MIME-Version") || stristr($val,"Content-Transfer-Encoding") || stristr($val,"bcc:")) { blockip($ip); die("ILLEGAL EXECUTION DETECTED!"); } } if (($key == "Submit") || ($key == "submit")) { } else { if ($val == "") { $w4fMessage .= "$key: - <br>\n"; } else { $w4fMessage .= "<b>$key:</b> $val<br>\n"; } } } } // end while }//end if else { reset($_POST); while(list($key, $val) = each($_POST)) { $GLOBALS[$key] = $val; if (is_array($val)) { $w4fMessage .= "<b>$key:</b> "; foreach ($val as $vala) { $vala =stripslashes($vala); $vala = htmlspecialchars($vala); if (trim($vala)) { if (stristr($vala,"Content-Type:") || stristr($vala,"MIME-Version") || stristr($vala,"Content-Transfer-Encoding") || stristr($vala,"bcc:")) {blockip($ip); die("ILLEGAL EXECUTION DETECTED!"); } } $w4fMessage .= "$vala, "; } $w4fMessage .= "<br>\n"; } else { $val = stripslashes($val); if (trim($val)) { if (stristr($val,"Content-Type:") || stristr($val,"MIME-Version") || stristr($val,"Content-Transfer-Encoding") || stristr($val,"bcc:")) {blockip($ip); die("ILLEGAL EXECUTION DETECTED!"); } } if (($key == "Submit") || ($key == "submit")) { } else { if ($val == "") { $w4fMessage .= "$key: - <br>\n"; } else { $w4fMessage .= "<b>$key:</b> $val<br>\n"; } } } } // end while }//end else $w4fMessage .= "<font size=3D1><br><br>\n Sender IP: ".$ip."</font></font></body></html>"; $w4f_what = array("/To:/i", "/Cc:/i", "/Bcc:/i","/Content-Type:/i","/\n/"); $name = preg_replace($w4f_what, "", $name); $email = preg_replace($w4f_what, "", $email); if (!$email) {$email = $MailToAddress;} $mailHeader = "From: $name <$email>\r\n"; $mailHeader .= "Reply-To: $name <$email>\r\n"; $mailHeader .= "Message-ID: <". md5(rand()."".time()) ."@". ereg_replace("www.","",$_SERVER["SERVER_NAME"]) .">\r\n"; $mailHeader .= "MIME-Version: 1.0\r\n"; if ($sendHTML) { $mailHeader .= "Content-Type: multipart/alternative;"; $mailHeader .= " boundary=\"----=_NextPart_000_000E_01C5256B.0AEFE730\"\r\n"; } $mailHeader .= "X-Priority: 3\r\n"; $mailHeader .= "X-Mailer: PHP/" . phpversion()."\r\n"; $mailHeader .= "X-MimeOLE: Produced By Web4Future Easiest Form2Mail $w4fver\r\n"; if ($sendHTML) { $mailMessage = "This is a multi-part message in MIME format.\r\n\r\n"; $mailMessage .= "------=_NextPart_000_000E_01C5256B.0AEFE730\r\n"; $mailMessage .= "Content-Type: text/plain; charset=\"ISO-8859-1\"\r\nContent-Transfer-Encoding: quoted-printable\r\n\r\n"; $mailMessage .= trim(strip_tags($w4fMessage))."\r\n\r\n"; $mailMessage .= "------=_NextPart_000_000E_01C5256B.0AEFE730\r\n"; $mailMessage .= "Content-Type: text/html; charset=\"ISO-8859-1\"\r\nContent-Transfer-Encoding: quoted-printable\r\n\r\n"; $mailMessage .= "$w4fMessage\r\n\r\n"; $mailMessage .= "------=_NextPart_000_000E_01C5256B.0AEFE730--\r\n"; } if ($sendHTML === FALSE) { $mailHeader .= "Content-Type: text/plain; charset=\"ISO-8859-1\"\r\nContent-Transfer-Encoding: quoted-printable\r\n\r\n"; $mailMessage .= trim(strip_tags($w4fMessage))."\r\n\r\n"; } if (!mail($MailToAddress, $MailSubject, $mailMessage,$mailHeader)) { echo "Error sending e-mail!";} else { header("Location: ".$redirectURL); } } else { echo "<center><font face=verdana size=3 color=red><b>ILLEGAL EXECUTION DETECTED!</b></font></center>";} ?> Link to comment https://forums.phpfreaks.com/topic/122547-complicated-php-form-help/#findComment-632748 Share on other sites More sharing options...
mnftg64 Posted September 3, 2008 Author Share Posted September 3, 2008 It worked, thanks! I new I had to be missing some simple script command... Link to comment https://forums.phpfreaks.com/topic/122547-complicated-php-form-help/#findComment-632761 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.