I'm attempting to develop a custom wordpress widget that's a message form. I've built the widget and all sorts of is okay except the send mail function, where it grabs the shape input posts and includes them because the email body.

This is actually the strange factor, after i go ahead and take actual mail functionality from the actual widget, and can include it within the sidebar prior to the icons the shape send the e-mail all right.

Im thinking maybe since a widget itself has some input fields itself, the mail form is searching for individuals posts inside the widget form.

This is actually the mail function:

<?php 


//If the form is submitted
if(isset($_POST['submitted'])) {

    //Check to see if the honeypot captcha field was filled in
    if(trim($_POST['checking']) !== '') {
        $captchaError = true;
    } else {

        //Check to make sure that the name field is not empty
        if(trim($_POST['contactName']) === '') {
            $nameError =  __('You forgot to enter your name.', 'medicalthemes'); 
            $hasError = true;
        } else {
            $name = trim($_POST['contactName']);

        }


        //Check to make sure sure that a valid email address is submitted
        if(trim($_POST['eemail']) === '')  {
            $eemailError = __('You forgot to enter your eemail address.', 'medicalthemes');
            $hasError = true;
        } else if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$", trim($_POST['eemail']))) {
            $eemailError = __('|');
            $hasError = true;
        } else {
            $eemail = trim($_POST['eemail']);
        }

        //Check to make sure that the name field is not empty
        if(trim($_POST['contactPhone']) === '') {
            $phoneError =  __('You forgot to enter your phone.', 'medicalthemes'); 
            $hasError = true;
        } else {
            $phone = trim($_POST['contactPhone']);
        }

        //Check to make sure comments were entered  
        if(trim($_POST['comments']) === '') {
            $commentError = __('You forgot to enter your comments.', 'medicalthemes');
            $hasError = true;
        } else {
            if(function_exists('stripslashes')) {
                $comments = stripslashes(trim($_POST['comments']));
            } else {
                $comments = trim($_POST['comments']);
            }
        }

        //If there is no error, send the email
        if(!isset($hasError)) {

            $eemailTo = get_option('med_contactform_email'); 
            $subject = __('Contact Form Submission from ').get_bloginfo('title');

            $body = __("Name: $name \n\nEmail: $eemail \n\nPhone: $phone \n\nComments: $comments", 'medicalthemes');
            $headers = __('From: ').get_bloginfo('title').' <'.$eemail.'>' . "\r\n" . __('Reply-To: ') . $eemail;

            mail($eemailTo, $subject, $body, $headers);

                   $eemailSent = true;

        }
    }
} ?>

Here is the whole widget code (without the above mail function):

  <?php
    /*---------------------------------------------------------------------------------*/
    /* Social Widget */
    /*---------------------------------------------------------------------------------*/

    class med_contact extends WP_Widget {

        function med_contact() {
            $widget_ops = array('description' => 'Add a contact form to your sidebar' );
            parent::WP_Widget(false, __('Contact Form', 'medicalthemes'),$widget_ops);      
        }

        function widget($args, $instance) {  


            $title = $instance['title'];


            echo '<div id="contact-form">';

if($title != ''){
            ?>

            <?php echo '<h2>'.$title.'</h2>'; ?>

     <script type="text/javascript">Form validation etc....</script>



                <?php if(isset($eemailSent) && $eemailSent == true) { ?>

                    <p class="info"><?php _e('Your eemail was successfully sent.', 'medicalthemes'); ?></p>

                <?php } else { ?>

 <?php if(isset($hasError) || isset($captchaError) ) { ?>
                            <p class="alert"><?php _e('There was an error submitting the form.', 'medicalthemes'); ?></p>
                        <?php } ?>

                        <form action="<?php the_permalink(); ?>" id="contactForm" method="post">
                            <ol class="forms">
                                <li>
                                    <input type="text" name="contactName" id="contactName" value="<?php if(isset($_POST['contactName'])) echo $_POST['contactName'];?>" class="txt requiredField name" /></li>

<li><input type="text" name="eemail" id="eemail" value="" class="txt requiredField eemail" /></li>


<li><input type="text" name="contactPhone" id="contactPhone" value="" class="txt requiredField phone" /></li>

<li class="textarea"><textarea name="comments" id="commentsText"  cols="30" class="txt requiredField message"></textarea></li>

                                <li class="screenReader"><label for="checking" class="screenReader"><?php _e('If you want to submit this form, do not enter anything in this field', 'medicalthemes') ?></label><input type="text" name="checking" id="checking" class="screenReader" value="<?php if(isset($_POST['checking']))  echo $_POST['checking'];?>" /></li>
                                <li class="buttons"><input type="hidden" name="submitted" id="submitted" value="true" /><input class="submit" type="submit" value="<?php _e('Submit', 'medicalthemes'); ?>" /></li>
                            </ol>
                        </form>


                <?php } ?>

              <!-- /#contact-page -->                

<?php  }

            echo '</div>';

        }

        function update($new_instance, $old_instance) {                
            return $new_instance;
        }

        function form($instance) {        
            $title = esc_attr($instance['title']);
            $emailadd = esc_attr($instance['emailadd']);

            ?>


            <p>
                <label for="<?php echo $this->get_field_id('title'); ?>">Title</label>
                <input type="text" name="<?php echo $this->get_field_name('title'); ?>" value="<?php echo $title; ?>" class="widefat" id="<?php echo $this->get_field_id('title'); ?>" />
            </p>

            <p>
                <label for="<?php echo $this->get_field_id('emailadd'); ?>">Your Email Address</label>
                <input type="text" name="<?php echo $this->get_field_name('emailadd'); ?>" value="<?php echo $emailadd; ?>" class="widefat" id="<?php echo $this->get_field_id('emailadd'); ?>" />
            </p>



            <?php
        }
    } 

    register_widget('med_contact');
    ?>

In order Ive stated, Once the top mail functionality code is incorporated withint he actual widget there is nothing sent. However, after i remove the mail functionality from the widget and can include it outdoors the widget the mail transmits fine.

Any help on this is greatly appreciated.