My bad! That was a typo in the message. I did actually have the semicolon in there. The script I am trying to modify is one I found online that was free to use and modify (helpful for someone like me who seems to think the only way to learn is the hard way :rolleyes: ). For my needs, I have to pull out the function and put it in a separate php file that can be included in the script. So, if you are willing to wade through the whole thing...
The function (the actual original one that has been the real problem:
<?php>
function Random($length)
{
$chars = "ABCDEFGHJKLMNPQRSTUVWXYZabcdefghjklmnopqrstuvwxyz23456789";
srand((double)microtime()*1000000);
$i = 0;
$pass = '' ;
while ($i <= 4)
{
$num = rand() % 32;
$tmp = substr($chars, $num, 1);
$pass = $pass . $tmp;
$i++;
}
return $pass;
}
?>
The script that had the function in it (where I now have the "require_once" call):
<?php
/*******************************************
My Form Processor
Cobbled from all over
*******************************************/
extract($_POST);
$host = $_SERVER[HTTP_HOST ];
$path = pathinfo($_SERVER['PHP_SELF']);
$file_path = $path['dirname'];
/*******************************************
Set all variables
*******************************************/
//Email address form will be sent to
$sendto_email = "heather@cathyheather.net";
// Disable email addresses from the same domain as your email from being sent?
// This will often reduce spam but will not allow anyone to send from anything@yourdomain.
$checkdomain = "yes";
// Language variables
$lang_title = "Send an email";
$lang_notice = "Fill in the form to contact us by email. Required fields are shown in bold.";
$lang_name = "Your name:";
$lang_email = "Your email:";
$lang_phone = "Your phone:";
$lang_subject = "Subject:";
$lang_message = "Comments:";
$lang_checkbox = "Please contact me as soon as possible regarding this matter.";
$lang_confirmation = "Please enter validation code(it is case sensitive):";
$lang_submit = "Send email";
// Error messages
$lang_error = "Your comments were not submitted. Please correct the following errors:";
$lang_noemail = "You did not enter your email address.";
$lang_nocode = "You did not enter the validation code.";
$lang_wrongcode = "You entered the validation code incorrectly. Please note that it is case sensitive";
$lang_invalidemail = "The email address that you entered appears to be invalid";
// Success
$lang_sent = "Thank you for your comments.<br />The following message was submitted:";
/*******************************************
Validate the form
In this case, just checking for email and
validation code.
*******************************************/
//check for empty email
if (empty ($senders_email))
{
$error = "1";
$info_error .= $lang_noemail . "<br />";
}
//check for invalid email address
if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,6}$", $senders_email))
{
$error = "1";
$info_error .= $lang_invalidemail . "<br />";
}
//check to see if security code is entered
if (empty ($security_code))
{
$error = "1";
$info_error .= $lang_nocode . "<br />";
}
//check to make sure code entered correctly
elseif ($security_code != $randomness)
{
$error = "1";
$info_error .= $lang_wrongcode . "<br />";
}
//if errors were found, display them
if ($error == "1")
{
$info_notice = "<span style=\"color: " . $error_colour . "; font-weight: bold;\">" . $lang_error . "</span><br />";
if (empty ($submit))
{
$info_error = "";
$info_notice = $lang_notice;
}
require_once("random.php"); //this is the problem section
$random_code = random();
$mail_message = stripslashes($mail_message);
//display the form
print "
<form name=\"contact\" method=\"post\" action=\"\">
<p>$info_notice$info_error</p>
<fieldset>
<legend>Tell us how to get in touch with you:</legend>
<label for=\"name\">$lang_name</label>
<input type=\"text\" id=\"senders_name\" name=\"senders_name\" accesskey=\"n\" tabindex=\"1\" title=\"your name\" value=\"$senders_name\" /><br />
<label for=\"email\" class=\"required\">$lang_email</label>
<input type=\"text\" id=\"senders_email\" name=\"senders_email\" accesskey=\"e\" tabindex=\"2\" title=\"your email\" value=\"$senders_email\" /><br />
<label for=\"phone\">$lang_phone</label>
<input type=\"text\" id=\"phone\" name=\"phone\" accesskey=\"p\" tabindex=\"3\" title=\"your phone\" value=\"$senders_phone\" /><br />
</fieldset>
<p> </p>
<fieldset>
<legend>Enter your comments in the space provided:</legend>
<label for=\"comments\">$lang_message</label>
<textarea name=\"mail_message\" rows=\"5\" cols=\"23\" id=\"mail_message\" accesskey=\"c\" tabindex=\"4\" title=\"mail_message\">$mail_message</textarea><br />
<input class=\"checkbox\" type=\"checkbox\" name=\"contact_me\" value=\"$contact_me\" id=\"contact_me\" accesskey=\"x\" tabindex=\"5\" title=\"Contact Me\" /> $lang_checkbox
</fieldset>
<p>$lang_confirmation</p>
<input name=\"security_code\" type=\"text\" id=\"security_code\" size=\"5\" />
<strong>$random_code</strong>
<input name=\"randomness\" type=\"hidden\" id=\"randomness\" value=\"$random_code\" />
<input name=\"submit\" type=\"submit\" id=\"submit\" value=\"$lang_submit\" />
</form>";
}
else
{
if ($checkdomain == "yes")
{
$sender_domain = substr($senders_email, (strpos($senders_email, '@')) +1);
$recipient_domain = substr($sendto_email, (strpos($sendto_email, '@')) +1);
if ($sender_domain == $recipient_domain)
{
print "Sorry, you cannot send messages from this domain ($sender_domain)";
exit;
}
}
if(isset($contact_me)){ // Check to see if the checkbox is checked
$contact_me = "$lang_checkbox";
}
else {
$contact_me = " I do not want to be contacted. ";
}
$info_notice = $lang_sent;
$mail_message = stripslashes($mail_message);
$senders_email = preg_replace("/[^a-zA-Z0-9s.@-]/", " ", $senders_email);
$senders_name = preg_replace("/[^a-zA-Z0-9s]/", " ", $senders_name);
$headers = "From: $senders_name <$senders_email> \r\n";
$headers .= "X-Mailer: BELLonline.co.uk PHP mailer \r\n";
// mail($sendto_email, $mail_subject, $mail_message, $headers);
print "
<p>$info_notice</p>
<p><em>$lang_name</em> $senders_name</p>
<p><em>$lang_email</em> $senders_email</p>
<p><em>$lang_subject</em> Contact Form Submission</p>
<p><em>$lang_message</em><br /> $mail_message</p>
<p>$contact_me</p>
";
}
?>
As I said, I have modified the script to suit my particular needs. What I do know is that if I paste the entire function into the same location as the "require_once" statement, the whole thing works. The error comes when I extract the function and put it in a separate file.
(My head hurts from all this new stuff I'm trying to cram into it!!!! :queasy: