]> git.vanrenterghem.biz Git - www.vanrenterghem.biz.git/blob - phppages/mail.php
Update header - remove Tech section and add Projects.
[www.vanrenterghem.biz.git] / phppages / mail.php
1 <html>
2 <head><title>PHP Mail Sender</title></head>
3 <body>
4 <?php
6 /* All form fields are automatically passed to the PHP script through the array $HTTP_POST_VARS. */
7 $email = $HTTP_POST_VARS['email'];
8 $subject = $HTTP_POST_VARS['subject'];
9 $message = $HTTP_POST_VARS['message'];
11 /* PHP form validation: the script checks that the Email field contains a valid email address and the Subject field isn't empty. preg_match performs a regular expression match. It's a very powerful PHP function to validate form fields and other strings - see PHP manual for details. */
12 if (!preg_match("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/", $email)) {
13   echo "<h4>Invalid email address</h4>";
14     echo "<a href='javascript:history.back(1);'>Back</a>";
15     } elseif ($subject == "") {
16       echo "<h4>No subject</h4>";
17         echo "<a href='javascript:history.back(1);'>Back</a>";
18         }
19         
20         /* Sends the mail and outputs the "Thank you" string if the mail is successfully sent, or the error string otherwise. */
21         elseif (mail($email,$subject,$message)) {
22           echo "<h4>Thank you for sending email</h4>";
23           } else {
24             echo "<h4>Can't send email to $email</h4>";
25             }
26             ?>
27             </body>
28             </html>
29