PHP表单字段已填充,但在电子邮件中收到空字段

PHP表单字段已填充,但在电子邮件中收到空字段,php,forms,email,Php,Forms,Email,我有一个php文件,它将表单的字段发送到电子邮件地址。但是,有些字段是空的。以下是电子邮件的一个示例: “我的名字是:D 我的名字是:卡米尔 我的电子邮件是:dollec@xxx.fr 我的电话号码是:0xxxxxxx6 我的职业是: 我的员工是: 我的位置是: 我的评论:bbb“ 下面是PHP代码: $nameError = ''; $firstnameError = ''; $emailError = ''; $commentError = '';

我有一个php文件,它将表单的字段发送到电子邮件地址。但是,有些字段是空的。以下是电子邮件的一个示例:

“我的名字是:D

我的名字是:卡米尔

我的电子邮件是:dollec@xxx.fr

我的电话号码是:0xxxxxxx6

我的职业是:

我的员工是:

我的位置是:

我的评论:bbb“

下面是PHP代码:

    $nameError = '';
    $firstnameError = '';
    $emailError = ''; 
    $commentError  = '';
    $professionError = '';
    $employeurError = '';
    $lieuError = '';
    //If the form is submitted
    if($cap_val == 1) {
    $name = trim($_POST['contactName']);
    $firstname = trim($_POST['contactFirstname']);
    $email = trim($_POST['email']);
    $phone = trim($_POST['phone']);
    $profession = trim($POST['profession']);
    $employeur = trim($POST['employeur']);
    $lieu = trim($POST['lieu']);
    $comments = trim($_POST['comments']);
    if(!isset($hasError)) {
        $emailTo = ot_get_option('wpl_contact_form_email');
        if (!isset($emailTo) || ($emailTo == '') ){
            $emailTo = get_option('admin_email');
        }
        $subject = 'New message From '.$name.' '.$firstname;
        $body = "My name is: $name \n\nMy firstname is: $firstname \n\nMy Email is: $email \n\nMy phone number is: $phone \n\nMy profession is: $profession \n\nMy employee is: $employeur \n\nMy location is: $lieu \n\nMy comments: $comments";
        $headers = 'From: '.$name.' '.$firstname.' <'.$email.'>' . "\r\n" . 'Reply-To: ' . $email;

        mail($emailTo, $subject, $body, $headers);
        $emailSent = true;
    }
}
    //end form
    ?>
    <div class="item teaser-page-list">
        <div class="container_16">
            <aside class="grid_10">
                <h1 class="page-title"><?php the_title(); ?></h1>
            </aside>
            <?php if ( ot_get_option('wpl_breadcrumbs') != "off") { ?>
                <div class="grid_6">
                    <div id="rootline">
                        <?php wplook_breadcrumbs(); ?>  
                    </div>
                </div>
            <?php } ?>
            <div class="clear"></div>
        </div>
    </div>

    <div id="main" class="site-main container_16">
        <div class="inner">
            <div id="primary" class="grid_11 suffix_1">

            <?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
                    <?php the_content(); ?>
                <?php endwhile; // end of the loop. ?>

                <?php if(isset($emailSent) && $emailSent == true) { ?>
                    <div class="alert green">
                        <?php _e( 'Thanks, your email was sent successfully.', 'wplook' ); ?>
                    </div>
                <?php } else { ?>
                    <?php if(isset($hasError) ) { ?>
                        <p class="error"><?php _e( 'Sorry, an error occured.', 'wplook' ); ?><p>
                    <?php } ?>
                    <form action="<?php the_permalink(); ?>" id="contact-form" method="post">
                        <p>
                            <label for="contactName"></label>
                            <input  type="text" name="contactName" value="<?php if(isset($_POST['contactName'])) echo $_POST['contactName'];?>" placeholder="<?php _e( 'Votre nom*', 'wplook' );  ?>" required/>
                        </p>
                        <p>
                            <label for="contactFirstname"></label>
                            <input  type="text" name="contactFirstname" value="<?php if(isset($_POST['contactFirstname'])) echo $_POST['contactFirstname'];?>" placeholder="<?php _e( 'Votre prénom*', 'wplook' );  ?>" required/>
                        </p>
                        <p>
                        <label for="email"></label>
                        <input  type="email" name="email" value="<?php if(isset($_POST['email']))  echo $_POST['email'];?>" placeholder="<?php _e( 'Your Email Adress*', 'wplook' ); ?>" required/>

                        </p>
                        <p>
                            <label for="phone"></label>
                            <input type="tel" name="phone" value="<?php if(isset($_POST['phone']))  echo $_POST['phone'];?>" placeholder="<?php _e( 'Votre téléphone*', 'wplook' ); ?>" required/>
                        </p>
                        <p>
                        <label for="profession"></label>
                        <input type="text" name="profession" value="<?php if(isset($_POST['profession']))  echo $_POST['profession'];?>" placeholder="<?php _e( 'Votre profession*', 'wplook' ); ?>" required/>
                        </p>
                        <p>
                        <label for="employeur"></label>
                        <input type="text" name="employeur" value="<?php if(isset($_POST['employeur']))  echo $_POST['employeur'];?>" placeholder="<?php _e( 'Votre employeur*', 'wplook' ); ?>" required/>

                        </p>
                        <p>
                        <label for="lieu"></label>
                        <input type="text" name="lieu" value="<?php if(isset($_POST['lieu']))  echo $_POST['lieu'];?>" placeholder="<?php _e( 'Votre lieu d\'activité ou de résidence*', 'wplook' ); ?>" required/>

                        </p>
                        <p>
                            <label for="commentsText"></label>
                            <textarea class="contactme-text required requiredField" name="comments" cols="20" rows="10" placeholder="<?php _e( 'Your message goes here', 'wplook' ); ?>" required="required"><?php if(isset($_POST['comments'])) { if(function_exists('stripslashes')) { echo stripslashes($_POST['comments']); } else { echo $_POST['comments']; } } ?></textarea>
                            <?php $commentError=''; if($commentError != '') { ?>
                                <div class="alert red"><?php $commentError;?></div>
                            <?php } ?>
                        </p>


                        <?php //recapcha failed message 
                            if (isset($_POST['submitted']) ){
                                if (!$resp->is_valid) { ?>
                                    <div class="alert red">
                                        <?php echo _e( 'The security code you entered in wrong. Please retype the security code!', 'wplook' ); ?>
                                    </div>
                                <?php }
                            }
                        ?>

                        </p>
                        <p>

                            <script type="text/javascript">
                                var RecaptchaOptions = { theme : 'clean' };
                            </script><!-- recapcha theme -->

                            <?php //recapcha code
                                if ( $publickey  && $privatekey ) {
                                    require_once(get_template_directory().'/inc/recaptchalib.php');
                                    $publickey = ot_get_option('wpl_recaptcha_publickey');
                                    echo recaptcha_get_html($publickey);
                                } else {
                                    echo "<div class='alert red'>";
                                    echo _e( 'To use reCAPTCHA you must get an API key from:', 'wplook' );
                                    echo " <a href='https://www.google.com/recaptcha/admin/create'>https://www.google.com/recaptcha/admin/create</a>";
                                    echo "</div>";
                                }
                            ?>

                        </p>
                        <div class="form-submit">
                            <input id="submit" class="sendemail" value="<?php _e( 'Send', 'wplook' ); ?>" type="submit"></input >
                            <input type="hidden" name="submitted" id="submitted" value="true" />
                        </div>
                    </form>
                <?php } ?>
