Created
April 5, 2018 13:45
-
-
Save dcangulo/59b6bbee2eb36b7dc4b46d7119664a45 to your computer and use it in GitHub Desktop.
A simple contact form WordPress plugin. Visit https://www.davidangulo.xyz/ for more information.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /* | |
| Plugin Name: Simple Contact Form | |
| Plugin URI: https://www.davidangulo.xyz/portfolio/ | |
| Description: A very simple contact form. | |
| Version: 1.0.0 | |
| Author: David Angulo | |
| Author URI: https://www.davidangulo.xyz/ | |
| License: GPL2 | |
| */ | |
| add_shortcode("simple_contact_form","myContactFormRender"); | |
| function myContactFormRender() { | |
| ob_start(); | |
| myContactForm(); | |
| return ob_get_clean(); | |
| } | |
| function myContactForm() { | |
| if(isset($_POST["scf-submit"])) { | |
| $name = $_POST["scf-name"]; | |
| $email = $_POST["scf-email"]; | |
| $subject = $_POST["scf-subject"]; | |
| $message = $_POST["scf-message"]; | |
| $to = get_option("admin_email"); | |
| $headers = "From: $name <$email>" . "\r\n"; | |
| if(wp_mail($to,$subject,$message,$headers)) { | |
| echo "<script>Your message has been sent successfully.</script>"; | |
| } | |
| else { | |
| echo "<script>An error has occured. </script>"; | |
| } | |
| } | |
| ?> | |
| <style> | |
| .form-control { | |
| width: 100%; | |
| margin-bottom: 20px; | |
| } | |
| .pull-right { | |
| float: right; | |
| } | |
| </style> | |
| <form action="<?php echo esc_url($_SERVER['REQUEST_URI']);?>" method="post"> | |
| <label for="scf-name">Name:</label><input type="text" class="form-control" id="scf-name" name="scf-name" required> | |
| <label for="scf-email">Email Address:</label><input type="email" class="form-control" id="csf-email" name="scf-email" required> | |
| <label for="scf-subject">Subject:</label><input type="text" class="form-control" id="scf-subject" name="scf-subject" required> | |
| <label for="scf-message">Message:</label><textarea class="form-control" id="scf-message" name="scf-message" rows="5" required></textarea> | |
| <button class="pull-right" type="submit" id="scf-submit" name="scf-submit">Send</button> | |
| </form> | |
| <?php | |
| } | |
| //Visit the tutorial for more information | |
| //https://www.davidangulo.xyz/website-development/how-to-create-a-contact-form-plugin-in-wordpress/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment