表单未发送所有字段数据

Form not sending all the field data

所以我借用并修改了一个电子邮件表单插件,我添加了模式成功并更改了一些字段名称,呼应了一些html等。我是php的新手但是基本上它不发送完整的表格,它只发送输入的电子邮件,不发送任何其他内容,如姓名、电话等。这可能是愚蠢的,但我正在拔头发试图解决它。

见下文php:

<?php
/*
Plugin Name: Example Contact Form Plugin
Plugin URI: http://example.com
Description: Simple non-bloated WordPress Contact Form
Version: 1.0
Author: Agbonghama Collins
Author URI: http://w3guy.com
*/
function html_form_code() {
 echo '<div class="frame">';
 echo '<div class="box-1">';
 echo '<div class="box">';
 echo '<h2 class="appointment-h2">My Rates</h2>';
 echo '<p class="news-section p">&pound;50 per 50 minute session.</br>I offer either a free initial 30 minute phone consultation or charge &pound;25 for a face to face initial 30 minute consultation.</br>I also offer concession rates for those on a low income.</p>';
 echo '<h2 class="appointment-h2">Request an appointment. I will contact you to discuss a convienient time for us to meet.</h2>';
    echo '<form action="' . esc_url( $_SERVER['REQUEST_URI'] ) . '" method="post" class="appointment-form">';
    echo '<label>First Name (required) <br/></label>';
    echo '<input type="text" class="pill required" name="cf-firstname" pattern="[a-zA-Z0-9 ]+" value="' . ( isset( $_POST["cf-firstname"] ) ? esc_attr( $_POST["cf-firstname"] ) : '' ) . '" size="40" placeholder="First name" />';
    echo '<label>Last Name (required) <br/></label>';
    echo '<input type="text" class="pill required" name="cf-lastname" pattern="[a-zA-Z0-9 ]+" value="' . ( isset( $_POST["cf-lastname"] ) ? esc_attr( $_POST["cf-lastname"] ) : '' ) . '" size="40" placeholder="Last name" />';
    echo '</br></br>';
    echo '<label>Your Email (required) <br/></label>';
    echo '<input type="email" class="pill required" name="cf-email" value="' . ( isset( $_POST["cf-email"] ) ? esc_attr( $_POST["cf-email"] ) : '' ) . '" size="40" placeholder="Email" />';
    echo '<label>Telephone (required) <br/></label>';
    echo '<input type="text" class="pill" name="cf-telephone" value="' . ( isset( $_POST["cf-telephone"] ) ? esc_attr( $_POST["cf-telephone"] ) : '' ) . '" size="40" placeholder="Telephone" />';
    echo '</br></br>';
    echo '<p><input type="submit" class="pill appointment-btn submit" name="cf-submitted" value="Send"></p>';
    echo '</form>';
 echo '</div>';
 echo '</div>';
 echo '</div>';
}
 
function deliver_mail() {
 
    // if the submit button is clicked, send the email
    if ( isset( $_POST['cf-submitted'] ) ) {
 
        // sanitize form values
        $name    = sanitize_text_field( $_POST["cf-name"] );
  $lastname  = sanitize_text_field( $_POST["cf-lastname"] );
        $email   = sanitize_email( $_POST["cf-email"] );
        $telephone = sanitize_text_field( $_POST["cf-telephone"] );
 
        // get the blog administrator's email address
        $to = get_option( 'admin_email' );
 
        $headers = "From: $name <$email>" . "\r\n";
 
        // If email has been process for sending, display a success message
        if ( wp_mail( $to, $name, $lastname, $email, $telephone ) ) {
         echo '<div class="modal-overlay"></div>';
            echo '<div class="modal" id="modal-one" aria-hidden="true">';
   echo '<div class="modal-dialog">';
   echo '<div class="modal-header">';
   echo '<h2>Appointment request sent succsefully</h2>';
   echo '</div>';
   echo '<div class="modal-body">';
   echo '<p>I will be in touch in due course, thank you, Jo.</p>';
   echo '<div class="modal-footer">';
   echo '<a href="#/" class="btn close-modal">Close</a>';
            echo '</div></div></div>';
            echo '</div>';
    
    
        } else {
            echo '<div>';
            echo '<p>There were errors in the form, please try again</p>';
            echo '</div>';
        }
    }
}
 
function cf_shortcode() {
    ob_start();
    deliver_mail();
    html_form_code();
 
    return ob_get_clean();
}
 
add_shortcode( 'sitepoint_contact_form', 'cf_shortcode' );
 
?>

您使用的 wp_mail 错误。

您需要将 phone 和其他变量放在一个变量中,如下所示:

$message = " Name: $name <br>
             Lastname:  $lastname<br>
             Telephone: $telephone <br>
             Email: $email   ";

$subject = "Contact from my site";

然后使用这个:

wp_mail( $to, $subject, $message)