Skip to content

Instantly share code, notes, and snippets.

@ShiponKarmakar
Last active November 1, 2024 17:56
Show Gist options
  • Save ShiponKarmakar/c344e6889858870bf4ee03f91c8cc7cf to your computer and use it in GitHub Desktop.
Save ShiponKarmakar/c344e6889858870bf4ee03f91c8cc7cf 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