homepage Welcome to WebmasterWorld Guest from 54.196.62.23
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Hardware and OS Related Technologies / Website Technology Issues
Forum Library, Charter, Moderators: phranque

Website Technology Issues Forum

    
FormMail.pl error, emails send with no body
Body of email shows up completely empty
Cindovin



 
Msg#: 4459625 posted 9:57 pm on May 30, 2012 (gmt 0)

I work at a company that utilizes emailed requests for quotes through our website. The current configuration utilizes FormMail.pl, and that is something that we may be planning to change in the near future, but a quick fix to this issue for the interim period would be preferred.

The script, sporadically is not sending a body with the email, but I cannot seem to find anything to correlate that to. We are receiving "yapache in free(): warning: junk pointer, too high to make sense" in association with the FormMail.pl script, but they do not appear to coincide with this issue.

The email system utilizes javascript for validation/formatting/cookie extraction, so this is another area which may be the culprit.

Lastly there may be an issue with the form itself, or a certain type of input, that is causing the entire email body not to send, but I cannot imagine what this error could be.

I know better than to copy my entire FormMail.pl file onto this post, as it is about 20 printed pages of text, but I will draw attention to one snippet:
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";
}
}
}


To annotate the above code: the email 'To' field is being set by a hidden form field, 'recipient', the 'From' field is set by a hidden form field defined email, and is lastly given the name of a user defined value in the form 'realname'. This is all working as intended even in the broken emails.

Next, the subject line is set to the value of a hidden form field.

Oddly, where the program breaks is on the Body section of the email. There is no content sent. No characters at all.

Below is a sample of the relevant JS and the relevant HTML:
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>


I know it's a lot to sift through, but thank you to anyone that takes the time to review this and offer guidance.

On a related inquiry, as I will likely be transitioning away from this mail solution soon, does anyone have a preferred service with the priorities being speed, reliability, and user friendliness.

Thanks guys.

 

phranque

WebmasterWorld Administrator phranque us a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



 
Msg#: 4459625 posted 2:59 am on Jun 3, 2012 (gmt 0)

welcome to WebmasterWorld, Cindovin!

the javascript form validation appears to completely ignore the Needs/message textarea, so i doubt the problem exists in the user agent.

which version of the FormMail.pl script are you using?

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Hardware and OS Related Technologies / Website Technology Issues
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved