array( "description" => "{The text that will show as the label to the field}", "type" => "{checkbox|text|textarea|submit|hidden|password}", "vital" => {true|false} // Is this field compulsory. ); */ $this->contact_form_fields = array( 'icit_persoanl_para' => array('description' => 'Your contact information', 'type' => 'paragraph'), 'icit_name' => array('description' => 'Name', 'type' => 'text', 'vital' => true), 'icit_email' => array('description' => 'Email address', 'type' => 'text', 'vital' => true, 'validate' => 'email'), 'icit_text' => array('description' => 'Your message', 'type' => 'textarea'), 'icit_submit_3' => array('description' => 'Send', 'type' => 'submit') ); $to = get_post_meta($post->ID,"to",true); $to = explode ("\n",$to); // If there is more than one line we'll just take the first. In future I plan to make this to you can have multiple address lines, just not now. $to = $to[0]; if ($to != "") { //If the post meta data TO is set then we'll try and not use the admin email. Otherwise we have to. if ($this->valid_email($to)) { // If to is set to an email address lets split the name off the start and set email to address. $name = spliti("@",$to); $this->recipient = array('email' => $to, 'name' => $name[0]); } elseif(is_numeric($to)) { // If it's a number we'll presume it's a user ID and get the info from the user profile. If the user ID returns nothing use the admin email. $user = get_userdata($to); if ($user) { $this->recipient = array('email' => $user->user_email, 'name' => $user->display_name); } else { $this->recipient = array("email" => get_bloginfo("admin_email"), "name" => "Site owner"); } } } else { $this->recipient = array("email" => get_bloginfo("admin_email"), "name" => "Site owner"); } if (!$_POST['submitted']) { $this->html(); } else { // Check data for errors and setup local copy of the post variable unset($_POST['submit']); unset($this->postresults); unset($this->errors); foreach ($_POST as $key => $post_var) { if (!empty($post_var)) $this->postresults[$key] = stripslashes($post_var); if ($this->contact_form_fields[$key]['vital'] && empty($this->postresults[$key])) $this->errors[$key] = true; if ($this->contact_form_fields[$key]['validate'] == 'email' && !$this->valid_email($this->postresults[$key])) $this->errors[$key] = true; } // Send the message an regenerate the HTML using the return value to generate a message or two. $this->html($this->send()); } } function send() { if (count($this->errors) == 0) { // Format the conent of the mail. $email_subject = "[".get_bloginfo('name')."] Message sent from website."; $email_headers = ""; if (!empty($this->contact_form_fields['icit_email'])) $email_headers .= "Reply-To:".$this->postresults['icit_email']."\n"; $email_headers .= "From: ".get_bloginfo('name')." <".get_settings('admin_email').">\n"; $email_headers .= "MIME-Version: 1.0\n"; $email_headers .= "Content-Type: text/plain; charset=".get_option('blog_charset')."; format=flowed \n"; $email_content = "The following information was submitted to '".get_bloginfo('name')."' website on ".date('l dS \of F Y h:i:s A')."\n"; $email_content .= "This mail originated from page ".$_SERVER["HTTP_REFERER"]." and the sender had the following ip address ".$_SERVER["REMOTE_ADDR"]."\n\n"; foreach (array_keys($this->contact_form_fields) as $key) { if ($this->postresults[$key] != '' && !in_array(strtolower($this->contact_form_fields[$key]['type']), array('checkbox', 'radio'))) { $email_content .= $this->contact_form_fields[$key]['description'].":\n\t".$this->postresults[$key]."\n\n"; } elseif (in_array(strtolower($this->contact_form_fields[$key]['type']), array('checkbox', 'radio')) && $this->postresults[$key] == 'on') { $email_content .= $this->contact_form_fields[$key]['description']." = Yes\n"; } } // Send the mail and return. if (@wp_mail($this->recipient['email'],$email_subject,$email_content,$email_headers )) { return(true); } else { $this->errors['mail_server_problem'] = "There were problems with the mail server.\n We will try and fix the problem as soon as we can."; return(false); } } else { return(false); } } function valid_email($email) { return (eregi ("^([a-z0-9_]|\\-|\\.)+@(([a-z0-9_]|\\-)+\\.)+[a-z]{2,4}$", $email)); } function html($success = null) { if ($success) { ?>

Message sent successfully

Thank you,
Someone will get back to you as soon as they can.

errors['mail_server_problem'] == '') { ?>

Oops.

Please check any field that is marked in red and try again.

errors['mail_server_problem'] == '') { ?> errors['mail_server_problem']; }?>
contact_form_fields) as $key) { // Assemble the html based on the content of the array.?>
contact_form_fields[$key]['description'] && in_array(strtolower($this->contact_form_fields[$key]['type']),array('checkbox', 'hidden', 'password', 'radio', 'text','textarea'))) { ?>contact_form_fields[$key]['type'] == 'paragraph') { echo '

'.$this->contact_form_fields[$key]['description'].'

'; } elseif ($this->contact_form_fields[$key]['type'] == 'submit') {?> contact_form_fields[$key]['type']), array('checkbox', 'hidden', 'password', 'radio', 'text')) ) { ?>postresults[$key] && in_array(strtolower($this->contact_form_fields[$key]['type']), array('hidden', 'password', 'text'))) { echo 'value="'.$this->postresults[$key].'" '; } elseif (!empty($this->postresults[$key]) && in_array(strtolower($this->contact_form_fields[$key]['type']), array('checkbox', 'radio'))) { echo 'checked="checked" '; } if ($this->errors[$key] == true) echo 'style="border-color: red;" '; ?> />contact_form_fields[$key]['type']) == 'textarea') { ?>