$namererror='';
$firstnameError='';
$emailError='';
$commentError='';
$professionError='';
$employeurError='';
$lieuError='';
//如果提交了表格
如果($cap_val==1){
$name=trim($_POST['contactName']);
$firstname=trim($_POST['contactFirstname']);
$email=trim($_POST['email']);
$phone=trim($_POST['phone']);
$profession=trim($POST['profession']);
$employeur=trim($POST['employeur']);
$LIUE=修剪($POST['LIUE']);
$comments=trim($_POST['comments']);
如果(!isset($hasError)){
$emailTo=ot_get_选项(“wpl_联系人_表格_电子邮件”);
如果(!isset($emailTo)| |($emailTo==''){
$emailTo=get_选项('admin_email');
}
$subject='newmessagefrom'.$name.'.$firstname;
$body=“我的名字是:$name\n\n我的名字是:$firstname\n\n我的电子邮件是:$Email\n\n我的电话号码是:$phone\n\n我的职业是:$profession\n\n我的员工是:$employeeur\n\n我的位置是:$liue\n\n我的评论:$comments”;
$headers='发件人:'.$name.'.$firstname.'.'.“\r\n.''回复:'.$email;
邮件($emailTo、$subject、$body、$headers);
$emailSent=true;
}
}
//结束形式
?>
";
回声“;
}
?>


缺少下划线字符:

更改它:

$profession = trim($POST['profession']);
$employeur = trim($POST['employeur']);
$lieu = trim($POST['lieu']);
致:


享受你的代码吧!

这种情况会发生。别担心。@blondie你能在我的回复中设置ok复选框吗?谢谢:)
$profession = trim($_POST['profession']);
$employeur = trim($_POST['employeur']);
$lieu = trim($_POST['lieu']);