Php help

apps

#1

Hello there! I’m setting up a flash website using a pre-made template and it includes a contact form which utilizes PHP. I’m a fairly knowledgable web person (advanced beginner I’d guess you’d say) but PHP is mostly new to me. The template includes a file called “mail.php” and there’s two other PHP files in the mix of things. I’ve edited the mail.php file to include my information as follows:

<?php // dependencies $url = "http://www.harmlesscharles.com" ; $admin_notify_email = array( "to" => "ck@harmlesscharles.com", "to_name" => "charles2", "from" => "{EMAIL}", "from_name" => "{NAME}", "subject" => "You received a new contact message", "body" => <<<EOD

You have information request from Venice Shipyards SE

Name: {NAME}
Email: {EMAIL}
Attachment: {ATTACHMENT} Message
{MESSAGE}

EOD ); $autoresponder_email = array( "enable" => true, "to" => "{EMAIL}", "to_name" => "{NAME}", "from" => "ck@harmlesscharles.com", "from_name" => "charles2", "subject" => "Thank you for contacting us on Venice Shipyards SE - We send you the requested info. from you before 48 hours...", "body" => <<<EOD

Thank you for contacting us

on Venice Shipyards SE - We send you the requested info. from you before 48 hours... Name: {NAME}
Email: {EMAIL}
Message
{MESSAGE}

EOD ); require_once "lib/common.php"; require_once "lib/template.php"; if ($_SERVER["REQUEST_METHOD"] == "POST") { $vars = array( "name" => stripslashes($_POST["name"]), "email" => stripslashes($_POST["email"]), "subject" => stripslashes($_POST["subject"]), "message" => nl2br(stripslashes($_POST["message"])), ); //process the notify email $email = array( "email_to" => $admin_notify_email["to"], "email_to_name" => $admin_notify_email["to_name"], "email_from" => $admin_notify_email["from"], "email_from_name" => $admin_notify_email["from_name"], "email_subject" => $admin_notify_email["subject"], "email_body" => $admin_notify_email["body"], "email_type" => "html" ); foreach ($email as $key => $val) { $email[$key] = CTemplateStatic::Replace($val , $vars); } SendMail($email); //process the autoresponder email if ($autoresponder_email["enable"] == true) { $email = array( "email_to" => $autoresponder_email["to"], "email_to_name" => $autoresponder_email["to_name"], "email_from" => $autoresponder_email["from"], "email_from_name" => $autoresponder_email["from_name"], "email_subject" => $autoresponder_email["subject"], "email_body" => $autoresponder_email["body"], "email_type" => "html" ); foreach ($email as $key => $val) { $email[$key] = CTemplateStatic::Replace($val , $vars); } SendMail($email); } echo "success=true"; die(); } echo "success=false"; die(); ?>

There’s one file called “common.php”:


<?php // dependencies function SendMail() { $params = AStripSlasshes(func_get_args()); //check to see the numbers of the arguments switch (func_num_args()) { case 1: $email = $params[0]; $vars = array(); break; case 2: $email = $params[0]; $vars = $params[1]; break; case 3: $to = $params[0]; $email = $params[1]; $vars = $params[2]; break; case 4: $to = $params[0]; $to_name = $params[1]; $email = $params[2]; $vars = $params[3]; break; } if ($email["email_status"] == 1) { return true; } $msg = new CTemplate(stripslashes($email["email_body"]) , "string"); $msg = $msg->Replace($vars); $sub = new CTemplate(stripslashes($email["email_subject"]) , "string"); $sub = $sub->Replace($vars); $email["email_from"] = new CTemplate(stripslashes($email["email_from"]) , "string"); $email["email_from"] = $email["email_from"]->Replace($vars); $email["email_from_name"] = new CTemplate(stripslashes($email["email_from_name"]) , "string"); $email["email_from_name"] = $email["email_from_name"]->Replace($vars); if (!$email["email_reply"]) $email["email_reply"] = $email["email_from"]; if (!$email["email_reply_name"]) $email["email_reply_name"] = $email["email_from_name"]; //prepare the headers $headers = "MIME-Version: 1.0\r\n"; if ($email["email_type"] == "html") $headers .= "Content-type: text/html\r\n"; else $headers .= "Content-type: text/plain\r\n"; //prepare the from fields if (!$email["email_hide_from"]) { $headers .= "From: {$email[email_from_name]}<{$email[email_from]}>\r\n"; $headers .= "Reply-To: {$email[email_reply_name]}<{$email[email_reply]}>\r\n"; } $headers .= $email["headers"]; if (!$email["email_hide_to"]) { return mail($email["email_to"] , $sub, $msg,$headers); } else { } $headers .= "X-Mailer: PHP/" . phpversion(); return mail($to, $sub, $msg,$headers); } function AStripSlasshes($array) { if (is_array($array)) foreach ($array as $key => $item) if (is_array($item)) $array[$key] = AStripSlasshes($item); else $array[$key] = stripslashes($item); else return stripslashes($array); return $array; } ?>

And another file called “template.php”:


<?php // dependencies require_once _LIBPATH . "common.php"; require_once _LIBPATH . "xml.php"; //other templates dependencies require_once _LIBPATH . "template.layout.php"; require_once _LIBPATH . "template.static.php"; require_once _LIBPATH . "template.dynamic.php"; /** * template shared memory; the format of this variable is: * array ( * "BLOCK1" => array ( * "VAR1" => "val1", * "VAR2" => "val2" * ), * "BLOCK2" => array ( * "VAR1" => "val1", * "VAR2" => "val2" * ) * ) * so anything that goes into tsm should be like $_TSM["BLOCK"]["VAR"] = "value"; * except the require flags from the layout tpl assign which can be inserted directly. * do *not* trash the tsm. * * @var array * * @access public */ $_TSM = array(); class CTemplate { /** * template source data * * @var string * * @access private */ var $input; /** * template result data * * @var string * * @access public */ var $output; /** * template blocks if any * * @var array * * @access public */ var $blocks; /** * constructor which autoloads the template data * * @param string $source source identifier; can be a filename or a string var name etc * @param string $source_type source type identifier; currently file and string supported * * @return void * * @acces public */ function CTemplate($source,$source_type = "file") { $this->Load($source,$source_type); } /** * load a template from file. places the file content into input and output * also setup the blocks array if any found * * @param string $source source identifier; can be a filename or a string var name etc * @param string $source_type source type identifier; currently file and string supported * * @return void * * @acces public */ function Load($source,$source_type = "file") { switch ($source_type) { case "file": $this->template_file = $source; // get the data from the file $data = GetFileContents($source); //$data = str_Replace('$','\$',$data); break; case "rsl": case "string": $data = $source; break; } // blocks are in the form of data preg_match_all("'.*?'si",$data,$matches); // any blocks found? if (count($matches[0]) != 0) // iterate thru `em foreach ($matches[0] as $block) { // extract block name $name = substr($block,strpos($block,"S:") + 2,strpos($block,"-->") - 6); // cleanup block delimiters $block = substr($block,9 + strlen($name),strlen($block) - 18 - strlen($name) * 2); // insert into blocks array $this->blocks["$name"] = new CTemplate($block,"string"); } // cleanup block delimiters and set the input/output $this->input = $this->output = preg_replace(array("'(\r\n|\n|\n\r)'si","'(\r\n|\n|\n\r)'si"),"",$data); } /** * replace template variables w/ actual values * * @param array $vars array of vars to be replaced in the form of "VAR" => "val" * @param bool $clear reset vars after replacement? defaults to TRUE * * @return string the template output * * @acces public */ function Replace($vars,$clear = TRUE) { if (is_array($vars)) { foreach ($vars as $key => $var) { if (is_array($var)) { unset($vars[$key]); } } } // init some temp vars $patterns = array(); $replacements = array(); // build patterns and replacements if (is_array($vars)) // just a small check foreach ($vars as $key => $val) { $patterns[] = "/\{" . strtoupper($key) . "\}/"; //the $ bug $replacements[] = str_replace('$','\$',$val); } // do regex $result = $this->output = @preg_replace($patterns,$replacements,$this->input); // do we clear? if ($clear == TRUE) $this->Clear(); // return output return $result; } function SepReplace($ssep , $esep , $vars,$clear = TRUE) { if (is_array($vars)) { foreach ($vars as $key => $var) { if (is_array($var)) { unset($vars[$key]); } } } // init some temp vars $patterns = array(); $replacements = array(); // build patterns and replacements if (is_array($vars)) // just a small check foreach ($vars as $key => $val) { $patterns[] = $ssep . strtoupper($key) . $esep; //the $ bug $replacements[] = str_replace('$','\$',$val); } // do regex $result = $this->output = @preg_replace($patterns,$replacements,$this->input); // do we clear? if ($clear == TRUE) $this->Clear(); // return output return $result; } /** * replace a single template variable * * @param string $var variable to be replaced * @param string $value replacement * @param bool $perm makes the change permanent [i.e. replaces input also]; defaults to FALSE * * @return string result of replacement * * @acces public */ function ReplaceSingle($var,$value,$perm = FALSE) { if ($perm) $this->input = $this->Replace(array("$var" => $value)); else return $this->Replace(array("$var" => $value)); } /** * resets all the replaced vars to their previous status * * @return void * * @acces public */ function Clear() { $this->output = $this->input; } /** * voids every template variable * * @return void * * @acces public */ function EmptyVars() { global $_TSM; //$this->output = $this->ReplacE($_TSM["_PERM"]); //return$this->output = preg_replace("'{[A-Z]}'si","",$this->output); return $this->output = preg_replace("'{[A-Z_\-0-9]*?}'si","",$this->output); //return $this->output = preg_replace("'{[\/\!]*?[^{}]*?}'si","",$this->output); } /** * checks if the specified template block exists * * @param string $block_name block name to look for * * @return bool TRUE if exists or FALSE if it doesnt * * @access public */ function BlockExists($block_name) { return isset($this->blocks[$block_name]) && is_object($this->blocks[$block_name])? TRUE : FALSE; } /* function Block($block,$vars = array(),$return_error = false) { if ($this->BlockExists($block)) return $this->blocks[$block]->Replace($vars); else { return ""; } } */ /*Extra functions to keep the compatibility with the new CTemplateDynamic library*/ /** * description * * @param * * @return * * @access */ function BlockReplace($block , $vars = array(), $clear = true){ if (!is_object($this->blocks[$block])) echo "CTemplate::{$this->template_file}::$block Doesnt exists.
"; return $this->blocks[$block]->Replace($vars , $clear); } /** * description * * @param * * @return * * @access */ function BlockEmptyVars($block , $vars = array(), $clear = true) { if (!is_object($this->blocks[$block])) echo "CTemplate::{$this->template_file}::$block Doesnt exists.
"; if (is_array($vars) && count($vars)) $this->blocks[$block]->Replace($vars , false); return $this->blocks[$block]->EmptyVars(); } /** * description * * @param * * @return * * @access */ function Block($block) { if (!is_object($this->blocks[$block])) echo "CTemplate::{$this->template_file}::$block Doesnt exists.
"; return $this->blocks[$block]->output; } } /** * description * * @library * @author * @since */ class CTemplateStatic{ /** * description * * @param * * @return * * @access */ /** * description * * @param * * @return * * @access */ function Replace($tmp , $data = array()) { $template = new CTemplate($tmp , "string"); return $template->replace($data); } function EmptyVars($tmp , $data = array()) { $template = new CTemplate($tmp , "string"); if (count($data)) { $template->replace($data , false); } return $template->emptyvars(); } /** * description * * @param * * @return * * @access */ function ReplaceSingle($tmp , $var , $value) { return CTemplateStatic::Replace( $tmp , array( $var => $value ) ); } } ?>

I cannot seem to get a message to send to my e-mail. It keeps telling me “Message was not sent” whenever I fill out the information boxes and press the send button. I appreciate the help!

Charles