I created a contact form in DW CS4. I downloaded software from bebosoft.com in order to obtain a .php script to send the form to the specified email address. So I uploaded both the html contact form and the php script to the server. I also inserted the php file in the "Action" field too. But now when I "test" it out so to speak and hit the "submit" button nothing happens. There is no indication that anything is happening and no email is received. Can someone take a look at my page and see if there is any problems in the code? I'm not a coder and don't know php so if someone who's more experienced in this area could point me in the right direction I'd sure appreciate it. Thanks!
Oh I removed the "validation" messages because it was showing up when the browser refreshed so I removed them so they wouldn't show up. But now I'd like to put them back in and don't know how. But I guess that's a separate issue altogether.
Here's the link to the page I'm referring to:
http://www.sperryinteriors.com/contact.html
Thanks,
ashmic
I'm pasting a basic contact form into this post. Copy & paste code into a new, blank html document. Adjust path in form to where your script is located. SaveAs test.html and upload to your remote server to test it. Let us know how you make out.
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Sample Form</title>
<style type="text/css">
/**BEGIN FORM STYLES**/
#form1 {
font-size: 14px;
width: 500px;
margin: 0 auto; /**centered**/
background: #FFF;
border: 2px groove green;
padding: 7px 14px 7px 14px;}
fieldset {
margin-bottom:5px;
border-right:none;
border-bottom:none;
border-left:none;
}
legend {
padding: 8px;
border: 1px solid silver;
background: #009900;
font-weight: bold;
color: #FFFFFF;
margin-left: -75px;
*margin-left:0;
line-height: 1.5
}
/**wrap form lables and fields inside ordered lists for better web accessibility**/
#form1 ol {
list-style:none;
margin:0;
padding:0}
#form1 li {
padding:5px;
margin: 0;
clear: left;
}
label{
display:inline-block;
float:left;
line-height: 23px; /**lines up labels with fields**/
width:167px;
font-size: 12px;
color: #666;
text-align:right;
margin-right: 10px; /*space between labels, fields*/
}
input[type=text],
textarea {
width: 190px; /**same width on text fields**/
padding: 5px;
color: #666;
border: 1px dotted #009900;
font-family:Arial, Helvetica, sans-serif;
font-size: 12px;
}
/**field background on focus**/
input:focus,
input:active,
textarea:focus,
textarea:active
{background-color: #EBECDE; border: 1px solid;}
#submit {
margin-left: 45px;
background: #009900;
font-size: 18px;
color:#FFF;
font-weight: bold;
border: 2px outset #FFF}
#submit:hover,
#submit:focus,
#submit:active {
background: #006600;
color: yellow;
border: 2px inset #FFF}
/**END FORM STYLES**/
</style>
</head>
<body>
<!--BEGIN HTML FORM, action="path to form-processing script on your server" -->
<form action="vsi.php" method="post" enctype="multipart/form-data" id="form1" name="form1">
<h3>HTML Contact Form</h3>
<fieldset>
<legend>Required Fields:</legend>
<ol>
<li>
<label for="first">First:</label>
<input name="first" id="first" type="text" />
</li>
<li>
<label for="last">Last:</label>
<input name="last" id="last" type="text" />
</li>
<li>
<label for="email">E-mail:</label>
<input name="email" id="email" type="text" />
</li>
</ol>
</fieldset>
<fieldset>
<legend>Optional Fields:</legend>
<ol>
<li>
<label for="phone">Phone:</label>
<input name="phone" id="phone" type="text" />
</li>
<li>
<label for="fax">Fax:</label>
<input name="fax" id="fax" type="text" />
</li>
<li>
<label for="subject">Subject:</label>
<input name="subject" id="subject" type="text" />
</li>
<li>
<label for="message">Message:</label>
<textarea name="message"></textarea>
</li>
<li>
<label for="submit"> </label>
<input type="submit" name="submit" id="submit" value="Submit" />
</li>
</ol>
</fieldset>
</form>
<!--END OF FORM -->
</body>
</html>
Nancy O.
Alt-Web Design & Publishing
Web | Graphics | Print | Media Specialists
I created a new HTML doc like you said and pasted the form you gave me (thanks for that by the way). I uploaded it to the server and when I hit submit I got the following error message:
Errors Found: Email Address does not match above email address. Incorrect format.
I know in my original form I created (which shouldn't even be in the mix since I have a new form that you provided) I had a box to retype your email address could that be causing the problem? Or I'm wondering if maybe I have the receiving email address (the one the emails will be sent to) in the wrong spot on my vsi.php form. Should it be in the $emailTo = 'Vickie <vickie@sperryinteriors.com>'; or should it be put here in the $emailFrom = FilterCChars("yourname@yourname.com");
There must be something not syncing up between this new form (test.html) and my vsi.php script. Any ideas what might be causing this?
Thanks for the help!
ashmic
Nancy O-
Here's my PHP code. Thanks for the help! I really appreciate it!
ashmic
<?PHP
######################################################
# #
# Forms To Go Lite 4.5.4 #
# http://www.bebosoft.com/ #
# #
######################################################
define('kOptional', true);
define('kMandatory', false);
define('kStringRangeFrom', 1);
define('kStringRangeTo', 2);
define('kStringRangeBetween', 3);
define('kYes', 'yes');
define('kNo', 'no');
error_reporting(E_ERROR | E_WARNING | E_PARSE);
ini_set('track_errors', true);
function DoStripSlashes($fieldValue) {
// temporary fix for PHP6 compatibility - magic quotes deprecated in PHP6
if ( function_exists( 'get_magic_quotes_gpc' ) && get_magic_quotes_gpc() ) {
if (is_array($fieldValue) ) {
return array_map('DoStripSlashes', $fieldValue);
} else {
return trim(stripslashes($fieldValue));
}
} else {
return $fieldValue;
}
}
function FilterCChars($theString) {
return preg_replace('/[\x00-\x1F]/', '', $theString);
}
function CheckString($value, $low, $high, $mode, $limitAlpha, $limitNumbers, $limitEmptySpaces, $limitExtraChars, $optional) {
$regEx = '';
if ($limitAlpha == kYes) {
$regExp = 'A-Za-z';
}
if ($limitNumbers == kYes) {
$regExp .= '0-9';
}
if ($limitEmptySpaces == kYes) {
$regExp .= ' ';
}
if (strlen($limitExtraChars) > 0) {
$search = array('\\', '[', ']', '-', '$', '.', '*', '(', ')', '?', '+', '^', '{', '}', '|', '/');
$replace = array('\\\\', '\[', '\]', '\-', '\$', '\.', '\*', '\(', '\)', '\?', '\+', '\^', '\{', '\}', '\|', '\/');
$regExp .= str_replace($search, $replace, $limitExtraChars);
}
if ( (strlen($regExp) > 0) && (strlen($value) > 0) ){
if (preg_match('/[^' . $regExp . ']/', $value)) {
return false;
}
}
if ( (strlen($value) == 0) && ($optional === kOptional) ) {
return true;
} elseif ( (strlen($value) >= $low) && ($mode == kStringRangeFrom) ) {
return true;
} elseif ( (strlen($value) <= $high) && ($mode == kStringRangeTo) ) {
return true;
} elseif ( (strlen($value) >= $low) && (strlen($value) <= $high) && ($mode == kStringRangeBetween) ) {
return true;
} else {
return false;
}
}
function CheckEmail($email, $optional) {
if ( (strlen($email) == 0) && ($optional === kOptional) ) {
return true;
} elseif ( preg_match("/^([\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+\.)*[\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+@((((([a-z0-9]{1}[a-z0-9\-]{0,62}[a-z0-9]{1})|[a-z])\.)+[a-z]{2,6})|(\d{1,3}\.){3}\d{1,3}(\:\d{1,5})?)$/i", $email) == 1 ) {
return true;
} else {
return false;
}
}
function CheckEqualTo($original, $repeated) {
if ($original == $repeated) {
return true;
} else {
return false;
}
}
function CheckTelephone( $telephone, $valFormat, $optional ) {
if ( (strlen( $telephone ) == 0 ) && ( $optional === kOptional ) ) {
return true;
} elseif ( preg_match( $valFormat, $telephone ) == 1 ) {
return true;
} else {
return false;
}
}
if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$clientIP = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$clientIP = $_SERVER['REMOTE_ADDR'];
}
$FTGfirstname = DoStripSlashes( $_POST['firstname'] );
$FTGlastname = DoStripSlashes( $_POST['lastname'] );
$FTGemail = DoStripSlashes( $_POST['email'] );
$FTGvalidateEmail = DoStripSlashes( $_POST['validateEmail'] );
$FTGphonenum = DoStripSlashes( $_POST['phonenum'] );
$FTGsubject = DoStripSlashes( $_POST['subject'] );
$FTGmessage = DoStripSlashes( $_POST['message'] );
$FTGsubmit = DoStripSlashes( $_POST['submit'] );
$validationFailed = false;
# Fields Validations
if (!CheckString($FTGfirstname, 3, 36, kStringRangeBetween, kNo, kNo, kNo, '', kMandatory)) {
$FTGErrorMessage['firstname'] = '';
$validationFailed = true;
}
if (!CheckString($FTGlastname, 3, 36, kStringRangeBetween, kNo, kNo, kNo, '', kMandatory)) {
$FTGErrorMessage['lastname'] = '';
$validationFailed = true;
}
if (!CheckEmail($FTGemail, kMandatory)) {
$FTGErrorMessage['email'] = 'Incorrect email format.';
$validationFailed = true;
}
if (!CheckEqualTo($FTGvalidateEmail, $FTGemail)) {
$FTGErrorMessage['validateEmail'] = 'Email address doesn\'t match above email address.';
$validationFailed = true;
}
if (!CheckTelephone($FTGphonenum, '/\([0-9]{3}\)[0-9]{3}\-[0-9]{4}/', kMandatory)) {
$FTGErrorMessage['phonenum'] = 'Incorrect format';
$validationFailed = true;
}
if (!CheckString($FTGmessage, 1, 400, kStringRangeBetween, kNo, kNo, kNo, '', kMandatory)) {
$FTGErrorMessage['message'] = '';
$validationFailed = true;
}
# Include message in error page and dump it to the browser
if ($validationFailed === true) {
$errorPage = '<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><title>Error</title></head><body>Errors found: <!--VALIDATIONERROR--></body></html>';
$errorPage = str_replace('<!--FIELDVALUE:firstname-->', $FTGfirstname, $errorPage);
$errorPage = str_replace('<!--FIELDVALUE:lastname-->', $FTGlastname, $errorPage);
$errorPage = str_replace('<!--FIELDVALUE:email-->', $FTGemail, $errorPage);
$errorPage = str_replace('<!--FIELDVALUE:validateEmail-->', $FTGvalidateEmail, $errorPage);
$errorPage = str_replace('<!--FIELDVALUE:phonenum-->', $FTGphonenum, $errorPage);
$errorPage = str_replace('<!--FIELDVALUE:subject-->', $FTGsubject, $errorPage);
$errorPage = str_replace('<!--FIELDVALUE:message-->', $FTGmessage, $errorPage);
$errorPage = str_replace('<!--FIELDVALUE:submit-->', $FTGsubmit, $errorPage);
$errorPage = str_replace('<!--ERRORMSG:email-->', $FTGErrorMessage['email'], $errorPage);
$errorPage = str_replace('<!--ERRORMSG:validateEmail-->', $FTGErrorMessage['validateEmail'], $errorPage);
$errorPage = str_replace('<!--ERRORMSG:phonenum-->', $FTGErrorMessage['phonenum'], $errorPage);
$errorList = @implode("<br />\n", $FTGErrorMessage);
$errorPage = str_replace('<!--VALIDATIONERROR-->', $errorList, $errorPage);
echo $errorPage;
}
if ( $validationFailed === false ) {
# Email to Form Owner
$emailSubject = FilterCChars("$FTGsubject");
$emailBody = "You've received an email via your contact form on sperryinteriors.com below are the details of that message. Now the balls in your court to contact them back!\r\n"
. "\r\n"
. "firstname : $FTGfirstname\r\n"
. "lastname : $FTGlastname\r\n"
. "email : $FTGemail\r\n"
. "phonenum : $FTGphonenum\r\n"
. "\r\n"
. "message : $FTGmessage\r\n"
. "";
$emailTo = 'Vickie <vickie@sperryinteriors.com>';
$emailFrom = FilterCChars("yourname@yourname.com");
$emailHeader = "From: $emailFrom\r\n"
. "MIME-Version: 1.0\r\n"
. "Content-type: text/plain; charset=\"UTF-8\"\r\n"
. "Content-transfer-encoding: 8bit\r\n";
mail($emailTo, $emailSubject, $emailBody, $emailHeader);
# Include message in the success page and dump it to the browser
$successPage = '<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><title>Success</title></head><body>Thank you for contacting Vickie Sperry Interiors. The form was submitted successfully. You will be contacted shortly!</body></html>';
$successPage = str_replace('<!--FIELDVALUE:firstname-->', $FTGfirstname, $successPage);
$successPage = str_replace('<!--FIELDVALUE:lastname-->', $FTGlastname, $successPage);
$successPage = str_replace('<!--FIELDVALUE:email-->', $FTGemail, $successPage);
$successPage = str_replace('<!--FIELDVALUE:validateEmail-->', $FTGvalidateEmail, $successPage);
$successPage = str_replace('<!--FIELDVALUE:phonenum-->', $FTGphonenum, $successPage);
$successPage = str_replace('<!--FIELDVALUE:subject-->', $FTGsubject, $successPage);
$successPage = str_replace('<!--FIELDVALUE:message-->', $FTGmessage, $successPage);
$successPage = str_replace('<!--FIELDVALUE:submit-->', $FTGsubmit, $successPage);
echo $successPage;
}
?>Let's start over. Here is the PHP code. SaveAs vsi2.php and upload to your server.
<?php
////////////////////////////////////////////////////////////////////////////
// Form Processing Script
////////////////////////////////////////////////////////////////////////////
// General Variables
$check_referrer="no";
$referring_domains="http://domain.com/,http://www.domain.com/,http://subdomain.domain.com/";
// options to use if hidden field "config" has a value of 0
// recipient info
$charset[0]="iso-8859-1";
$tomail[0]="vickie@sperryinteriors.com";
$cc_tomail[0]=" ";
$bcc_tomail[0]="";
// Mail contents config
$subject[0]="message from SPERRY INTERIORS.COM";
$reply_to_field[0]="email";
$reply_to_name[0]="email";
$required_fields[0]="first_name,last_name";
$required_email_fields[0]="email";
$attachment_fields[0]="";
$return_ip[0]="yes";
$mail_intro[0]="The following message was sent from SPERRY INTERIORS.COM:";
$mail_fields[0]="first_name,last_name,email,phone,subject,message";
$mail_type[0]="text";
$mail_priority[0]="1";
$allow_html[0]="no";
// Send back to sender config
$send_copy[0]="yes";
$copy_format[0]="vert_table";
$copy_fields[0]="first_name,last_name,subject,message";
$copy_attachment_fields[0]="";
$copy_subject[0]="SPERRY INTERIORS automated reply";
$copy_intro[0]="Thanks for taking time to contact Sperry Interiors. Someone will be in touch with you soon.";
$copy_from[0]="noreply@sperryinteriors.com";
$copy_tomail_field[0]="email";
// Result options
$header[0]="";
$footer[0]="";
$error_page[0]="";
$thanks_page[0]="";
// Default Error and Success Page Variables
$error_page_title[0]="Error - Missing Fields";
$error_page_text[0]="Required information is missing. Please use your browser's back button to return to the form and complete the required fields.";
$thanks_page_title[0]="Success - Form processing completed";
$thanks_page_text[0]="Thank you. Please check your e-mail for an automated confirmation. ";
// Antispam Options
$empty_field[0]="nospam";
$character_scan[0]="message";
$time_delay[0]="";
$captcha_codes[0]="9C2449,EEADC8,77A585,D72838";
$max_urls[0]="1";
$max_url_fields[0]="message";
$flag_spam[0]="";
/////////////////////////////////////////////////////////////////////////
// Don't muck around past this line unless you know what you are doing //
/////////////////////////////////////////////////////////////////////////
ob_start();
$config=$_POST["config"];
$debug=0;
$debug_text="";
// fix for Windows email server security
ini_set("sendmail_from",$tomail[$config]);
// email validation regular expression
$regex = "^[-a-z0-9!#$%&\'*+/=?^_`{|}~]+(\.[-a-z0-9!#$%&\'*+/=?^_`{|}~]+)*@(([a-z0-9]([-a-z0-9]*[a-z0-9]+)?){1,63}\.)+([a-z]([-a-z0-9]*[a-z0-9]+)?){2,63}$";
$header_injection_regex = "(\r|\n)";
if($header[$config]!="")
include($header[$config]);
if($_POST["submit"] || $_POST["Submit"] || $_POST["submit_x"] || $_POST["Submit_x"])
{
////////////////////////////
// begin global functions //
////////////////////////////
// get visitor IP
function getIP()
{
if(getenv(HTTP_X_FORWARDED_FOR))
$user_ip=getenv("HTTP_X_FORWARDED_FOR");
else
$user_ip=getenv("REMOTE_ADDR");
return $user_ip;
}
// get value of given key
function parseArray($key)
{
$array_value=$_POST[$key];
$count=1;
extract($array_value);
foreach($array_value as $part_value)
{
if($count > 1){$value.=", ";}
$value.=$part_value;
$count=$count+1;
}
return $value;
}
// stripslashes and autolink url's
function parseValue($value)
{
$value=preg_replace("/(http:\/\/+.[^\s]+)/i",'<a href="\\1">\\1</a>', $value);
return $value;
}
// html header if used
function htmlHeader()
{
$htmlHeader="<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\">\n<html>\n<head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=".$charset[$config]."\"></head>\n<body>\n<table cellpadding=\"2\" cellspacing=\"0\" border=\"0\" width=\"600\">\n";
return $htmlHeader;
}
// html footer if used
function htmlFooter()
{
$htmlFooter="</table>\n</body>\n</html>\n";
return $htmlFooter;
}
// build verticle table format
function buildVertTable($fields, $intro, $to, $send_ip)
{
$message=htmlHeader();
if($intro != "")
$message.="<tr>\n<td align=\"left\" valign=\"top\" colspan=\"2\">".$intro."</td>\n</tr>\n";
$fields_check=preg_split('/,/',$fields);
$run=sizeof($fields_check);
for($i=0;$i<$run;$i++)
{
$cur_key=$fields_check[$i];
$cur_value=$_POST[$cur_key];
if(is_array($cur_value))
{
$cur_value=parseArray($cur_key);
}
$cur_value=parseValue($cur_value);
if($allow_html[$config]=="no")
$cur_value=htmlspecialchars(nl2br($cur_value));
else
$cur_value=nl2br($cur_value);
$message.="<tr>\n<td align=\"left\" valign=\"top\" style=\"white-space:nowrap;\"><b>".$cur_key."</b></td>\n<td align=\"left\" valign=\"top\" width=\"100%\">".$cur_value."</td>\n</tr>\n";
}
if($send_ip=="yes" && $to=="recipient")
{
$user_ip=getIP();
$message.="<tr>\n<td align=\"left\" valign=\"top\" style=\"white-space:nowrap;\"><b>Sender IP</b></td>\n<td align=\"left\" valign=\"top\" width=\"100%\">".$user_ip."</td>\n</tr>\n";
}
$message.=htmlFooter();
return $message;
}
// build horizontal table format
function buildHorzTable($fields, $intro, $to, $send_ip)
{
$message=htmlHeader();
$fields_check=preg_split('/,/',$fields);
$run=sizeof($fields_check);
if($intro != "")
$message.="<tr>\n<td align=\"left\" valign=\"top\" colspan=\"".$run."\">".$intro."</td>\n</tr>\n";
$message.="<tr>\n";
for($i=0;$i<$run;$i++)
{
$cur_key=$fields_check[$i];
$message.="<td align=\"left\" valign=\"top\" style=\"white-space:nowrap;\"><b>".$cur_key."</b></td>\n";
}
if($send_ip=="yes" && $to=="recipient")
$message.="<td align=\"left\" valign=\"top\" style=\"white-space:nowrap;\"><b>Sender IP</b></td>\n";
$message.="</tr>\n";
$message.="<tr>\n";
for($i=0;$i<$run;$i++)
{
$cur_key=$fields_check[$i];
$cur_value=$_POST[$cur_key];
if(is_array($cur_value))
{
$cur_value=parseArray($cur_key);
}
$cur_value=parseValue($cur_value);
if($allow_html[$config]=="no")
$cur_value=htmlspecialchars(nl2br($cur_value));
else
$cur_value=nl2br($cur_value);
$message.="<td align=\"left\" valign=\"top\">".$cur_value."</td>\n";
}
$message.="</tr>\n";
$message.="<tr>\n";
if($send_ip=="yes" && $to=="recipient")
{
$user_ip=getIP();
$message.="<td align=\"left\" valign=\"top\">".$user_ip."</td>\n";
}
$message.="</tr>\n";
$message.=htmlFooter();
return $message;
}
// build plain text format
function buildTextTable($fields, $intro, $to, $send_ip)
{
$message="";
if($intro != "")
$message.=$intro."\n\n";
$fields_check=preg_split('/,/',$fields);
$run=sizeof($fields_check);
for($i=0;$i<$run;$i++)
{
$cur_key=$fields_check[$i];
$cur_value=$_POST[$cur_key];
if(is_array($cur_value))
{
$cur_value=parseArray($cur_key);
}
$cur_value=parseValue($cur_value);
if($allow_html[$config]=="no")
$cur_value=htmlspecialchars($cur_value);
else
$cur_value=$cur_value;
$message.="".$cur_key.": ".$cur_value."\n";
}
if($send_ip=="yes" && $to=="recipient")
{
$user_ip=getIP();
$message.="Sender IP: ".$user_ip."\n";
}
return $message;
}
// get the proper build fonction
function buildTable($format, $fields, $intro, $to, $send_ip)
{
if($format=="vert_table")
$message=buildVertTable($fields, $intro, $to, $send_ip);
else if($format=="horz_table")
$message=buildHorzTable($fields, $intro, $to, $send_ip);
else
$message=buildTextTable($fields, $intro, $to, $send_ip);
return $message;
}
// referrer checking security option
function checkReferer()
{
if($check_referrer=="yes")
{
$ref_check=preg_split('/,/',$referring_domains);
$ref_run=sizeof($ref_check);
$referer=$_SERVER['HTTP_REFERER'];
$domain_chk="no";
for($i=0;$i<$ref_run;$i++)
{
$cur_domain=$ref_check[$i];
if(stristr($referer,$cur_domain)){$domain_chk="yes";}
}
}
else
{
$domain_chk="yes";
}
return $domain_chk;
}
// checking required fields and email fields
function checkFields($text_fields, $email_fields, $regex)
{
$error_message="";
if($debug==1)
$error_message.="<li>text_fields: ".$text_fields."<br />email_fields: ".$email_fields."<br />reply_to_field: ".$reply_to_field."<br />reply_to_name: ".reply_to_name."</li>";
if($text_fields != "")
{
$req_check=preg_split('/,/',$text_fields);
$req_run=sizeof($req_check);
for($i=0;$i<$req_run;$i++)
{
$cur_field_name=$req_check[$i];
$cur_field=$_POST[$cur_field_name];
if($cur_field=="")
{
$error_message.="<li>You are missing the <b>".$req_check[$i]."</b> field</li>\n";
}
}
}
if($email_fields != "")
{
$email_check=preg_split('/,/',$email_fields);
$email_run=sizeof($email_check);
for($i=0;$i<$email_run;$i++)
{
$cur_email_name=$email_check[$i];
$cur_email=$_POST[$cur_email_name];
if($cur_email=="" || !eregi($regex, $cur_email))
{
$error_message.="<li>You are missing the <b>".$email_check[$i]."</b> field or it is not a valid email address.</li>\n";
}
}
}
return $error_message;
}
// attachment function
function getAttachments($attachment_fields, $message, $content_type, $border)
{
$att_message="This is a multi-part message in MIME format.\r\n";
$att_message.="--{$border}\r\n";
$att_message.=$content_type."\r\n";
$att_message.="Content-Transfer-Encoding: 7bit\r\n\r\n";
$att_message.=$message."\r\n\r\n";
$att_check=preg_split('/,/',$attachment_fields);
$att_run=sizeof($att_check);
for($i=0;$i<$att_run;$i++)
{
$fileatt=$_FILES[$att_check[$i]]['tmp_name'];
$fileatt_name=$_FILES[$att_check[$i]]['name'];
$fileatt_type=$_FILES[$att_check[$i]]['type'];
if (is_uploaded_file($fileatt))
{
$file=fopen($fileatt,'rb');
$data=fread($file,filesize($fileatt));
fclose($file);
$data=chunk_split(base64_encode($data));
$att_message.="--{$border}\n";
$att_message.="Content-Type: {$fileatt_type}; name=\"{$fileatt_name}\"\r\n";
$att_message.="Content-Disposition: attachment; filename=\"{$fileatt_name}\"\r\n";
$att_message.="Content-Transfer-Encoding: base64\r\n\r\n".$data."\r\n\r\n";
}
}
$att_message.="--{$border}--\n";
return $att_message;
}
// function to set content type
function contentType($charset, $format)
{
if($format=="vert_table")
$content_type="Content-type: text/html; charset=".$charset."\r\n";
else if($format=="horz_table")
$content_type="Content-type: text/html; charset=".$charset."\r\n";
else
$content_type="Content-type: text/plain; charset=".$charset."\r\n";
return $content_type;
}
//////////////////////////
// end global functions //
//////////////////////////
////////////////////////////////
// begin procedural scripting //
////////////////////////////////
// anti-spam empty field check
if($_POST[$empty_field[$config]] != "")
{
$empty_message = "<li>This submission failed and was flagged as spam.</li>\n";
}
// anti-spam character scan check
if(strlen($character_scan[$config]) > 0)
{
$spam_message="";
$field_check=preg_split('/,/',$character_scan[$config]);
$field_run=sizeof($field_check);
for($i=0;$i<$field_run;$i++)
{
$cur_field_name=$field_check[$i];
$cur_field=$_POST[$cur_field_name];
if(preg_match("/<(.|\n)+?>/", $cur_field) || preg_match("/\[(.|\n)+?\]/", $cur_field))
$spam_message.="<li>This message contains disallowed characters.</li>\n";
}
}
// anti-spam time delay check
if((strlen($time_delay[$config]) > 0 && strlen($_POST["time"]) > 0) || (strlen($time_delay[$config]) > 0 && (strlen($_POST["time"]) == 0 || !$_POST["time"])))
{
if((time() - $_POST["time"]) < $time_delay[$config])
$time_message = "<li>This has been stopped by the timer, and is likely spam.</li>\n";
}
// anti-spam CAPTCHA check
if(strlen($captcha_codes[$config]) > 0)
{
$captcha_check=preg_split('/,/',$captcha_codes[$config]);
if(strtolower($_POST["captcha_entry"]) != strtolower($captcha_check[$_POST["captcha_code"]]))
$captcha_message = "<li>CAPTCHA test did not match.</li>\n";
}
// anti-spam max URL check
if(strlen($max_url_fields[$config]) > 0)
{
$max_url_message="";
$field_check=preg_split('/,/',$max_url_fields[$config]);
$field_run=sizeof($field_check);
for($i=0;$i<$field_run;$i++)
{
$cur_field_name=$field_check[$i];
$cur_field=$_POST[$cur_field_name];
preg_match_all("/http:/", $cur_field, $matches);
if(count($matches[0]) > $max_urls[$config])
$max_url_message.="<li>This message contains too many URL's.</li>\n";
}
}
// set anti-spam flagging option
if(strlen($empty_message.$spam_message.$time_message.$captcha_message.$max_url_message) > 0 && strlen($flag_spam[$config]) == 0)
$set_flag = 2;
else if(strlen($empty_message.$spam_message.$time_message.$captcha_message.$max_url_message) > 0 && strlen($flag_spam[$config]) > 0)
$set_flag = 1;
else
$set_flag = 0;
// header injection check
$security_filter="";
if(strlen($_POST[$reply_to_field[$config]]) > 0)
{
if(eregi($header_injection_regex,$_POST[$reply_to_field[$config]]))
$security_filter.="<li>Header injection attempt detected, mail aborted.</li>\n";
else
$reply_to_field_checked=$_POST[$reply_to_field[$config]];
}
if(strlen($_POST[$reply_to_name[$config]]) > 0)
{
if(eregi($header_injection_regex,$_POST[$reply_to_name[$config]]))
$security_filter.="<li>Header injection attempt detected, mail aborted.</li>\n";
else
$reply_to_name_checked=$_POST[$reply_to_name[$config]];
}
// check domain referrer and continue
$domain_chk=checkReferer();
if($domain_chk=="yes")
{
$error_message=checkFields($required_fields[$config], $required_email_fields[$config], $regex);
if(strlen($error_message) < 1 && strlen($security_filter) < 1 && $set_flag < 2)
{
// build appropriate message format for recipient
$content_type=contentType($charset[$config], $mail_type[$config]);
$message=buildTable($mail_type[$config], $mail_fields[$config], $mail_intro[$config], "recipient", $return_ip[$config]);
// build header data for recipient message
//$extra="From: ".$_POST[$reply_to_field[$config]]."\r\n";
$extra="From: ".$reply_to_name_checked." <".$reply_to_field_checked.">\r\n";
if($cc_tomail[$config]!="")
$extra.="Cc: ".$cc_tomail[$config]."\r\n";
if($bcc_tomail[$config]!="")
$extra.="Bcc: ".$bcc_tomail[$config]."\r\n";
if($mail_priority[$config]!="")
$extra.="X-Priority: ".$mail_priority[$config]."\r\n";
// get attachments if necessary
if($attachment_fields[$config]!="")
{
$semi_rand=md5(time());
$border="==Multipart_Boundary_x{$semi_rand}x";
$extra.="MIME-Version: 1.0\r\n";
$extra.="Content-Type: multipart/mixed; boundary=\"{$border}\"";
$message=getAttachments($attachment_fields[$config], $message, $content_type, $border);
}
else
{
$extra.="MIME-Version: 1.0\r\n".$content_type;
}
// send recipient email
if($debug==1)
{
if($set_flag == 1)
$debug_text.="<p><b>Mail would have sent flagged for spam if not in debug mode.</b></p>";
else
$debug_text.="<p><b>Mail would have sent if not in debug mode.</b></p>";
}
else if($debug==0)
{
if($set_flag == 1)
$subject = $flag_spam[$config]." ".$subject[$config];
else
$subject = $subject[$config];
mail("".$tomail[$config]."", "".stripslashes($subject)."", "".stripslashes($message)."", "".$extra."");
}
// autoresponse email if necessary
if($send_copy[$config]=="yes")
{
// build appropriate message format for autoresponse
$content_type=contentType($charset[$config], $copy_format[$config]);
$message=buildTable($copy_format[$config], $copy_fields[$config], $copy_intro[$config], "autoresponder", $return_ip[$config]);
// build header data for autoresponse
$copy_tomail=$_POST[$copy_tomail_field[$config]];
$copy_extra="From: ".$copy_from[$config]."\r\n";
// get autoresponse attachments if necessary
if($copy_attachment_fields[$config]!="")
{
$semi_rand=md5(time());
$border="==Multipart_Boundary_x{$semi_rand}x";
$copy_extra.="MIME-Version: 1.0\r\n";
$copy_extra.="Content-Type: multipart/mixed; boundary=\"{$border}\"";
$message=getAttachments($copy_attachment_fields[$config], $message, $content_type, $border);
}
else
{
$copy_extra.="MIME-Version: 1.0\r\n".$content_type;
}
// send autoresponse email
if($debug==1)
{
if($set_flag == 1)
$debug_text.="<p><b>Autoresponder would have sent flagged for spam if not in debug mode.</b></p>";
else
$debug_text.="<p><b>Autoresponder would have sent if not in debug mode.</b></p>";
}
else if($debug==0)
{
$send_copy = 1;
if($copy_tomail=="" || !eregi($regex,$copy_tomail))
$send_copy = 0;
if($send_copy == 1)
{
if($set_flag == 1)
$copy_subject = $flag_spam[$config]." ".$copy_subject[$config];
else
$copy_subject = $copy_subject[$config];
mail("$copy_tomail", "".$copy_subject."", "$message", "$copy_extra");
}
}
}
// showing thanks pages from a successful submission
if($thanks_page[$config]=="")
{
echo "<h3>".$thanks_page_title[$config]."</h3>\n";
echo "<p>".$thanks_page_text[$config]."</p>\n";
if(strlen($debug_text) > 0)
echo "<p><b><i>".$debug_text."</i></b></p>\n";
}
else
{
header("Location: ".$thanks_page[$config]);
}
}
else
{
// entering error page options from missing required fields
if($error_page[$config]=="")
{
echo "<h3>".$error_page_title[$config]."</h3>\n";
echo "<ul>\n";
echo $security_filter.$empty_message.$error_message.$spam_message.$time_message.$captcha_message.$max_url_message;
echo "</ul>\n";
echo "<p>".$error_page_text[$config]."</p>\n";
}
else
{
header("Location: ".$error_page[$config]);
}
}
}
else
{
echo "<h3>".$error_page_title[$config]."</h3>\n";
// message if unauthorized domain trigger from referer checking option
echo "<p>Sorry, mailing request came from an unauthorized domain.</p>\n";
}
//////////////////////////////
// end procedural scripting //
//////////////////////////////
}
else
{
echo "<h3>Error</h3>";
echo "<p>No form data has been sent to the script</p>\n";
}
if($footer[$config]!="")
include($footer[$config]);
ob_end_flush();
?>
<input type="button" value="Return to Form" onClick="javascript: history.go(-1);" />
Nancy O.
Here is a new HTML contact form to work with vsi2 script.
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Sample Form</title>
<style type="text/css">
/**BEGIN FORM STYLES**/
#form1 {
font-size: 14px;
width: 500px;
margin: 0 auto; /**centered**/
background: #FFF;
border: 2px groove green;
padding: 7px 14px 7px 14px;}
fieldset {
margin-bottom:5px;
border-right:none;
border-bottom:none;
border-left:none;
}
legend {
padding: 8px;
border: 1px solid silver;
background: #009900;
font-weight: bold;
color: #FFFFFF;
margin-left: -75px;
*margin-left:0;
line-height: 1.5
}
/**wrap form lables and fields inside ordered lists for better web accessibility**/
#form1 ol {
list-style:none;
margin:0;
padding:0}
#form1 li {
padding:5px;
margin: 0;
clear: left;
}
label{
display:inline-block;
float:left;
line-height: 23px; /**lines up labels with fields**/
width:167px;
font-size: 12px;
color: #666;
text-align:right;
margin-right: 10px; /*space between labels, fields*/
}
input[type=text],
textarea {
width: 190px; /**same width on text fields**/
padding: 5px;
color: #666;
border: 1px dotted #009900;
font-family:Arial, Helvetica, sans-serif;
font-size: 12px;
}
/**field background on focus**/
input:focus,
input:active,
textarea:focus,
textarea:active
{background-color: #EBECDE; border: 1px solid;}
#submit {
margin-left: 45px;
background: #009900;
font-size: 18px;
color:#FFF;
font-weight: bold;
border: 2px outset #FFF}
#submit:hover,
#submit:focus,
#submit:active {
background: #006600;
color: yellow;
border: 2px inset #FFF}
/**END FORM STYLES**/
</style>
</head>
<body>
<!--BEGIN HTML FORM, action="path to form-processing script on your server" -->
<form id="form1" action="vsi2.php" method="post" enctype="multipart/form-data" name="form1">
<h3>HTML Contact Form</h3>
<fieldset>
<legend>Required Fields:</legend>
<!--spam prevention-->
<input name="config" type="hidden" value="0" />
<input type="text" name="nospam" style="display:none" />
<ol>
<li>
<label for="first_name">First Name:</label>
<input name="first_name" id="first_name" type="text" />
</li>
<li>
<label for="last_name">Last Name:</label>
<input name="last_name" id="last_name" type="text" />
</li>
<li>
<label for="email">E-mail:</label>
<input name="email" id="email" type="text" />
</li>
</ol>
</fieldset>
<fieldset>
<legend>Optional Fields:</legend>
<ol>
<li>
<label for="phone">Phone number:</label>
<input name="phone" id="phone" type="text" />
</li>
<li>
<label for="subject">Subject:</label>
<input name="subject" id="subject" type="text" />
</li>
<li>
<label for="message">Message:</label>
<textarea id="message" name="message"></textarea>
</li>
<li>
<label for="submit"> </label>
<input type="submit" name="submit" id="submit" value="Submit" />
</li>
</ol>
</fieldset>
</form>
<!--END OF FORM -->
</body>
</html>
I think you're good to go!
Nancy O.
Alt-Web Design & Publishing
Web | Graphics | Print | Media Specialists
Hi Nancy-
First off, thank you for the php and html code. That was a huge help.
Here's the link to the form: http://www.sperryinteriors.com/contact.html
I ran across a few problems:
1. I inserted my email address into the php code to test it out (to make sure it sent to me) and I got an email at the email address I entered in the contact form notifying me that Sperry Interiors would be getting in touch with me (which was fine) but the information I entered in the form should've gone to my other email (the one I specified in the .php form) and instead it was included in the notification and I never received an email at the email address I specified in the php code. This worries me because the whole point is for the info. that people enter to go directly to Vickie not the customer. Is there something in the code that is causing this? Can you show me how to fix this? Or maybe help me understand better why it's doing this?
2. The form displays perfectly in Firefox but in IE 9 the border of the form is not around the perimeter but instead is at the top and squished to maybe an inch high and next to each label (ie: name, number, etc.) is 1. 2. 3. and so on. Also the space between each field is gone so it's all squished together. I'm attaching the URL to see what I mean for IE 9 and to see how the form is acting in general.
Thanks so much for sticking with me and helping me through this. I really appreciate your help!
ashmic
Nancy-
Last night I tested out the form (using my email address as the "recipient") and received nothing but supposedly my client (whose website this is) did. So I changed the email address back to her email address in the php form and sent her an email via her contact form. I told her to let me know if she got it. So *hopefully* she did. I'll let you know. If she does get it then the only problem lies in that the form's layout doesn't look right in IE.
So I just wanted to update you from what I wrote last night (as some of it still applies).
Thanks,
Ashley
Form Styles belong in your CSS. Either in your external stylesheet or between the <head> & </head> tags in your html document; not in the <body>. Starting on line 107 move the Form styles to a more appropriate location.
You have two sets of <body> and <head> tags. Only one set is valid.
Validate your HTML code and fix errors. IE9 is less forgiving of code errors than some other browsers.
Code Validation Tools
------------------------------------
CSS - http://jigsaw.w3.org/css-validator/
HTML - http://validator.w3.org/
I'll look at the PHP code again and report back later. Message should be going to both addresses.
Nancy O.
Alt-Web Design & Publishing
Web | Graphics | Print | Media Specialists
I just tested the PHP script again with my contact form and everything works as it should.
My server address received the entire message.
My private gmail address received the automated reply.
//This goes to the web site's email address
$mail_intro[0]="The following message was sent from SPERRY INTERIORS.COM:";
$mail_fields[0]="first_name,last_name,email,phone,subject,message";
//This goes to the customer who submits the form
// Send back to sender config
$send_copy[0]="yes";
$copy_format[0]="vert_table";
$copy_fields[0]="first_name,last_name,subject,message";
$copy_subject[0]="SPERRY INTERIORS automated reply";
$copy_intro[0]="Thanks for taking time to contact Sperry Interiors. Someone will be in touch with you soon.";
Fields shown in red must match HTML form fields exactly. Fields in bold red are required fields.
Nancy O.
Alt-Web Design & Publishing
Web | Graphics | Print | Media Specialists
North America
Europe, Middle East and Africa
Asia Pacific