Skip to content

Instantly share code, notes, and snippets.

@TANVIRFAZLEY
Forked from ShiponKarmakar/contact-form.php
Created July 14, 2017 01:57
Show Gist options
  • Save TANVIRFAZLEY/dcafa836548948096da2962760c8da4a to your computer and use it in GitHub Desktop.
Save TANVIRFAZLEY/dcafa836548948096da2962760c8da4a to your computer and use it in GitHub Desktop.
PHP Scripts
<?php
// Naming Constant
define( "RECIPIENT_NAME", "John Doe" );
define( "RECIPIENT_EMAIL", "[email protected]" );
// Values
$success = false;
$senderName = isset( $_POST['username'] ) ? preg_replace( "/[^\.\-\' a-zA-Z0-9]/", "", $_POST['username'] ) : "";
$senderEmail = isset( $_POST['email'] ) ? preg_replace( "/[^\.\-\_\@a-zA-Z0-9]/", "", $_POST['email'] ) : "";
$subject = isset( $_POST['subject'] ) ? preg_replace( "/[^\.\-\' a-zA-Z0-9]/", "", $_POST['subject'] ) : "";
$message = isset( $_POST['message'] ) ? preg_replace( "/(From:|To:|BCC:|CC:|Subject:|Content-Type:)/", "", $_POST['message'] ) : "";
// Send the email
if ( $senderName && $senderEmail && $message ) {
$recipient = RECIPIENT_NAME . " <" . RECIPIENT_EMAIL . ">";
$headers = "From: " . $senderName . " <" . $senderEmail . ">";
$success = mail( $recipient, $subject, $message, $headers );
//Set Location
header('Location: index.html');
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment