Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ///// content of newsletter.php
- <?php
- //If the form is submitted
- if(isset($_POST['submit'])) {
- //Check to make sure sure that a valid email address is submitted
- if(trim($_POST['email']) == '') {
- $hasError = true;
- } else if (!preg_match("/^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$/", trim($_POST['email']))) {
- $hasError = true;
- } else {
- $email = trim($_POST['email']);
- }
- //If there is no error, send the email
- if(!isset($hasError)) {
- $emailTo = 'test@test.com'; //Put your own email address here
- $subject = "Newsletter subscription";
- $body = "Email: $email";
- $headers = "From: $email";
- mail($emailTo, $subject, $body, $headers);
- }
- die("<span class='success'>Success! Your message has been sent.</span>");
- }
- ?>
- /// content of mail.php
- <?php
- //If the form is submitted
- if(isset($_POST['submit'])) {
- //Check to make sure that the name field is not empty
- if(trim($_POST['contactname']) == '') {
- $hasError = true;
- } else {
- $name = trim($_POST['contactname']);
- }
- //Check to make sure that the subject field is not empty
- if(trim($_POST['subject']) == '') {
- $hasError = true;
- } else {
- $subject = trim($_POST['subject']);
- }
- //Check to make sure sure that a valid email address is submitted
- if(trim($_POST['email']) == '') {
- $hasError = true;
- } else if (!preg_match("/^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$/", trim($_POST['email']))) {
- $hasError = true;
- } else {
- $email = trim($_POST['email']);
- }
- //Check to make sure comments were entered
- if(trim($_POST['message']) == '') {
- $hasError = true;
- } else {
- if(function_exists('stripslashes')) {
- $comments = stripslashes(trim($_POST['message']));
- } else {
- $comments = trim($_POST['message']);
- }
- }
- //If there is no error, send the email
- if(!isset($hasError)) {
- $emailTo = 'test@test.com'; //Put your own email address here
- $body = "Name: $name \n\nEmail: $email \n\nSubject: $subject \n\nComments:\n $comments";
- $headers = "From: $email";
- mail($emailTo, $subject, $body, $headers);
- }
- die("<span class='success'>Success! Your message has been sent.</span>");
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement