<?php
ob_start();
// if the submit button is clicked, send the email
if ( isset( $_POST['abs-submitted'] ) ) {
// sanitize form values
$name = sanitize_text_field( $_POST["abs-name"] );
$email = sanitize_email( $_POST["abs-email"] );
$subject = get_the_title();
$message = esc_textarea( $_POST["abs-message"] );
//Sent meil by WordPess 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, $subject, $message, $headers ) ) {
echo '<div>';
echo '<p>Thanks for contacting me, expect a response soon.</p>';
echo '</div>';
} else {
echo 'An unexpected error occurred';
}
}
/**
* Output form
*/
echo '<form action="' . esc_url( $_SERVER['REQUEST_URI'] ) . '" method="post">';
echo '<p>';
echo 'Your Name (required) <br />';
echo '<input type="text" name="abs-name" pattern="[a-zA-Z0-9 ]+" value="' . ( isset( $_POST["abs-name"] ) ? esc_attr( $_POST["abs-name"] ) : '' ) . '" size="40" />';
echo '</p>';
echo '<p>';
echo 'Your Email (required) <br />';
echo '<input type="email" name="abs-email" value="' . ( isset( $_POST["abs-email"] ) ? esc_attr( $_POST["abs-email"] ) : '' ) . '" size="40" />';
echo '</p>';
echo '<p>';
echo 'Subject <br />';
echo '<p>'.get_the_title().'</p>';
echo '</p>';
echo '<p>';
echo 'Your Message (required) <br />';
echo '<textarea rows="10" cols="35" name="abs-message">' . ( isset( $_POST["abs-message"] ) ? esc_attr( $_POST["abs-message"] ) : '' ) . '</textarea>';
echo '</p>';
echo '<p><input type="submit" name="abs-submitted" value="Send"/></p>';
echo '</form>';
// Object get clean
return ob_get_clean();
?>
For guideline follow comment inside snippet
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.