Created
September 18, 2015 15:17
-
-
Save jkuip/d118cde4a7f93712ab29 to your computer and use it in GitHub Desktop.
Simple PHP email
This file contains hidden or 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Email</title> | |
<meta charset="utf-8"> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"> | |
</head> | |
<body> | |
<div class="container" style="margin-top: 50px"> | |
<?php | |
// Suppress PHP error notices | |
error_reporting(E_ALL & ~E_NOTICE); | |
// If the submit button has been pressed | |
if(isset($_POST['submit'])) | |
{ | |
// Empty error array | |
$error = array(); | |
// Check for an e-mail address | |
if(empty($_POST['email'])) | |
{ | |
$error['email'] = 'An email address is required'; | |
} | |
// Check for a message | |
if(empty($_POST['message'])) | |
{ | |
$error['message'] = 'A message is required'; | |
} | |
// If there are no errors, send the email | |
// If there are errors, display them to the user | |
if(sizeof($error) == 0) | |
{ | |
// Send the message (to, subject, message, from) | |
mail($_POST['email'], 'Default subject', stripslashes($_POST['message']), "From: {$_POST['email']}"); | |
// Create confirmation message | |
echo "<div class=\"alert alert-success\">Your e-mail has been sent!</div>"; | |
} | |
} | |
?> | |
<!-- email Form --> | |
<form method="post" action="email.php"> | |
<div class="form-group"> | |
<label for="email">Your e-mail address:</label> | |
<input name="email" type="text" value="<?php echo $_POST['email']; ?>" class="form-control" /> | |
<span class="text-danger"><?php echo $error['email']; ?></span> | |
</div> | |
<div class="form-group"> | |
<label for="message">Message:</label> | |
<textarea name="message" rows="8" class="form-control"><?php echo $_POST['message']; ?></textarea> | |
<span class="text-danger"><?php echo $error['message']; ?></span> | |
</div> | |
<input name="submit" type="submit" value="Send Message" class="btn btn-primary" /> | |
</form> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment