so I have borrowed and modded an email form plugin, I have added modal success and changed a few field names, echoed out some html etc. I'm a novice with php but basically it is not sending the complete form, it sends only the email inputted and nothing else such as name, telephone etc. It's probably something stupid but im pulling my hair out trying to fiqure it out.
See the below 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">£50 per 50 minute session.</br>I offer either a free initial 30 minute phone consultation or charge £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' );
?>
You are using wp_mail wrong.
You need to put phone and other variables within a single variable, like this:
$message = " Name: $name <br>
Lastname: $lastname<br>
Telephone: $telephone <br>
Email: $email ";
$subject = "Contact from my site";
And then use this:
wp_mail( $to, $subject, $message)