comparison submit_comment.php @ 35:a30aee3f6158

simple form handler for submitting a comment. This script just forwards the comment via eMail.
author Dirk Olmes <dirk@xanthippe.ping.de>
date Mon, 01 Sep 2014 04:15:01 +0200
parents
children cf31bf5fce72
comparison
equal deleted inserted replaced
34:822bec7ea32d 35:a30aee3f6158
1 <?php
2 function get_slug()
3 {
4 $slug = htmlspecialchars($_POST['Slug']);
5 if (empty($slug))
6 {
7 die('POST request did not include value for required key "Slug"');
8 }
9 return $slug;
10 }
11
12 if ($_SERVER['REQUEST_METHOD'] == 'POST')
13 {
14 $recipient = 'blog@xanthippe.ping.de';
15 $slug = get_slug();
16
17 $author = htmlspecialchars($_POST['Author']);
18 $comment = htmlspecialchars($_POST['Comment']);
19 $date = date('Y-m-d H:i:s');
20
21 $message = 'Author: ' . $author . PHP_EOL
22 . 'Date: ' . $date . PHP_EOL . PHP_EOL
23 . $comment;
24
25 $subject = 'New blog post comment on article ' . $slug;
26 mail($recipient, $subject, $message);
27
28 ?>
29
30 <html>
31 <head>
32 <title>Your comment was posted</title>
33 </head>
34 <body>
35 <h1>Thank you</h1>
36 <p>
37 Your comment was posted and will appear on the blog as soon as a moderator has reviewed it.
38 </p>
39 <a href="http://xanthippe.duckdns.org/blog/">Back to the blog</a>
40 </body>
41 </html>
42
43 <?php
44 }
45 ?>