Last active
October 20, 2015 08:21
-
-
Save ganmahmud/fabe0821a230409f39b2 to your computer and use it in GitHub Desktop.
PHP Email Script
This file contains 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 | |
$name = @trim(stripslashes($_POST['name'])); | |
$email = @trim(stripslashes($_POST['email'])); | |
$msg = @trim(stripslashes($_POST['msg'])); | |
$subject = 'PHP-AJAX Email' ; //type your email subject here | |
$to = 'you@your-email.com';//replace with your email | |
$headers = array(); | |
$headers[] = "MIME-Version: 1.0"; | |
$headers[] = "Content-type: text/plain; charset=iso-8859-1"; | |
$headers[] = "Subject: {$subject}"; | |
$headers[] = "X-Mailer: PHP/".phpversion(); | |
// Build the email content. | |
$email_content = "Name: $name\n"; | |
$email_content .= "Email: $email\n"; | |
$email_content .= "Message:$msg\n"; | |
if ( empty($name) OR empty($msg) OR !filter_var($email, FILTER_VALIDATE_EMAIL)) { | |
// Set a 400 (bad request) response code and exit. | |
http_response_code(400); | |
exit; | |
} | |
else{ | |
mail($to, $subject, $email_content, implode("\r\n", $headers)); | |
} | |
die; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment