Hello Ernie, thanks so much for the quick response and new code.
Just another questions, will I be able to implement the new code provided by you into the php script that I downloaded from EasyPHP? They do have a non SMTP script with CAPTCHA but it still calls the mail() handler. When I use that one it throws an error at me stating it couldn’t initiate the mail function?
Or am I just going to have to build a new HTML form that fits those variables?
I know this is long, but I’ve included the PHP code from the non SMTP version. The script also builds the form for you… Just wondering if I could take the script provided by you and somehow tweak it in this one… If not, could you provide me with a link to a good tutorial to build my own form page where I can customize the name, email, subject and message body to my liking. I have a page background that is blackish white.
Thanks again for you help!
[php]
require “formfiles/contact-config.php”;
$error_message = ‘’;
if (!isset($_POST[‘submit’])) {
showForm();
} else { //form submitted
$error = 0;
if(!empty($_POST[‘name’])) {
$name[2] = clean_var($_POST[‘name’]);
}
else {
$error = 1;
$name[3] = ‘color:#FF0000;’;
}
if(!empty($_POST[‘email’])) {
$email[2] = clean_var($_POST[‘email’]);
if (!validEmail($email[2])) {
$error = 1;
$email[3] = ‘color:#FF0000;’;
$email[4] = ‘Invalid email’;
}
}
else {
$error = 1;
$email[3] = ‘color:#FF0000;’;
}
if(!empty($_POST[‘subject’])) {
$subject[2] = clean_var($_POST[‘subject’]);
if (function_exists(‘htmlspecialchars’)) $subject[2] = htmlspecialchars($subject[2], ENT_QUOTES);
}
else {
$error = 1;
$subject[3] = ‘color:#FF0000;’;
}
if(!empty($_POST[‘message’])) {
$message[2] = clean_var($_POST[‘message’]);
if (function_exists(‘htmlspecialchars’)) $message[2] = htmlspecialchars($message[2], ENT_QUOTES);
}
else {
$error = 1;
$message[3] = ‘color:#FF0000;’;
}
if(empty($_POST[‘captcha_code’])) {
$error = 1;
$code[3] = ‘color:#FF0000;’;
} else {
include_once “formfiles/contact-securimage.php”;
$securimage = new Securimage();
$valid = $securimage->check($_POST[‘captcha_code’]);
if(!$valid) {
$error = 1;
$code[3] = 'color:#FF0000;';
$code[4] = '<strong><span style="color:#FF0000;">Incorrect code</span></strong>';
}
}
if ($error == 1) {
$error_message = ‘
Please correct/enter field(s) in red.
’;
showForm();
} else {
if (function_exists('htmlspecialchars_decode')) $subject[2] = htmlspecialchars_decode($subject[2], ENT_QUOTES);
if (function_exists('htmlspecialchars_decode')) $message[2] = htmlspecialchars_decode($message[2], ENT_QUOTES);
$body = "$name[0]: $name[2]\r\n\r\n";
$body .= "$email[0]: $email[2]\r\n\r\n";
$body .= "$message[0]:\r\n$message[2]\r\n\r\n";
if (!$from) $from_value = $email[2];
else $from_value = $from;
require_once('formfiles/class.phpmailer.php');
$mail = new PHPMailer();
$mail->SetFrom($from_value);
$mail->AddReplyTo($email[2]);
$mail->Subject = "$subject_prefix - $subject[2]";
$mail->Body = $body;
$mail->AddAddress($to);
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
}
if (!$thank_you_url) {
if ($use_header_footer) include $header_file;
echo '<a name="cform"><!--Form--></a>'."\n";
echo '<div id="formContainer" style="width:'.$form_width.';height:'.$form_height.';text-align:left; vertical-align:top;">'."\n";
echo $GLOBALS['thank_you_message']."\n";
echo '</div>'."\n";
if ($use_header_footer) include $footer_file;
}
else {
header("Location: $thank_you_url");
}
session_unset();
session_destroy();
}
} //else submitted
function showForm()
{
global $name, $email, $subject, $message, $code;
global $where_included, $use_header_footer, $header_file, $footer_file;
global $form_width, $form_height, $form_background, $form_border_color, $form_border_width, $form_border_style, $cell_padding, $left_col_width;
if ($use_header_footer) include $header_file;
echo <<<EOD
{$GLOBALS['error_message']}
{$name[0]} |
|
{$email[0]} |
{$email[4]} |
{$subject[0]} |
|
{$message[0]} |
{$message[2]} |
|
|
{$code[0]} |
{$code[4]}
(Please enter the text in the image above. Text is not case sensitive.)
Click here if you cannot recognize the code.
|
All fields are required. |
|
EOD;
if ($use_header_footer) include $footer_file;
}
function clean_var($variable) {
$variable = strip_tags(stripslashes(trim(rtrim($variable))));
return $variable;
}
/**
Email validation function. Thanks to http://www.linuxjournal.com/article/9585
/
function validEmail($email)
{
$isValid = true;
$atIndex = strrpos($email, “@”);
if (is_bool($atIndex) && !$atIndex)
{
$isValid = false;
}
else
{
$domain = substr($email, $atIndex+1);
$local = substr($email, 0, $atIndex);
$localLen = strlen($local);
$domainLen = strlen($domain);
if ($localLen < 1 || $localLen > 64)
{
// local part length exceeded
$isValid = false;
}
else if ($domainLen < 1 || $domainLen > 255)
{
// domain part length exceeded
$isValid = false;
}
else if ($local[0] == ‘.’ || $local[$localLen-1] == ‘.’)
{
// local part starts or ends with ‘.’
$isValid = false;
}
else if (preg_match(’/\.\./’, $local))
{
// local part has two consecutive dots
$isValid = false;
}
else if (!preg_match(’/^[A-Za-z0-9\-\.]+$/’, $domain))
{
// character not valid in domain part
$isValid = false;
}
else if (preg_match(’/\.\./’, $domain))
{
// domain part has two consecutive dots
$isValid = false;
}
else if (!preg_match(’/^(\\.|[A-Za-z0-9!#%&`_=\/$’+?^{}|~.-])+$/’, str_replace("\\","",$local)))
{
// character not valid in local part unless
// local part is quoted
if (!preg_match(’/^"(\\"|[^"])+"$/’,
str_replace("\\","",$local)))
{
$isValid = false;
}
}
if ($isValid && function_exists(‘checkdnsrr’))
{
if (!(checkdnsrr($domain,“MX”) || checkdnsrr($domain,“A”))) {
// domain not found in DNS
$isValid = false;
}
}
}
return $isValid;
}
?>[/php]