...

View Full Version : Help presenting errors on recommend script



AshleyQuick
01-17-2004, 04:32 PM
Currently, the errors are presented by essentially hiding the form and being shown by themselves. As you can see, I added a history.go(-1) function to get back to the form a bit easier but this is far from ideal. Can someone help modify this so that the errors are maybe highlighted on the form? ie. Your Name: and Your Email would turn to #F04637?

Ashley


<?php

$yourUrl = "http://xyz.net";

$webmasterEmail = "info@xyz.net";

$receiveNotifications = 1;

$messagecolor = "#F04637";

$subject = "Website Recommendation from $yourName ($yourEmail)";

$sendMessage = "Hello,\n\n**YourName** thought you would like to visit the following site:\n\n$yourUrl";

if($action == "go") {

if(empty($yourName)) {
$message .= "Please enter your name.<br />";
$error = 1;
}

if(empty($yourEmail)) {
$message .= "Please enter your email address.<br />";
$error = 1;
}
else {
if(!isValid($yourEmail)) {
$message .= "Please enter a proper email address for yourself.<br />";
$error = 1;
}
}
if(empty($a1) && empty($a2) && empty($a3) && empty($a4) && empty($a5)) {
$message .= "Please enter at least one friend's email address.<br />";
$error = 1;
}

$emailList = array(); // create empty array
if(!empty($a1)) {
if(!isValid($a1)) {
$finalM .= "Email 1 was not valid and no message was sent to it.<br />";
}
else {
$amount = $amount + 1;
array_push($emailList,$a1);
}
}
if(!empty($a2)) {
if(!isValid($a2)) {
$finalM .= "Email 2 was not valid and no message was sent to it.<br />";
}
else {
$amount = $amount + 1;
array_push($emailList,$a2);
}
}

if(!empty($a3)) {
if(!isValid($a3)) {
$finalM .= "Email 3 was not valid and no message was sent to it.<br />";
}
else {
$amount = $amount + 1;
array_push($emailList,$a3);
}
}

if(!empty($a4)) {
if(!isValid($a4)) {
$finalM .= "Email 4 was not valid and no message was sent to it.<br />";
}
else {
$amount = $amount + 1;
array_push($emailList,$a4);
}
}

if(!empty($a5)) {
if(!isValid($a5)) {
$finalM .= "Email 5 was not valid and no message was sent to it.<br />";
}
else {
$amount = $amount + 1;
array_push($emailList,$a5);
}
}
reset($emailList); // Set the array pointer to the beginning

// Now if there are no errors, send the message.
if($error == 0) {
$sendMessage = str_replace("**YourName**",$yourName,$sendMessage);
foreach($emailList as $to) {
if(!mail($to,$subject,"$sendMessage\n\n" . $customMessage . "\n\n\nNote: This message was not sent unsolicited. It was sent through a form located at http://xyz.net. If you believe this message was received on error, please disregard it.",
"From: $yourEmail\r\n"
."Reply-To: $yourEmail\r\n"
."X-Mailer: Recommend Us Script\r\n"))
{
$finalM .= "<br />Message was not successfully sent to ${to}. Please try again later.<br />";
} // != mail()
else {
$finalM .= "<br />Message was sent to $to.<br />";
$reciplist .= " $to,"; // To be used in notifications
} // end != else
} // end for each
} // end error if

if ($error == "1") {
echo "<font color=\"$messagecolor\">$message</font><br /><br /><a href=javascript:history.go(-1)>Go Back</a>\n";
}
if ($finalM) {
echo "$finalM<br />Thank you very much for recommending XYZ.<br />\n";
if($receiveNotifications) {
@mail($webmasterEmail,"Someone Recommended Your Site","\nThis is a message to tell you that $yourName ($yourEmail) sent a website recommendation to$reciplist.\nEnd Message",
"From: $webmasterEmail\r\n"
."X-Mailer: Recommend Us Script");
} // end if receive notifications.
}

} // end main if

