nd4spdbh Posted March 9, 2007 Share Posted March 9, 2007 OK well im looking for a contact form, but i would like to be able to click a certan link and have it use the emal... This is for a project at school. Let me expalin further. im a senior at my highschool in the website class and we update our site. Any ways we have depratment pages with all the teachers of the departments with mailto links to their underneath each of their pictures. now with mailto links this opens up the default email app on the computer and my teacher came upto me to find a solution. So i instantly thought PHP as i have worked with php contact forms in the past and they work very well and are quite easy. Now what i would like to do is to be able to click on the link below each of the teachers picture and have it open up the contact form page and have it change the TO form to the teacher. So i was wondering if there was an easy way to do this. Like in the link have it open up the php page with some type of parameter that changes the TO form in relation to the teachers email that was click on. Thanks Link to comment https://forums.phpfreaks.com/topic/41894-contact-form-with-different-to-links/ Share on other sites More sharing options...
skali Posted March 9, 2007 Share Posted March 9, 2007 If you want to save emails and teachers information to database and then use it: Then create teachers page with id, name, email,image as the columns. From the page with teachers images create links with <a href='contact_form.php?teacher_id=<?= $id_from_database?>'><img src='<?= $image_from_database?>'></a> Otherwise if you don't want database then just create link this way <a href='[email protected]'><img src='teacher1 image'></a> On the form page just use $_GET['email'] to use teachers email address for sending this form Link to comment https://forums.phpfreaks.com/topic/41894-contact-form-with-different-to-links/#findComment-203135 Share on other sites More sharing options...
nd4spdbh Posted March 9, 2007 Author Share Posted March 9, 2007 hmm im having a lil problem... i changed the parameter in the field that says my email (testing with mine) with the $_GET['email'] and it doesnt work. theres 3 files neede for this contact form to work, a HTML template file, and 2 php files <?php /********************************************************************************* * Filename: mcs_config.php * Developer: MyCoStar.com *********************************************************************************/ error_reporting (E_ALL ^ E_NOTICE); //=============================== // Site Initialization //------------------------------- $app_path = "."; // Obtain the path where this site is located on the server $GEmails_subject = "BENSHOME.TK CONTACT FORM"; // set subject of email of email [color=blue][font=Verdana]$GAdmin_email = "$_GET['email']"; [/font] [/color] // set email address where you want to receive message //------------------------------- // Create Header and Footer Path variables //------------------------------- //********************************************************************************* // configuration part ended, please don't edit functions below text //********************************************************************************* //=============================== // Common functions //------------------------------- //------------------------------- // Obtain specific URL Parameter from URL string //------------------------------- function get_param($param_name) { global $HTTP_POST_VARS; global $HTTP_GET_VARS; $param_value = ""; if(isset($HTTP_POST_VARS[$param_name])) $param_value = $HTTP_POST_VARS[$param_name]; else if(isset($HTTP_GET_VARS[$param_name])) $param_value = $HTTP_GET_VARS[$param_name]; return $param_value; } function tohtml($strValue) { return htmlspecialchars($strValue); } //=============================== // GlobalFuncs begin function validEmail($email) { if (eregi("^[a-z0-9]+([-_\.]?[a-z0-9])+@[a-z0-9]+([-_\.]?[a-z0-9])+\.[a-z]{2,4}", $email)) { return TRUE; } else { return FALSE; } } // GlobalFuncs end //=============================== //=============================== // Template engine class Template { var $sTemplate; var $DBlocks = array(); // initial data:files and blocks var $ParsedBlocks= array(); // resulted data and variables var $templates_root; function Template($templates_root) { $this->templates_root = $templates_root; } function load_file($filename, $sName) { $nName = ""; $template_path = $this->templates_root . "/" . $filename; if (file_exists($template_path)) { $this->DBlocks[$sName] = join('',file($template_path)); $nName = $this->NextDBlockName($sName); while($nName != "") { $this->SetBlock($sName, $nName); $nName = $this->NextDBlockName($sName); } } } function NextDBlockName($sTemplateName) { $sTemplate = $this->DBlocks[$sTemplateName]; $BTag = strpos($sTemplate, "<!--Begin"); if($BTag === false) { return ""; } else { $ETag = strpos($sTemplate, "-->", $BTag); $sName = substr($sTemplate, $BTag + 9, $ETag - ($BTag + 9)); if(strpos($sTemplate, "<!--End" . $sName . "-->") > 0) { return $sName; } else { return ""; } } } function SetBlock($sTplName, $sBlockName) { if(!isset($this->DBlocks[$sBlockName])) $this->DBlocks[$sBlockName] = $this->getBlock($this->DBlocks[$sTplName], $sBlockName); $this->DBlocks[$sTplName] = $this->replaceBlock($this->DBlocks[$sTplName], $sBlockName); $nName = $this->NextDBlockName($sBlockName); while($nName != "") { $this->SetBlock($sBlockName, $nName); $nName = $this->NextDBlockName($sBlockName); } } function getBlock($sTemplate, $sName) { $alpha = strlen($sName) + 12; $BBlock = strpos($sTemplate, "<!--Begin" . $sName . "-->"); $EBlock = strpos($sTemplate, "<!--End" . $sName . "-->"); if($BBlock === false || $EBlock === false) return ""; else return substr($sTemplate, $BBlock + $alpha, $EBlock - $BBlock - $alpha); } function replaceBlock($sTemplate, $sName) { $BBlock = strpos($sTemplate, "<!--Begin" . $sName . "-->"); $EBlock = strpos($sTemplate, "<!--End" . $sName . "-->"); if($BBlock === false || $EBlock === false) return $sTemplate; else return substr($sTemplate,0,$BBlock) . "{" . $sName . "}" . substr($sTemplate, $EBlock + strlen("<!--End" . $sName . "-->")); } function GetVar($sName) { return $this->DBlocks[$sName]; } function set_var($sName, $sValue) { $this->ParsedBlocks[$sName] = $sValue; } function print_var($sName) { echo $this->ParsedBlocks[$sName]; } function parse($sTplName, $bRepeat) { if(isset($this->DBlocks[$sTplName])) { if($bRepeat && isset($this->ParsedBlocks[$sTplName])) $this->ParsedBlocks[$sTplName] = $this->ParsedBlocks[$sTplName] . $this->ProceedTpl($this->DBlocks[$sTplName]); else $this->ParsedBlocks[$sTplName] = $this->ProceedTpl($this->DBlocks[$sTplName]); } else { echo "<br><b>Block with name <u><font color=\"red\">$sTplName</font></u> does't exist</b><br>"; } } function pparse($block_name, $is_repeat) { $this->parse($block_name, $is_repeat); echo $this->ParsedBlocks[$block_name]; } function blockVars($sTpl,$beginSymbol,$endSymbol) { if(strlen($beginSymbol) == 0) $beginSymbol = "{"; if(strlen($endSymbol) == 0) $endSymbol = "}"; $beginSymbolLength = strlen($beginSymbol); $endTag = 0; while (($beginTag = strpos($sTpl,$beginSymbol,$endTag)) !== false) { if (($endTag = strpos($sTpl,$endSymbol,$beginTag)) !== false) { $vars[] = substr($sTpl, $beginTag + $beginSymbolLength, $endTag - $beginTag - $beginSymbolLength); } } if(isset($vars)) return $vars; else return false; } function ProceedTpl($sTpl) { $vars = $this->blockVars($sTpl,"{","}"); if($vars) { reset($vars); while(list($key, $value) = each($vars)) { if(preg_match("/^[\w\_][\w\_]*$/",$value)) if(isset($this->ParsedBlocks[$value])) $sTpl = str_replace("{".$value."}",$this->ParsedBlocks[$value],$sTpl); else if(isset($this->DBlocks[$value])) { $this->parse($value, false); $sTpl = str_replace("{".$value."}", $this->ParsedBlocks[$value], $sTpl); } else $sTpl = str_replace("{".$value."}","",$sTpl); } } return $sTpl; } function PrintAll() { $res = "<table border=\"1\" width=\"100%\">"; $res .= "<tr bgcolor=\"#C0C0C0\" align=\"center\"><td>Key</td><td>Value</td></tr>"; $res .= "<tr bgcolor=\"#FFE0E0\"><td colspan=\"2\" align=\"center\">ParsedBlocks</td></tr>"; reset($this->ParsedBlocks); while(list($key, $value) = each($this->ParsedBlocks)) { $res .= "<tr><td><pre>" . htmlspecialchars($key) . "</pre></td>"; $res .= "<td><pre>" . htmlspecialchars($value) . "</pre></td></tr>"; } $res .= "<tr bgcolor=\"#E0FFE0\"><td colspan=\"2\" align=\"center\">DBlocks</td></tr>"; reset($this->DBlocks); while(list($key, $value) = each($this->DBlocks)) { $res .= "<tr><td><pre>" . htmlspecialchars($key) . "</pre></td>"; $res .= "<td><pre>" . htmlspecialchars($value) . "</pre></td></tr>"; } $res .= "</table>"; return $res; } } ?> second PHP file <?php /********************************************************************************* * Filename: contactus.php * Developer: MyCoStar.com *********************************************************************************/ //------------------------------- // contactus CustomIncludes begin include ("./mcs_config.php"); // contactus CustomIncludes end //------------------------------- //=============================== // Save Page and File Name available into variables //------------------------------- $filename = "contactus.php"; $template_filename = "contactus.html"; //=============================== //=============================== //Save the name of the form and type of action into the variables //------------------------------- $sAction = get_param("FormAction"); $sForm = get_param("FormName"); //=============================== //------------------------------- // Initialize error variables //------------------------------- $sFormErr = ""; $isSent = ""; if ($sAction=="SendEmail" ) SendEmailToUs(); // contactus Show begin //=============================== // Display page //------------------------------- // Load HTML template for this page //------------------------------- $tpl = new Template($app_path); $tpl->load_file($template_filename, "contactus"); //------------------------------- // Load HTML template of Header and Footer //------------------------------- //------------------------------- $tpl->set_var("FileName", $filename); //------------------------------- // Step through each form //------------------------------- Form_show(); //------------------------------- // Process page templates //------------------------------- //------------------------------- // Output the page to the browser //------------------------------- $tpl->pparse("contactus", false); // contactus Show end //******************************************************************************** function SendEmailToUs(){ //------------------------------- // Initialize variables //------------------------------- global $sFormErr; global $GAdmin_email; global $GEmails_subject; global $isSent; $sender_email = get_param("email"); $subject = get_param("subject"); $name = get_param("name"); $message = get_param("message"); if ($subject == "") $subject = $GEmails_subject; if(!strlen($name)) $sFormErr .= "The value in field Your Name is required.<br>"; if(!strlen($sender_email)) $sFormErr .= "The value in field Your Email is required.<br>"; if(strlen($sender_email) &&( !validEmail( $sender_email )) ) $sFormErr .= "The value in field Your Email is incorrect.<br>"; if(!strlen($message)) $sFormErr .= "The value in field Message is required.<br>"; if(strlen($sFormErr)) return; mail ($GAdmin_email, $name.": ".$subject, $message, "From:$sender_email"); $isSent = 1; } function Form_show() { global $tpl; global $sFormErr; global $isSent; if($isSent == 1) { $tpl->set_var("Form", ""); $tpl->parse("Sent", false); } else { $subject = get_param("subject"); $tpl->set_var("subject", tohtml($subject)); $tpl->set_var("Sent", ""); } if($sFormErr == "") { $tpl->set_var("FormError", ""); } else { $sender_email = get_param("email"); $subject = get_param("subject"); $message = get_param("message"); $name = get_param("name"); $tpl->set_var("email", tohtml($sender_email)); $tpl->set_var("name", tohtml($name)); $tpl->set_var("subject", tohtml($subject)); $tpl->set_var("message", tohtml($message)); $tpl->set_var("sFormErr", $sFormErr); $tpl->parse("FormError", false); } } ?> Link to comment https://forums.phpfreaks.com/topic/41894-contact-form-with-different-to-links/#findComment-203166 Share on other sites More sharing options...
nd4spdbh Posted March 9, 2007 Author Share Posted March 9, 2007 no one? Link to comment https://forums.phpfreaks.com/topic/41894-contact-form-with-different-to-links/#findComment-203646 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.