Skip to content

Instantly share code, notes, and snippets.

@mhayes mhayes/index.php
Created Apr 8, 2015

Embed
What would you like to do?
Send an e-mail with PHP
<?php
if(isset($_POST['email'])) {
$name = trim($_POST['name']);
$email = trim($_POST['email']);
$subject = trim($_POST['subject']);
$message = trim($_POST['message']);
if (preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i", $email)) {
$to = "me@example.com";
$email_subject = "Contact Form Submission | $name";
$email_body = "You have received a new message.\n\n".
"Name: $name \n".
"E-mail: $email\n\n".
"Message:\n".
"$message";
$headers = "From: $email\n";
$headers .= "Reply-To: $email";
mail($to,$email_subject,$email_body,$headers);
}
}
?>
@elmobp

This comment has been minimized.

Copy link

elmobp commented Nov 24, 2016

That's soooo open to spam be careful

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.