else {
echo<<<EOD
<table class="indent">
<form method="POST" action="$PHP_SELF">
<tr>
<td class="formtext" id="pagetext2">Your Name:</td>
<td><input type=text name=yourName onfocus="this.style.borderColor='#0072BC';" onblur="this.style.borderColor='silver';"></td>
</tr>
<tr>
<td class="formtext" id="pagetext3">Your Email:</td>
<td><input type=text name=yourEmail onfocus="this.style.borderColor='#0072BC';" onblur="this.style.borderColor='silver';"></td>
</tr>
<tr>
<td colspan="2" id="pagetext4">Recipient Email Addresses&nbsp;&nbsp; <span class="basefontblue">at least one</span> <br /><br /></td>
</tr>
<tr>
<td class="formtext" id="pagetext5">1:</td>
<td><input type=text name=a1 onfocus="this.style.borderColor='#0072BC';" onblur="this.style.borderColor='silver';"></td>
</tr>
<tr>
<td class="formtext3" id="pagetext6">2:</td>
<td><input type=text name=a2 onfocus="this.style.borderColor='#0072BC';" onblur="this.style.borderColor='silver';"></td>
</tr>
<tr>
<td class="formtext3" id="pagetext7">3:</td>
<td><input type=text name=a3 onfocus="this.style.borderColor='#0072BC';" onblur="this.style.borderColor='silver';"></td>
</tr>
<tr>
<td class="formtext3" id="pagetext8">4:</td>
<td><input type=text name=a4 onfocus="this.style.borderColor='#0072BC';" onblur="this.style.borderColor='silver';"></td>
</tr>
<tr>
<td class="formtext3" id="pagetext9">5:</td>
<td><input type=text name=a5 onfocus="this.style.borderColor='#0072BC';" onblur="this.style.borderColor='silver';"></td>
</tr>
<tr>
<td colspan="2" id="pagetext10">Your Message&nbsp;&nbsp; <span class="basefontblue">Optional</span> <br /><textarea name=customMessage rows=5 cols=31 onfocus="this.style.borderColor='#0072BC';" onblur="this.style.borderColor='silver';"></textarea></td>
</tr>
<tr>
<td colspan="2"><br />
<table>
<tr>
<td><img alt="Recommend Us!" width="32" height="24" src="../art/gq.send.gif" /></td>
<td><input class="send" type=submit value="Send Message" /></td>
<td class="formtext">&nbsp;</td>
<td><input class="reset" type="reset" value="Reset Form" /></td>
<td><input type=hidden name=action value="go"></td>
</tr>
</table>
</td>
</tr>
</form>
</table>

EOD;
} // end main else

function isValid($email) {
if(eregi("^[a-z0-9\._-]+@+[a-z0-9\._-]+\.+[a-z]{2,3}$", $email)) return TRUE;
else return FALSE;
}

?>

Celtboy
01-17-2004, 07:39 PM
I'd love to help, but it would be much easier if I could get the code to work! I get all kinds of errors.

I took your messages, stuck them in variables (so as to reduce line break issues), but it still doesn't want to work....

I get a: T_CONSTANT_ENCAPSED_STRING

referencing the first "onBlur" line in the heredoc section (<<<EOD)

