Skip to content

Instantly share code, notes, and snippets.

@mhayes
Created April 8, 2015 01:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mhayes/40e61782b7ce5077b617 to your computer and use it in GitHub Desktop.
Save mhayes/40e61782b7ce5077b617 to your computer and use it in GitHub Desktop.
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
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