Jump to content

E-mailing form results to me


Spycat

Recommended Posts

Ok, this is probably laughingly simple to the experts out here.
Go ahead and laugh, but can ya help me too...please?
Well, from that intro, you have probably gathered that I am [i]not[/i] a PHP programmer.
Anyway, here it is:
I found a CAPTCHA script that I really liked. However, the author neglected to include code that would
take the input entered into the form and e-mail them to me.
I went looking around for other form handling scripts that sent the results in order to "piece it together" with the CAPTCHA
script. The thing is, most of these scripts get WAY to involved with their own validating processes and such, so
I can not get any to work.
I have a couple of little "send results to my email" snippets inserted into the code now, but like I said, they are not working.
Can someone please take a look at it and well...fix it?
I intend to learn PHP, but at this point, I just need the script to work.
Also, it is important that the "Thank You Page": "header("Location: http://www.metroactive.com/contact/thanks.html"); " remain functional.
I would be really grateful for this.
In the code I am providing, I will comment with :"Pieced in" on those parts that are from the 2nd script that sends form responses. All the rest of the code is from the "CAPTCHA" script.

Thanks folks :)

[code]
<?php
session_start();
if (isset($_POST['submit'])) {
// clean and check form inputs including the secure image code
    $name = trim(strip_tags($_POST['name']));
    $email = trim(strip_tags($_POST['email']));
    $phone = trim(strip_tags($_POST['phone']));
$event_title = trim(strip_tags($_POST['event_title']));
    $event_date_and_time = trim(strip_tags($_POST['event_date_and_time']));
    $event_location = trim(strip_tags($_POST['event_location']));
$event_phone_number = trim(strip_tags($_POST['event_phone_number']));
    $event_price = trim(strip_tags($_POST['event_price']));
    $event_description = trim(strip_tags($_POST['event_description']));

    $secure = strtoupper(trim(strip_tags($_POST['secure'])));
    $match = $_SESSION['captcha']; // the code on the image

//Start Pieced in
$MailToAddress = "rik408@yahoo.com";
$MailSubject = "Club Event Submission";
    if (!$MailFromAddress) {
    $MailFromAddress = "$email";
    }
//end pieced in

// input error checking
    if ($name=="") {
        $err.= "Please provide your name<br/>";
    }
    if (!$email) {
        $err.= "Please provide your email address<br>";
    }
    if ($email) {
        if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) {
            $err.= $email. " is not a valid email address.<br/>";
        }
    }
    if ($phone=="") {
        $err.= "Please provide your phone number<br/>";
    }

if ($event_title=="") {
        $err.= "Please provide the title of the event<br/>";
    }

if ($event_date_and_time=="") {
        $err.= "Please provide the date and time of the event<br/>";
    }

if ($event_location=="") {
        $err.= "Please provide the location of the event<br/>";
    }

if ($event_phone_number=="") {
        $err.= "Please provide a phone number for the venue<br/>";
    }

if ($event_price=="") {
        $err.= "Please provide the price to attend the event<br/>";
    }

if ($event_description=="") {
        $err.= "Please provide a description for the event<br/>";
    }




    if (!$secure) {
        $err.= "No security code entered<br/>";
    }
    if (($secure!=$match) && ($secure!="")) {
        $err.= "Security code mismatch<br/>";
    }
    if ($err=="") {

//start pieced in: this may be a major trouble spot, since it is preceeded by another "if" statement
if (!is_array($HTTP_POST_VARS))
    return;
reset($HTTP_POST_VARS);
    while(list($key, $val) = each($HTTP_POST_VARS)) {
    $GLOBALS[$key] = $val;
    $val=stripslashes($val);
    echo  "<b>$key</b> = $val<br>";
    $Message .= "$key = $val\n";
    }

 
mail( "$MailToAddress", "$MailSubject", "$Message", "From: $MailFromAddress");

 
header("Location: http://www.metroactive.com/contact/thanks.html");
//end pieced in
    exit();
    }
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Trolls go away</title>
<style type="text/css">
body,td {
font-family:arial, helvetica, sans-serif;
background:#fff;
color:#000;
font-size:12px;
}
input, textarea {
background:#eee;
color:#000;
font-size:12px;
border:1px solid #000; 
}
</style>
</head>
<body>
<?php
if ($err!="") {
    echo "<strong>Form Error(s)</strong><br/>";
    echo "<font color='#cc3300'>". nl2br($err). "</font><br/>";
}
?>

<form name="captcha" method="post" action="<?php echo $_SERVER['SCRIPT_NAME'];?>">
<table cellpadding="3" cellspacing="2" style="border:1px dotted #667;">
<tr>
<td>Name:</td><td><input type="text" name="name" value="<?php echo $_POST['name'];?>"/></td>
</tr>
<tr>
<td>Email:</td><td><input type="text" name="email" value="<?php echo $_POST['email'];?>"/></td>
</tr>
<tr>
<td>Daytime Phone: </td>
<td><input type="text" name="phone" value="<?php echo $_POST['phone'];?>"/></td>
</tr>
<tr>
<td>Club Event Title:</td><td><input type="text" name="event_title" value="<?php echo $_POST['event_title'];?>"/></td>
</tr>
<tr>
<td>Date and Time:</td><td><input type="text" name="event_date_and_time" value="<?php echo $_POST['event_date_and_time'];?>"/></td>
</tr>
<tr>
<td>Location:</td><td><input type="text" name="event_location" value="<?php echo $_POST['event_location'];?>"/></td>
</tr>
<tr>
<td>Venue Phone Number:</td><td><input type="text" name="event_phone_number" value="<?php echo $_POST['event_phone_number'];?>"/></td>
</tr>
<tr>
<td>Price</td><td><input type="text" name="event_price" value="<?php echo $_POST['event_price'];?>"/></td>
</tr>
<tr>
<td valign="top">Event Description:</td><td><textarea rows="5" columns="30" name="event_description"><?php echo $_POST['event_description'];?></textarea></td>
</tr>
<tr>

<td>Security Code</td><td><input type="text" name="secure"/></td>
</tr>
<tr>
<td><img src="captcha_image.php" alt="security image" border="0"/></td><td>
<input type="submit" name="submit" value="Send"/></td>
</tr>
</table>
</form>
</body>
</html>
[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.