AshleyQuick
01-17-2004, 08:58 PM
It should work now, sorry. :(

Celtboy
01-19-2004, 04:44 AM
LOL. In my great attempt to simplify the code, I may have made it much more complex, lol.....


The simple way to solve your problem would be to record all results into a variable. Also, instead of echoing the entire template, store it in a variable outside of the main if conditional.

That way, you just print out the results (if any), and the form, Every time.

To solve the background color,

You could do something like this:



...
$nameError = "";
$nameErrorColor = "#F04637";
$yourEmailError = "";
$yourEmailErrorColor="#F04637";
...
if(empty($yourName)) {
$message .= "Please enter your name.<br />";
$error = 1;
$nameError = "bgcolor=\"" . $nameErrorColor . "\"";
}

if(empty($yourEmail)) {
$message .= "Please enter your email address.<br />";
$error = 1;
$yourEmailError = "bgcolor=\"" . $yourEmailErrorColor ."\"";
}
else {
if(!isValid($yourEmail)) {
$message .= "Please enter a proper email address for yourself.<br />";
$error = 1;
$yourEmailError = "bgcolor=\"" . $yourEmailErrorColor ."\"";

}
}
...
echo<<<EOD
<table class="indent">
<form method="POST" action="$PHP_SELF">
<tr>
<td class="formtext" id="pagetext2" $nameError>Your Name:</td>
<td $nameError><input type=text name=yourName onfocus="this.style.borderColor='#0072BC';" onblur="this.style.borderColor='silver';"></td>
</tr>
<tr>
<td class="formtext" id="pagetext3" $yourEmailError>Your Email:</td>
<td $yourEmailError><input type=text name=yourEmail onfocus="this.style.borderColor='#0072BC';" onblur="this.style.borderColor='silver';"></td>
</tr>
...


(the ...'s indicate other code (untouched) above and below).

Your other option would be to take the nasty (but functional!) code that I rewrote for this. Again, it's nasty, but I changed quite a few things, such as:
- Formatting. Parenthesis didn't match (visually)
- the messages sent used hardcoded webmaster email adresses and your Url.
- naming of your config variables was confusing. I think I fixed this via naming
- You can easily alter the number of email recipients you want available by editing the value of $num_recips
- Error Numbers. Currently these are kinda uselesss, but I love adding them!
- updated the code to work with newer versions of apache where register_globals is turned off.

Anywho, here's my code:


<?php
/* Config Section */
$yourUrl = "http://xyz.net";
$webmasterEmail = "info@xyz.net";
$receiveNotifications = 1;
$num_recips = 6;
$messageColor = "#F04637";
$visitorEmailColor = "#F04637";
$visitorNameColor = "#F04637";
$subject = "Website Recommendation from {{VISITOR_NAME}} ({{VISITOR_EMAIL}})";
$sendMessage = "Hello,\n\n {{VISITOR_NAME}} thought you would like to visit the following site:\n\n" . $yourUrl;
$submit_results = "<b>Your Results</b><br/>\n<hr/ align=\"left\" width=\"150\"><br/>\n";
$title = "<b>Recommend this website to a friend!</b>\n<br/><br/>";
/* End Config */


///////////////////////////////////////////////////
// DO NOT EDIT ANYTHING BEYOND THIS POINT!!! //
///////////////////////////////////////////////////


/* Create a few variables for our script */
$PHP_SELF = $_SERVER['PHP_SELF'];
$visitorName = "";
$visitorEmail = "";
$customMessage = "";
$array_friends = array();
$visitorNameStyle = "";
$visitorEmailStyle = "";

/* Make sure the script has an action, if not given */
if (isset($_POST["action"])) {
$action = $_POST["action"];
} else {
$action = "no";
}

/* Generate the array of recipients text boxes*/
for ($x=1; $x<=$num_recips; $x++) {
eval ("\$a" . $x . "= \"\";");
$temp = "a" . $x;
array_push($array_friends,$temp);
}

$results = $title;



$error_array = array(); // this keeps a running inventory of errors found
$error = 0;
$emailList = array(); // create empty array
$amount = 0;
$all_empty = true;
$error_array_ids = array();
$error_style = "";



if($action == "go") {

$results = $title . $submit_results;

/* Were we given a visitor name? */
if(empty($_POST["visitorName"])) {
$message = "Please enter your name.<br />";
$error = 1;
$error_num = 1;
array_push($error_array,"Error Number " . $error_num . ": " . $message);
$visitorNameStyle = "bgcolor=\"" . $visitorNameColor . "\"";

} else { $visitorName = $_POST["visitorName"];}


/* Did the visitor give us their email address? */
if(!isset($_POST["visitorEmail"])) {

$message = "Please enter your email address.<br />";
$error = 1;
$error_num = 2;
array_push($error_array,"Error Number " . $error_num . ": " . $message);
$visitorEmailStyle = "bgcolor=\"" . $visitorEmailColor . "\"";
} else {

/* We got an email address, but is it valid? */
if(!isValid($_POST["visitorEmail"])) {
$message = "Please enter a proper email address for yourself.<br />";
$error = 1;
$error_num = 3;
array_push($error_array,"Error Number " . $error_num . ": " . $message);
$visitorEmailStyle = "bgcolor=\"" . $visitorEmailColor . "\"";
}

$visitorEmail = $_POST["visitorEmail"];
}

/* Check to see if we were given ANY email addresses */
foreach ($array_friends as $value) {
if (isset($_POST[$value])) {
if (!empty($_POST[$value]) && ($all_empty)) {
$all_empty = FALSE;
}
}
}

if ($all_empty) {
/* We weren't given any email addresses of friends! */
$message = "Please enter at least one friend's email address.<br />";
$error = 1;
$error_num = 4;
array_push($error_array,"Error Number " . $error_num . ": " . $message);
array_push($error_array_ids,"a1");
} else {

/* We were given an email address, but we need to check if it was valid */
foreach ($array_friends as $key) {
if (isset($_POST[$key])) {
if (!empty($_POST[$key])) {
$$key = $_POST["$key"];
if (!isValid($_POST[$key])) {
$error_num = 5;
$key .= "";
$message = "Email Address " . substr($key,1) . " was not valid and no message was sent to it.<br/>";
array_push($error_array,"Error Number " . $error_num . ": " . $message);
array_push($error_array_ids,$key);
} else {
$amount++;
array_push($emailList,$_POST[$key]);
}
}
}
} // foreach
}

reset($emailList); // Set the array pointer to the beginning

/* If there are no errors, send the message. */
if($error != 1) {

/* Additional Message Text */
$sendMessage = str_replace("{{VISITOR_NAME}}",$_POST["visitorName"],$sendMessage);
$text = "Note: This message was not sent unsolicited. It was sent through a form located at ";
$text .= "<a href=\"" . $yourUrl . "\" target=\"_blank\">" . $yourUrl ."</a> If you believe this message was received in error, please disregard it.";
$from = str_replace("{{VISITOR_NAME}}", $_POST["visitorName"], "From: {{VISITOR_NAME}}\r\n Reply-To: {{VISITOR_EMAIL}}\r\n X-Mailer: Recommend Us Script\r\n");
$from = str_replace("{{VISITOR_EMAIL}}", $_POST["visitorEmail"], $from);

/* Attempt to send the email message */
foreach($emailList as $to) {
if(!mail($to,$subject,$sendMessage . "\n\n\n" . $customMessage . "\n\n\n" . $text,$from)) {
$results .= "<br />Message was not successfully sent to ${to}. Please try again later.<br />";
} else {
$results .= "<br />Message was sent to $to.<br />";
$reciplist .= " $to,"; // To be used in notifications
}
}

/* Confirmation */
$results .= "<br/>\nThank you very much for recommending " . $yourUrl . ".<br/>\n";

/* Send email to webmaster if notifications are turned on */
if($receiveNotifications == 1) {
$text = "\n This is a message to tell you that {{VISITOR_NAME}} ({{VISITOR_EMAIL}}) sent a website recommendation to " . $reciplist . ".\n End Message";
$text = str_replace("{{VISITOR_NAME}}",$_POST["visitorName"],$text);
$text = str_replace("{{VISITOR_EMAIL}}",$_POST["visitorEmail"],$text);

@mail($webmasterEmail,"Someone Recommended Your Site",$text,"From: $webmasterEmail\r\n" . "X-Mailer: Recommend Us Script");
}

} else {
/* There were errors found */
$results .= "The following Errors were found in your submission:<br/>\n";
foreach ($error_array as $error_text) {
$results .= $error_text;
}
}

}

$form =<<<EOD
<table class="indent">
<form method="POST" action="$PHP_SELF" name="referrer">
<tr>
<td $visitorNameStyle class="formtext" id="pagetext2">Your Name:</td>
<td $visitorNameStyle><input type="text" name="visitorName" onfocus="this.style.borderColor='#0072BC'" onblur="this.style.borderColor='silver'" value="$visitorName"></td>
</tr>
<tr>
<td $visitorEmailStyle class="formtext" id="pagetext3">Your Email:</td>
<td $visitorEmailStyle><input type="text" name="visitorEmail" onfocus="this.style.borderColor='#0072BC'" onblur="this.style.borderColor='silver'" value="$visitorEmail"></td>
</tr>
<tr>
<td colspan="2" id="pagetext4">Recipient Email Addresses&nbsp;&nbsp; <span class="basefontblue">at least one</span> <br /><br /></td>
</tr>
EOD;

$pagetext_num = 5;
$count = 1;

foreach ($array_friends as $key) {
$value = $$key;

foreach ($error_array_ids as $error_key) {
if (substr($error_key,1) == $count) {
$error_style = "bgcolor=\"$messageColor\"";
break;
} else {
$error_style = "bgcolor=\"#FFFFFF\"";
}
}

$form .=<<<EOD
<tr $error_style>
<td class="formtext" id="pagetext$pagetext_num">$count:</td>
<td><input type="text" name="$key" onfocus="this.style.borderColor='#0072BC';" onblur="this.style.borderColor='silver';" value="$value"></td>
</tr>
EOD;


$pagetext_num++;
$count++;
}

$form .=<<<EOD
<tr>
<td colspan="2" id="pagetext10">Your Message&nbsp;&nbsp;
<span class="basefontblue">Optional</span> <br />
<textarea name="customMessage" rows="5" cols="31" onfocus="this.style.borderColor='#0072BC';" onblur="this.style.borderColor='silver';">$customMessage</textarea>
</td>
</tr>
<tr>
<td colspan="2"><br />
<table>
<tr>
<td><img alt="Recommend Us!" width="32" height="24" src="../art/gq.send.gif" /></td>
<td><input class="send" type=submit value="Send Message" /></td>
<td class="formtext">&nbsp;</td>
<td><input class="reset" type="reset" value="Reset Form" /></td>
<td><input type="hidden" name="action" value="go"></td>
</tr>
</table>
</td>
</tr>
</form>
</table>

EOD;

function isValid($email) {
if(eregi("^[a-z0-9._-]+@+[a-z0-9._-]+.+[a-z]{2,3}$", $email)) {
return TRUE ;
} else {
return FALSE;
}
}

/* All processing is done. Now let's show some output! */
print $results;
print "<br/><hr align=\"left\" width=\"150\"/><br/>\n";
print $form;

?>

AshleyQuick
01-19-2004, 06:45 PM
Ok...I really like the way in which you've rearranged and reorganized things. :)

I found some bugs, however. :(

Look at this screenshot which will show two of them:

http://mywebpages.comcast.net/maxpixel/recommend.from.subject.gif

If the user does not enter a last name (in this case, simply entering Ashley instead of Ashley Quick), will result in a from address such as Ashley@unixserver5.unixsrv5.com. In addition, the visitor's name and email (VISITOR_NAME and VISITOR_EMAIL respectively) are not populating the subject line.

Also, it looks like if you enter optional message text it is not coming through. If this is "fixable," is it also possible/feasible to have this data sent to the webmaster?

Last, but not least ;) ...and this is just a preference...would is be possible to hide the form fields and just display the "results" once the form has been successfully sent?

Thanks for all the help thus far! You've certainly invested some time. :)

Ashley

Celtboy
01-20-2004, 04:52 AM
Ok. I haven't tested it yet, but plug this in and see how it works. I've tried to fix each thing you mentioned, but I'm not positive about the FROM: email address thing. Just test it.

(I also added a header....you can delete it if you want)


<?php
/*****************************************
* Script Name: RecommendIt! Script *
* Author: Unknown *
* Modified: Celtboy (John Collins) *
* jsk@wintrusion.com *
* Date: 1.19.04 *
******************************************/


/* Config Section */
$yourUrl = "http://xyz.net";
$webmasterEmail = "info@xyz.net";
$receiveNotifications = 1;
$num_recips = 6;
$messageColor = "#F04637";
$visitorEmailColor = "#F04637";
$visitorNameColor = "#F04637";
$subject = "Website Recommendation from {{VISITOR_NAME}} ({{VISITOR_EMAIL}})";
$sendMessage = "Hello,\n\n {{VISITOR_NAME}} thought you would like to visit the following site:\n\n" . $yourUrl;
$submit_results = "<b>Your Results</b><br/>\n<hr/ align=\"left\" width=\"150\"><br/>\n";
$title = "<b>Recommend this website to a friend!</b>\n<br/><br/>";
/* End Config */


///////////////////////////////////////////////////
// DO NOT EDIT ANYTHING BEYOND THIS POINT!!! //
///////////////////////////////////////////////////


/* Create a few variables for our script */
$PHP_SELF = $_SERVER['PHP_SELF'];
$visitorName = "";
$visitorEmail = "";
$customMessage = "";
$array_friends = array();
$visitorNameStyle = "";
$visitorEmailStyle = "";
$error_array = array(); // this keeps a running inventory of errors found
$error = 0;
$emailList = array(); // create empty array
$amount = 0;
$all_empty = true;
$error_array_ids = array();
$error_style = "";
$success_complete = 0;

/* Make sure the script has an action, if not given */
if (isset($_POST["action"])) {
$action = $_POST["action"];
} else {
$action = "no";
}

/* Generate the array of recipients text boxes*/
for ($x=1; $x<=$num_recips; $x++) {
eval ("\$a" . $x . "= \"\";");
$temp = "a" . $x;
array_push($array_friends,$temp);
}

$results = $title;



if($action == "go") {

$results = $title . $submit_results;

/* Were we given a visitor name? */
if(empty($_POST["visitorName"])) {
$message = "Please enter your name.<br />";
$error = 1;
$error_num = 1;
array_push($error_array,"Error Number " . $error_num . ": " . $message);
$visitorNameStyle = "bgcolor=\"" . $visitorNameColor . "\"";

} else { $visitorName = $_POST["visitorName"];}


/* Did the visitor give us their email address? */
if(!isset($_POST["visitorEmail"])) {

$message = "Please enter your email address.<br />";
$error = 1;
$error_num = 2;
array_push($error_array,"Error Number " . $error_num . ": " . $message);
$visitorEmailStyle = "bgcolor=\"" . $visitorEmailColor . "\"";
} else {

/* We got an email address, but is it valid? */
if(!isValid($_POST["visitorEmail"])) {
$message = "Please enter a proper email address for yourself.<br />";
$error = 1;
$error_num = 3;
array_push($error_array,"Error Number " . $error_num . ": " . $message);
$visitorEmailStyle = "bgcolor=\"" . $visitorEmailColor . "\"";
}

$visitorEmail = $_POST["visitorEmail"];
}

/* Check to see if we were given ANY email addresses */
foreach ($array_friends as $value) {
if (isset($_POST[$value])) {
if (!empty($_POST[$value]) && ($all_empty)) {
$all_empty = FALSE;
}
}
}

if ($all_empty) {
/* We weren't given any email addresses of friends! */
$message = "Please enter at least one friend's email address.<br />";
$error = 1;
$error_num = 4;
array_push($error_array,"Error Number " . $error_num . ": " . $message);
} else {

/* We were given an email address, but we need to check if it was valid */
foreach ($array_friends as $key) {
if (isset($_POST[$key])) {
if (!empty($_POST[$key])) {
$$key = $_POST["$key"];
if (!isValid($_POST[$key])) {
$error_num = 5;
$key .= "";
$message = "Email Address " . substr($key,1) . " was not valid and no message was sent to it.<br/>";
array_push($error_array,"Error Number " . $error_num . ": " . $message);
array_push($error_array_ids,$key);
} else {
$amount++;
array_push($emailList,$_POST[$key]);
}
}
}
} // foreach
}

reset($emailList); // Set the array pointer to the beginning

/* If there are no errors, send the message. */
if($error != 1) {
$success_complete = 1;

/* Additional Message Text */
$sendMessage = str_replace("{{VISITOR_NAME}}",$_POST["visitorName"],$sendMessage);
$text = "Note: This message was not sent unsolicited. It was sent through a form located at ";
$text .= "<a href=\"" . $yourUrl . "\" target=\"_blank\">" . $yourUrl ."</a> If you believe this message was received in error, please disregard it.";
$from = str_replace("{{VISITOR_NAME}}", $_POST["visitorName"], "From: {{VISITOR_NAME}} \r\n Reply-To: {{VISITOR_EMAIL}}\r\n X-Mailer: Recommend Us Script\r\n");
$from = str_replace("{{VISITOR_EMAIL}}", $_POST["visitorEmail"], $from);

/* Attempt to send the email message */
foreach($emailList as $to) {

$subject = str_replace("{{VISITOR_NAME}}", $_POST["visitorName"], $subject);
$subject = str_replace("{{VISITOR_EMAIL}}", $_POST["visitorEmail"], $subject);

if(!mail($to,$subject,$sendMessage . "\n\n\n" . $_POST["customMessage"] . "\n\n\n" . $text,$from)) {
$results .= "<br />Message was not successfully sent to ${to}. Please try again later.<br />";
$success_complete = 0;
} else {
$results .= "<br />Message was sent to $to.<br />";
$reciplist .= " $to,"; // To be used in notifications
}
}

/* Confirmation */
$results .= "<br/>\nThank you very much for recommending " . $yourUrl . ".<br/>\n";

/* Send email to webmaster if notifications are turned on */
if($receiveNotifications == 1) {
$text = "\n This is a message to tell you that {{VISITOR_NAME}} ({{VISITOR_EMAIL}}) sent a website recommendation to " . $reciplist . ".\n";

if ($_POST["customMessage"] != " ") {
$text .= "{{VISITOR_NAME}} also sent the following message:\n\n" . $_POST["customMessage"];
}
$text .= "\n\nEnd Message";
$text = str_replace("{{VISITOR_NAME}}",$_POST["visitorName"],$text);
$text = str_replace("{{VISITOR_EMAIL}}",$_POST["visitorEmail"],$text);

@mail($webmasterEmail,"Someone Recommended Your Site",$text,"From: $webmasterEmail\r\n" . "X-Mailer: Recommend Us Script");
}

} else {
/* There were errors found */
$results .= "The following Errors were found in your submission:<br/>\n";
foreach ($error_array as $error_text) {
$results .= $error_text;
}
}

}

$form =<<<EOD
<table class="indent">
<form method="POST" action="$PHP_SELF" name="referrer">
<tr>
<td $visitorNameStyle class="formtext" id="pagetext2">Your Name:</td>
<td $visitorNameStyle><input type="text" name="visitorName" onfocus="this.style.borderColor='#0072BC'" onblur="this.style.borderColor='silver'" value="$visitorName"></td>
</tr>
<tr>
<td $visitorEmailStyle class="formtext" id="pagetext3">Your Email:</td>
<td $visitorEmailStyle><input type="text" name="visitorEmail" onfocus="this.style.borderColor='#0072BC'" onblur="this.style.borderColor='silver'" value="$visitorEmail"></td>
</tr>
<tr>
<td colspan="2" id="pagetext4">Recipient Email Addresses&nbsp;&nbsp; <span class="basefontblue">at least one</span> <br /><br /></td>
</tr>
EOD;

$pagetext_num = 5;
$count = 1;

foreach ($array_friends as $key) {
$value = $$key;

foreach ($error_array_ids as $error_key) {
if (substr($error_key,1) == $count) {
$error_style = "bgcolor=\"$messageColor\"";
break;
} else {
$error_style = "bgcolor=\"#FFFFFF\"";
}
}

$form .=<<<EOD
<tr $error_style>
<td class="formtext" id="pagetext$pagetext_num">$count:</td>
<td><input type="text" name="$key" onfocus="this.style.borderColor='#0072BC';" onblur="this.style.borderColor='silver';" value="$value"></td>
</tr>
EOD;

$pagetext_num++;
$count++;
}

$form .=<<<EOD
<tr>
<td colspan="2" id="pagetext10">Your Message&nbsp;&nbsp;
<span class="basefontblue">Optional</span> <br />
<textarea name="customMessage" rows="5" cols="31" onfocus="this.style.borderColor='#0072BC';" onblur="this.style.borderColor='silver';">$customMessage </textarea>
</td>
</tr>
<tr>
<td colspan="2"><br />
<table>
<tr>
<td><img alt="Recommend Us!" width="32" height="24" src="../art/gq.send.gif" /></td>
<td><input class="send" type=submit value="Send Message" /></td>
<td class="formtext">&nbsp;</td>
<td><input class="reset" type="reset" value="Reset Form" /></td>
<td><input type="hidden" name="action" value="go"></td>
</tr>
</table>
</td>
</tr>
</form>
</table>

EOD;


/* Checks the validity (formatting) of an email address */
function isValid($email) {
if(eregi("^[a-z0-9._-]+@+[a-z0-9._-]+.+[a-z]{2,3}$", $email)) {
return TRUE ;
} else {
return FALSE;
}
}



/* All processing is done. Now let's show some output! */

print $results;
print "<br/><hr align=\"left\" width=\"150\"/><br/>\n";

if ($success_complete != 1) {
print $form;
}

?>

AshleyQuick
01-27-2004, 03:59 AM
Nice job! I like this!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum