首页 > 解决方案 > 电子邮件中的 PHP 表单输入

问题描述

我创建了一个将由用户输入的表单

<form id="wc-form-return" action="" method="post">
  <label><?php _e('Select products for return','wc_return') ?></label>
  <select id="wc_products[]" name="wc_products" class="wc_products" multiple="multiple">
    <?php
    if ( sizeof( $products ) > 0 ) { 
      foreach( $products as $item ) { ?>
        <option value="<?php echo $item['item_meta']['_product_id'][0]; ?>"><?php echo __(esc_html($item['name']), 'wc_return'); ?></option>
      <?php 
      }
    }
    ?>
  </select>
  <small><?php _e('You can select multiple by holding down the CMD or Ctrl key.','wc_return'); ?></small>
  <textarea name="wc_message" id="wc_message" cols="30" rows="10" placeholder="<?php _e('Explain the reasons for your return', 'wc_return') ?>"></textarea>
  <input type="hidden" name="order" value="<?php echo $order->id; ?>" />
  <input type="hidden" name="customer" value="<?php echo $order->billing_email; ?>" />
  <input type="text" name="phone" id="wc_phone" value="<?php echo $order->billing_phone; ?>" />
  <input type="checkbox" name="check1" value="Yes" required>Accept our <a href="https://sabkishop.in/return"> return and exchange policy </a> </br>
  <input type="submit" name="submit" value="<?php _e('Submit','wc_return'); ?>" />
</form>

它将由用户输入,我们将被发送到给定的电子邮件(已经设置)

现在在我使用的电子邮件中提供这些信息

$note_form_email = '';
    if ( $_POST['wc_message'] != '' ) {
      $note .= '<br><br>';
      $note .= '<p>'.__('And the explanation:', 'wc_return').'</p>';
      $note_form_email .= '<p>'.__('And the explanation:', 'wc_return').'</p>';
      $note .= apply_filters( 'the_content', $_POST['wc_message'] );
      $note_form_email .= apply_filters( 'the_content', $_POST['wc_message'] );
      $note .= '<p>'.__('Customer details:', 'wc_return').'</p>';
      $note_form_email .= '<p>'.__('Customer details:', 'wc_return').'</p>';
      $note .= '<p>'.__('Customer phone:','wc_return').'</p>';
      $note_form_email .= '<p>'.__('Customer phone:','wc_return').'</p>';
      $note .= apply_filters('the_content', $_POST['wc_phone'] );
      $note_form_email .= apply_filters('the_content', $_POST['wc_phone'] );
    }

但是输出是这样的

And the explanation:
Huhhh
Customer details:
Customer phone:

'Huhhh' 是用户在 wc_message 上写的。他还写了 wc_phone,但没有显示在电子邮件中。wc_message 工作正常,但 wc_phone 没有。我究竟做错了什么?

标签: phphtmlwordpressforms

解决方案


推荐阅读