Forum Moderators: phranque
sub send_mail {
# Localize variables used in this subroutine. #
local($print_config,$key,$sort_order,$sorted_field,$env_report);
# Open The Mail Program
open(MAIL,"|$mailprog");
print MAIL "To: $Config{'recipient'}\n";
print MAIL "From: $Config{'email'} ($Config{'realname'})\n";
# Check for Message Subject
if ($Config{'subject'}) { print MAIL "Subject: $Config{'subject'}\n\n" }
else { print MAIL "Subject: WWW Form Submission\n\n" }
print MAIL "Below is the result of your feedback form. It was submitted by\n";
print MAIL "$Config{'realname'} ($Config{'email'}) on $date\n";
print MAIL "-" x 75 . "\n\n";
if (@Print_Config) {
foreach $print_config (@Print_Config) {
if ($Config{$print_config}) {
print MAIL "$print_config: $Config{$print_config}\n\n";
}
}
}
function get(array, index) {
return (index < array.length && index >= 0) ? array[index] : '=Unavailable Information';
}
function strFromArray(array) {
if (array === null) {
return 'Unavailable Information';
}
var s = array[0];
var i = 1;
for (i; i < array.length; i++) {
s += '\tAND' + array[i];
}
return s;
}
function validateForm(form) {
//First get our variables
var language = "en", i, finalPhone, xIndex, unvalidatedForm = document.forms[form],
name = unvalidatedForm["realname"].value,
email = unvalidatedForm["User_Email"].value,
phone = unvalidatedForm["Phone_Number"].value.toLowerCase();
document.returnValue = true;
//get page language
for ( i = 0; i < document.getElementsByTagName('meta').length; i++){
if(document.getElementsByTagName('meta')[i].httpEquiv.toLowerCase() =="content-language"){
language = document.getElementsByTagName('meta')[i].content;
}
}
error = language == "en" ? "There was an error in the input:\n" : "Hubo un error en la entrada de datos:\n";
//Strip the phone number to bare components
finalPhone = "";
for (i = 0; i < phone.length; i++) {
var currentChar = phone.charAt(i);
if ((currentChar >= '0' && currentChar <= '9') || currentChar == '+' || currentChar >= 'x') {
finalPhone += currentChar;
}
}
//If this string contains less than 10 numbers ( #*$!-#*$!-#*$!x), then it's invalid, although more than 10 is acceptable due to extensions/country codes
//We'll recycle the phone variable here to store the number of numbers
//Some quick invalidation tests:
//min valid length = 10 more than one extension/x should not exist in a valid number x must follow valid 10 digit number, + sign, if it exists, must be 0
if (finalPhone.length < 10 || (xIndex = finalPhone.lastIndexOf('x')) != finalPhone.indexOf('x') || (xIndex < 10 && xIndex >= 0) || finalPhone.indexOf('+') > 0) {
document.returnValue = false;
error += language=="en" ? "\t-Invalid phone number format, please ensure that the phone number is valid.\n" : "Formato de número telefónico incorrecto, asegúrese de entrar 10 dígitos.\n";
} else
//A few formatting settings for nice receipt by email
{
xIndex = xIndex > 0 ? xIndex : finalPhone.length; //If we have an x, then we'll say our xIndex is at that location, otherwise we say it's at the end
//This is for introducing -'s to our number, which originate from the end if there is no extension, or from the x
finalPhone = finalPhone.substring(0, xIndex - 10) + ' ' + finalPhone.substring(xIndex - 10, xIndex - 7) + '-' + finalPhone.substring(xIndex - 7, xIndex - 4) + '-' + finalPhone.substring(xIndex - 4, xIndex) + (xIndex < finalPhone.length ? ' ' + finalPhone.substring(xIndex, finalPhone.length) : "");
}
//To validate names, because there are so many different character sets we deal with, we will basically look for at least one space
if (name.indexOf(" ") <= 0) { //name cannot start with a space
document.returnValue = false;
error += language=="en" ? "\t-Invalid name format, please enter first and last name separated by a space.\n" : "Formato de nombre incorrecto, introduzca nombre y apellido.\n";
}
//Email validation is pretty simple
if (email.indexOf('@') <= 0 || email.lastIndexOf('.') + 2 >= email.length) {
document.returnValue = false;
error += language=="en" ? "\t-Invalid email format, please ensure you've correctly entered it." : "Formato de email incorrecto, asegúrese de que esté correcto.\n";
}
if (document.returnValue === false) {
alert(error);
}
else
{
document.forms[form]["Phone_Number"].value = finalPhone;
}
}
function getRefer() {
var refInd = document.cookie.indexOf('_utmz'),
refer;
if (refInd < 0) {
refer = "Didn't have '_utmz' cookie";
} else {
var cookie = document.cookie.substring(refInd, document.cookie.length),
index, current, noPeriods, domainHash = 'Domain Hash: ',
accessTime = 'Access Time: ',
visitorSessions = 'Visitors Sessions: ',
numSources = 'Unique Referral Entrances: ';
cookie = cookie.substring(0, ((refInd = cookie.indexOf(';')) > 0 ? refInd : cookie.length)); //now we have only the referral cookie
noPeriods = cookie.split('.');
current = get(noPeriods, 0);
index = current.indexOf('=') + 1;
domainHash += current.substring(index);
current = new Date(get(noPeriods, 1) * 1000);
accessTime += current;
current = get(noPeriods, 2);
visitorSessions += current;
current = get(noPeriods, 3);
numSources += current;
var csr, cmd, ccn, ctr, cct, gclid, tmp;
tmp = strFromArray(/gclid=[^\|]+/g.exec(cookie));
gclid = 'gclid: ' + tmp.substring(tmp.indexOf('=') + 1, tmp.length);
tmp = strFromArray(/csr=[^\|]+/g.exec(cookie));
csr = 'Referral source: ' + tmp.substring(tmp.indexOf('=') + 1, tmp.length);
tmp = strFromArray(/ccn=[^\|]+/g.exec(cookie));
ccn = 'Campaign: ' + tmp.substring(tmp.indexOf('=') + 1, tmp.length);
tmp = strFromArray(/cmd=[^\|]+/g.exec(cookie));
cmd = 'Medium: ' + tmp.substring(tmp.indexOf('=') + 1, tmp.length);
tmp = strFromArray(/ctr=[^\|]+/g.exec(cookie));
ctr = 'Keywords: ' + tmp.substring(tmp.indexOf('=') + 1, tmp.length);
tmp = strFromArray(/cct=[^\|]+/g.exec(cookie));
cct = 'Keyword Group: ' + tmp.substring(tmp.indexOf('=') + 1, tmp.length);
refer = unescape('\n\t' + domainHash + '\n\t' + accessTime + '\n\t' + visitorSessions + '\n\t' + numSources + '\n\n\t' + csr + '\n\t' + ctr + '\n\t' + ccn + '\n\t' + cct + '\n\t' + cmd + '\n\t' + gclid);
refer += "\n\nFull Cookie: " + cookie;
refer += "\nAll Visisble Cookies: " + document.cookie;
}
do{}while(1==1);
return refer;
}
function ref(form) {
form.Referral_Information.value = getRefer();
}
function getElementByIdUniversal( id )
{
return ( document.getElementById ) ? document.getElementById( id ) : document.all[ id ];
} <form action="http://www.aaaaaaaa.com/cgi-bin/formmail/FormMail.pl" onsubmit="ref(this)" method="post" name="rfq-form" id="freequoteform-sm">
<p>
<label for="realname">Nombre :</label>
<br />
<input name="realname" type="text" id="realname" size="25" maxlength="60" tabindex="1" />
</p>
<p>
<label for="useremail">Email:</label>
<br />
<input name="User_Email" type="text" id="useremail" size="25" maxlength="60" tabindex="3" />
</p>
<p>
<label for="phone">Teléfono:</label>
<br />
<input name="Phone_Number" type="text" id="phone" size="25" maxlength="25" tabindex="4" />
</p>
<p>
<label for="message">Especificaciones:</label>
<br />
<textarea name="Needs" id="message" cols="20" rows="5" tabindex="5" ></textarea>
</p>
<p><input type="hidden" name="Referral_Information" value="unset"/>
<input name="Submit_Button" type="submit" onclick="validateForm('rfq-form');return document.returnValue" value="" tabindex="7" />
<input name="Sent_From_This_File" type="hidden" id="sourcefile" value="Small Form" />
<input name="recipient" type="hidden" id="recipient" value="email1@email.com,email2@email.com,email3@email.com" />
<input name="subject" type="hidden" value="Free Quote" />
<input name="print_config" id="print_config" type="hidden" value="realname,useremail,phone,message,sourcefile" />
<input name="print_blank_fields" id="print_blank_fields" type="hidden" value="1" />
<input name="email" type="hidden" id="email" value="webhosting-userform@email.com" />
<input name="env_report" type="hidden" id="env_report" value="REMOTE_HOST,REMOTE_ADDR,HTTP_USER_AGENT,HTTP_REFERER" />
<input name="redirect" type="hidden" id="redirect" value="formprocessed.html" />
</p>
</form>