www.webdeveloper.com
Results 1 to 4 of 4

Thread: collect data, send in eMail, send "Thank you" & re-direct

  1. #1
    Join Date
    May 2006
    Posts
    3

    collect data, send in eMail, send "Thank you" & re-direct

    I am fighting a web page and the following code now id:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title>Contact us</title>
    <!-- define some style elements-->
    <style>
    h1
    {
    font-family : Arial, Helvetica, sans-serif;
    font-size : 16px;
    font-weight : bold;
    }
    label,a
    {
    font-family : Arial, Helvetica, sans-serif;
    font-size : 12px;
    }

    .style1 {
    text-align: center;
    }
    .style2 {
    font-family: Arial, Helvetica, sans-serif;
    font-size: 20pt;
    }

    .style3 {
    text-align: center;
    font-size: 48pt;
    }
    .style4 {
    text-align: center;
    font-size: 28pt;
    }
    .style5 {
    font-size: 20pt;
    }

    </style>
    <!-- a helper script for vaidating the form-->
    <script language="JavaScript" src="scripts/gen_validatorv31.js" type="text/javascript"></script>
    </head>

    <body style="background-image: url('Background.jpg')">
    <h1 class="style1">&nbsp;</h1>
    <h1 class="style3">Brandenburg Auto Clinic</h1>
    <h1 class="style4">Contact us</h1>
    <form method="POST" name="contactform" action="contact-form-handler.php">
    <div class="style1">
    <p class="style1">
    <label for='name' class="style5">Name:</label> <br class="style5">
    <input type="text" name="name" style="width: 280px" class="style5"><span class="style5">
    </span>
    </p>
    <p class="style1">
    <span class="style2">Street Address</span><br class="style5">
    <input type="text" name="address" style="width: 280px" class="style5"><span class="style5">
    </span>
    </p>
    <p class="style1">
    <span class="style2">City</span><br class="style5">
    <input type="text" name="city" style="width: 280px" class="style5"><span class="style5">
    </span>
    </p>
    <p class="style1">
    <span class="style2">State</span><br class="style5">
    <input type="text" name="state" style="width: 280px" class="style5"><span class="style5">
    </span>
    </p>
    <p class="style1">
    <span class="style2">Zip Code</span><br class="style5">
    <input type="text" name="state" style="width: 280px" class="style5"><span class="style5">
    </span>

    </p>
    <p class="style1">
    <span class="style2">Home/Work Telephone</span><br class="style5">
    <input type="text" name="phone" style="width: 280px" class="style5"><span class="style5">
    </span>
    </p>
    <p class="style1">
    <span class="style2">Cell Telephone</span><br class="style5">
    <input type="text" name="cell" style="width: 280px" class="style5"><span class="style5">
    </span>
    </p>
    <p class="style1">
    <span class="style2">eMail Address</span><br class="style5">
    <input type="text" name="email" style="width: 280px" class="style5"><span class="style5">
    </span>
    </p>
    <p class="style1">
    <label for='name' class="style5">Year/Make of Vehicle</label>
    <br class="style5">
    <input type="text" name="tear&make" style="width: 280px" class="style5"><span class="style5">
    </span>
    </p>
    <p class="style1">
    <span class="style2">Service Needed</span><br class="style5">
    <input type="text" name="needed" style="width: 450px" class="style5"><span class="style5">
    </span>
    </p>
    <p class="style1">
    <span class="style2">Preferred Date &amp; Time</span><br class="style5">
    <input type="text" name="date&time" style="width: 280px" class="style5">
    <br class="style5">
    </p>
    <p class="style1">
    <span class="style2">Comments</span><br>
    <textarea name="message" style="width: 306px; height: 197px"></textarea>
    </p>
    <input type="submit" value="Submit" name="Submit">&nbsp;&nbsp;&nbsp;
    <input type="reset" value="Reset"><br>
    </div>
    </form>

    </body>
    </html>

    Can soneone tell me how to collect the data entered, send it in an eMail, send a "Thank you" to the user then redirect to a specific URL?

  2. #2
    Join Date
    Aug 2011
    Location
    Worthing, West Sussex
    Posts
    96
    To collect the data, simply use the $_POST['var'] variable, with 'var' containing the NAME of the input. Then you can name it: $fname = $_POST['frame'];

    Send the email, using mail($email, $subject, $msg);

    And redirect using header("locationage.php"); exit;

    Here's my support page script:

    HTML Code:
    <? if(isset($_POST['send_x'])) {
    	if(empty($_POST['message'])) {
    		header("location:support.php?msg=1#page");
    		exit;
    	}
    	if(empty($_POST['email'])) {
    		header("location:support.php?msg=1#page");
    		exit;
    	}
    	if(empty($_POST['name'])) {
    		header("location:support.php?msg=1#page");
    		exit;
    	}
    	if(!eregi("^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,3})$", $_POST['email'])) {
    		header("location:support.php?msg=2#page");
    		exit;
    	}
    	$subject = "Website Message - Titanium Web Designs";
    	$name = $_POST['name'];
    	$subjectx = $_POST['subject'];
    	$company = $_POST['company'];
    	$telephone = $_POST['telephone'];
    	$message = $_POST['message'];
    	$theiremail = $_POST['email'];
    	$ip = $_SERVER['REMOTE_ADDR'];
    	$msg = '
    	<html>
    	<body style="font-family:Verdana, Arial, Helvetica, sans-serif;">
    	<p>A message has been sent from the Titanium Web Designs website.&nbsp; The message was from ' . $name . '.</p>
    	<p>Email: <strong>' . $theiremail . '</strong></p>
    	<p>Telephone: <strong>' . $telephone . '</strong></p>
    	<p>Company: <strong>' . $company . '</strong></p>
    	<p>Subject: <strong>' . $subjectx . '</strong></p>
    	<div style="width:700px; height:auto;">
    		<p>The message is:<br /><pre style="font-weight:bold; white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word; font-family:Verdana, Arial, Helvetica, sans-serif;">' . stripslashes($message) . '</pre></p>
    	</div>
    	<p>The message was sent on ' . gmdate('l jS \of F Y h:i:s A') . '</p>
    	<p>Their IP address is ' . $ip . '</p>
    	</body>
    	</html>
    	';
    	$headers  = 'MIME-Version: 1.0' . "\r\n";
    	$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
    	$headers .= 'From: Titanium Web Designs <donotreply@titaniumwebdesigns.com>' . "\r\n";
    	$headers .= 'Reply-To: ' . $name . ' <' . $theiremail . '>' . "\r\n";
    	$email = 'info@titaniumwebdesigns.com';
    	if (@mail($email, $subject, $msg, $headers)) {
    		header('location:support.php?msg=4');
    		exit;
    	}
    	header('location:support.php?msg=0');
    	exit;
    } ?>

  3. #3
    Join Date
    Nov 2006
    Location
    Springfield, MO
    Posts
    1,541
    One minor note about the code above, you should not be using eregi for the regular expression. Use preg_match instead, it's faster, and better optimized.

  4. #4
    Join Date
    Aug 2011
    Location
    Worthing, West Sussex
    Posts
    96
    Thanks for that tip, wrote that code a few years back!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles