Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- if(isset($_POST['email'])) {
- // EDIT THE 2 LINES BELOW AS REQUIRED
- $email_to = $_POST['email'];
- $email_subject = "Letter to Santa";
- function died($error) {
- // your error code can go here
- echo "We are very sorry, but there were error(s) found with the form you submitted. ";
- echo "These errors appear below.<br /><br />";
- echo $error."<br /><br />";
- echo "Please go back and fix these errors.<br /><br />";
- die();
- }
- // validation expected data exists
- if(!isset($_POST['name']) ||
- !isset($_POST['email']) ||
- !isset($_POST['message'])) {
- died('We are sorry, but there appears to be a problem with the form you submitted.');
- }
- $first_name = $_POST['name']; // required
- $email_from = $_POST['email']; // required
- $message = $_POST['message']; // required
- $error_message = "";
- $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
- if(!preg_match($email_exp,$email_from)) {
- $error_message .= 'The Email Address you entered does not appear to be valid.<br />';
- }
- $string_exp = "/^[A-Za-z .'-]+$/";
- if(!preg_match($string_exp,$first_name)) {
- $error_message .= 'The Name you entered does not appear to be valid.<br />';
- }
- if(strlen($message) < 2) {
- $error_message .= 'The Comments you entered do not appear to be valid.<br />';
- }
- if(strlen($error_message) > 0) {
- died($error_message);
- }
- function clean_string($string) {
- $bad = array("content-type","bcc:","to:","cc:","href");
- return str_replace($bad,"",$string);
- }
- $email_message .= "From: ".clean_string($first_name)."\n";
- $email_message .= "Dear Santa, ".clean_string($message)."\n";
- // create email headers
- $headers = 'From: '.$email_from."\r\n".
- 'Reply-To: '.$email_from."\r\n" .
- 'X-Mailer: PHP/' . phpversion();
- @mail($email_to, $email_subject, $email_message, $headers);
- ?>
- <!-- include your own success html here -->
- <html>
- <head>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Dear Santa,</title>
- <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-beta.2/css/bootstrap.min.css">
- <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Molle:400i">
- <link rel="stylesheet" href="assets/css/styles.css">
- </head>
- <body>
- <div class="container" style="text-align:center;">
- <div class="row">
- <div class="col-md-12 col-lg-10 offset-lg-1">
- <h1 style="color:rgb(255,255,255);margin:1em 0px 0px 0px;font-family:Molle, cursive;font-size:60px;">Your letter is on it's way to Santa, remember to be Nice and stay off that Naughty List!</h1>
- <a style="margin-bottom: 1em;" href="index.html">Back to Dear Santa</a>
- </br>
- </div>
- </div>
- </div>
- <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
- <script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-beta.2/js/bootstrap.min.js"></script>
- </body>
- </html>
- <?php
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment