Created
August 31, 2014 20:55
-
-
Save jonmunson/fc8ff9bd4472da7852de to your computer and use it in GitHub Desktop.
Send email from server
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 | |
// Use this when posting a form via ajax | |
// - this file should be above the webroot | |
//Retrieve form data. | |
//GET - user submitted data using AJAX | |
//POST - in case user does not support javascript, we'll use POST instead | |
$name = ($_GET['name']) ? $_GET['name'] : $_POST['name']; | |
$email = ($_GET['email']) ?$_GET['email'] : $_POST['email']; | |
$messsage = ($_GET['message']) ?$_GET['message'] : $_POST['message']; | |
//define the receiver of the email | |
$to = 'admin@domain.com'; | |
//define the subject of the email | |
$subject = 'Contact form from domain.com'; | |
//define the message to be sent. Each line should be separated with \n | |
$message = ' | |
Name: ' . $name . ' | |
Email: ' . $email . ' | |
Message: ' . $messsage . ' | |
'; | |
$headers = 'From: webmaster@domain.com' . "\r\n" . | |
'Reply-To: webmaster@domain.com' . "\r\n" . | |
'X-Mailer: PHP/' . phpversion(); | |
//send the email | |
$mail_sent = @mail( $to, $subject, $message, $headers ); | |
//if the message is sent successfully print "Mail sent". Otherwise print "Mail failed" | |
echo $mail_sent ? "Mail sent" : "Mail failed"; | |
?> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment