Click to See Complete Forum and Search --> : Email Perl Script Issue


dandaman2007
04-03-2007, 09:54 AM
Hi All,

I need some expertise Perl help.....

Basically i have an Email perl script that i use on alot of my sites, which basically E-mails the filled in form to a specified e-mail address. nms_formail.pl is the name of the perl script, in case anyone has got it themselves.

I now need to change it slightly, but don't know how to......

I want to be able to email the form to different address depending on what email address is selected on the form using a tick box.

FOR EXAMPLE

<input type="checkbox" name="Emial1" value="mailto:test@test.com">
<input type="checkbox" name="Email2" value="mailto:test2@test2.com">
<input type="checkbox" name="Email3" value="mailto:test3@test3.com">

The code is wrong for those tick boxes, but you get the idea,

So when a user selects 2 of the text boxes, the email gets sent to those select tick boxes ONLY, and not the deselected on.



If anyone could shine some light on this, that would be great. If you would like me to pose the script text of the perl script please say so and i will.

Thanks again

dandaman2007
04-04-2007, 06:24 AM
COME ON PEOPLE.

SOMEONE REPLY lol

need some help he he he

Scriptage
04-11-2007, 09:18 PM
Now then. Sorry for the late reply but I have been away from these forums for quite some time.

sub doEmail{

my $email = shift;

#Enter your Email code here

#Dont forget you can access the email using $email

#End Email Code

}

@emails = ("test@test.com", "test2@test2.com", "test3@test3.com");

if(defined param("email1")){

doEmail($emails[0]);

}


if(defined param("email2")){

doEmail($emails[1]);

}

if(defined param("email3")){

doEmail($emails[2]);

}



And there you have it. As long as your checkboxes are named email1, email2 etc this code should work.

Hope this helps.

Regards

Carl

dandaman2007
04-12-2007, 03:52 AM
Carl,

Thanks for the reply, i can see alot of effort went into that.

I am just about to try it out.... if it works...... a big sloppy kiss is coming your way!

Just with regards to the Value of the check boxes..... does that stay as it is???

Thanks man, your a star, ill let you know how i get on.

Dan

dandaman2007
04-12-2007, 04:06 AM
ok Carl,

Hit a rivit already lol

The Email code im using is a well known emailform called "FormMail.pl". Do i add the code you suggested under that in the .pl file???

Also there are a few fields in the FormMail.pl file that i dont know what to fill in given your example....... im rubbish lol

Here is the URL to the form i am trying to get working, so yo can see what im trying to do. Any further help would be greatly appreciated.

http://www.ekayadvertising.com/Intranet/Request_Forms/Print_Form/Print_Form.html

Thanks

dandaman2007
04-13-2007, 05:44 AM
Bump

Watts
04-13-2007, 04:52 PM
A "quick and dirty" solution would be to use JavaScript. If your not familiar with Perl then you probably don't want to be hacking around in the formmail script. Use the JavaScript solution temporarily to solve your problem, then play with a copy of the Perl Script in another folder or something so if you break it, it won't be catastrophic.

<HTML>

<SCRIPT LANGUAGE="JavaScript">
function makeMail() {

// RECIPIENT NUMBER ONE
if (form1.mail1.checked) {
$mail1 = form1.mail1.value + ",";
}
else {
$mail1 = "";
}

// RECIPIENT NUMBER TWO
if (form1.mail2.checked) {
$mail2 = form1.mail2.value + ",";
}
else {
$mail2 = "";
}

// RECIPIENT NUMBER THREE
if (form1.mail3.checked) {
$mail3 = form1.mail3.value + ",";
}
else {
$mail3 = "";
}

// ADDRESS TO SEND EMAILS TO
$address = $mail1 + $mail2 + $mail3; //add additional $mail4, $mail5, etc to this list for each one you add above
form1.recipient.value = $address;

} //end of function
</SCRIPT>

<BODY>

<FORM NAME="form1" ACTION="">
<BR><INPUT TYPE="checkbox" NAME="mail1" VALUE="shipping@yourdomain.com" onClick="makeMail()">Shipping
<BR><INPUT TYPE="checkbox" NAME="mail2" VALUE="accounting@yourdomain.com" onClick="makeMail()">Accounting
<BR><INPUT TYPE="checkbox" NAME="mail3" VALUE="production@yourdomain.com" onClick="makeMail()">Production

<!-- change this to a hidden tag later on -->
<P><INPUT TYPE="text" NAME="recipient" VALUE="" SIZE="100">

</FORM>

</BODY>

</HTML>


You really don't want any emails listed on your webpage in any form. The reason is that there automated programs the cruise through website looking for email address (visible or hidden) and then harvest them for spam databases. If you put your address anywhere public (this forum for example) you'll notice an exponential increase in spam within a few weeks.

dandaman2007
04-16-2007, 07:31 AM
Thanks for your response WATTS,

I'm a little confused as to how the Javascript is sending the mail..... is it still using the perl script???

Thanks

Watts
04-16-2007, 10:35 AM
Yep. You're still using your Perl script as before. The JavaScript just combines addressess together in to stick in the recipients variable. I don't use the NMS script so it may not allow comma-separated, multiple email addresses. As stated, this is an example of a quick solution and not necessarily a proper solution. Copy the example above and try it out, you'll get the general idea...

dandaman2007
04-16-2007, 10:39 AM
Thank you for that mate,

It doesnt seem to be working though.... probably someting im doing wrong.

Appriceate your help,time and effort though.

Maybe if you have a working solution you could post, then that would be great, so i can addapt that.

Thanks again though

Dan

Watts
04-17-2007, 04:32 PM
Your form is looking better... have you tried submitting it with just one email (delete the preceeding and following commas) and see if it works. Get it working with one email and then try it with two (separated by a comma).

dandaman2007
04-18-2007, 03:53 AM
sorry dude...... im totally confused.....

Never done anything like this before, so i dont know how to use the commas etc.... beginners hell im sure, sorry.

Maybe a working example you may lying around lol

Watts
04-18-2007, 05:47 PM
The script seems to be working at least. I'll copy your form from your website and get a copy of NMS_formmail installed and then post a link & message after I've played with it.

Scriptage
04-22-2007, 07:57 AM
Sorry I haven't replied I've been rushed off of my feet at work. Ignore everything that Watts has said to you because it is a garbled mess. He has mixed PERL code with Javascript.

// ADDRESS TO SEND EMAILS TO
$address = $mail1 + $mail2 + $mail3; //add additional $mail4, $mail5, etc to this list for each one you add above
form1.recipient.value = $address;

Even if this code did work (which it won't as seen as Javascript doesn't use dollar signs) then the resulting concatenated string would resemble something similar to this "email1@domain.comemail2@domain.comemail3@domain.com" which is bad.

I suggest Watts goes to http://www.w3schools.com/js/default.asp to brush up on (or gain) his Javascript skills.

How Watts has managed to complicate this simple matter is beyond me.

Can you attach a copy of the file please and I will re-code the necessary bits for you and then give you a run down of what I have done and how I did it.

Kind Regards

Carl Bates

Watts
04-23-2007, 01:51 PM
Carl, you're more than welcome to help him out, if you'll actually do it (seeing how you haven't posted a reply to this thread since April 12th.)

If you don't like the help I've offered that's fine, but your editorial comments are not necessary...

- Mike.
(Texan by Birth, NOT CARL by the Grace of God)

Watts
04-23-2007, 06:53 PM
...because it is a garbled mess. He has mixed PERL code with Javascript

What?? You are smoking crack. It's JavaScript. It's perfectly acceptable to use JavaScript to set form variable values and then use Perl to handle the form submission.

Even if this code did work

It works, you didn't even bother to look at it. Okay, rename the variables to remove the dollar signs, big whoop. I bet you feel real important.

The script he is using from sourceforge called "NMS formmail" and here is the section of the readme:

Form Configuration
The action of your form needs to point towards this script (obviously), and the method must be POST or GET in capital letters. Version 1.5 of FormMail offers many new ways to code your form to tailor the resulting HTML page and the way the script performs. Below is a list of form fields you can use and how to implement them.

Necessary Form Fields

There is only one form field that you must have in your form, for FormMail to work correctly. This is the recipient field.

Field: recipient
Description: This form field allows you to specify to whom you wish for your form results to be mailed. Most likely you will want to configure this option as a hidden form field with a value equal to that of your e-mail address.

As of version 1.8, You can include multiple recipients by separating the values with commas.
Syntax: <input type=hidden name="recipient" value="email@your.host.com"> OR
<input type=hidden name="recipient" value="user@yourhost.com,user2@yourhost.com">


Exactly.

Scriptage
04-24-2007, 04:14 AM
I beg your pardon Watts, I simply saw the dollar signs and assumed you were trying to code in PERL and the code was incorrect, once again my apologies;

What?? You are smoking crack. It's JavaScript. It's perfectly acceptable to use JavaScript to set form variable values and then use Perl to handle the form submission.


Read above.

As for the Javascript solution:

If you look at the text box the string comma delimited string shows as follows ",daniel.wheeler@ekay.co.uk,,rob.noon@ekay.co.uk,,terry.zarb@ekay.co.uk," note the leading / trailing commas and the double commas between email addresses, this is more than likely bad.

There is, however, a more serious issue; passing email addresses to the CGI program will allow anybody to send ANY email address to the program thus enabling people to send spam using the form on the website, this is bad, infact very bad.

Using the comma delimited string to send emails to different addresses:



my @address;

@emails = ("test@test.com", "test2@test2.com", "test3@test3.com");

if(defined param("email1")){

push(@address, $emails[0]);

}

if(defined param("email2")){

push(@address, $emails[1]);

}

if(defined param("email3")){

push(@address, $emails[2]);

}

my $addresses = join(",", @address);



Use the $addresses variable in the program as the recipient field (will be named something like: $address, $email, $recipient etc).

This will fix the security issues and send e-mails to all specified people (if you use the names for the checkboxes I posted earlier).

Once again I must apologise to Watts for my over zealous response.


kind Regards

Carl Bates

dandaman2007
04-30-2007, 09:40 AM
OK i htink im doing something wrong cause its still not working....

This is my HTML for the form.....


<!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">
<meta name="DESCRIPTION" content="At Ekay PLC, we are a full service advertising agency, we can handle all your creative and media requirements">
<meta name="KEYWORDS" content="ekay, advertising, marketing, design, ppc, pay per click, direct response, agency, direct, response, press, media, radio, tv, drtv, ekay advertising, local advertising, posters, print, full service agency, agency, largest advertising agency, advertise">
<meta name="Name" content="Webmaster_Keyword">
<meta name="Author" content="Daniel Wheeler - www.ekayadvertising.com - daniel.wheeler@ekay.co.uk">
<meta name="Creator" content="Ekay PLC">
<meta name="Publisher" content="Ekay PLC">
<meta name="Copyright" content="Ekay PLC">
<meta name="Distributor" content="Global">
<meta name="Rating" content="General">
<meta name="Robots" content="All">
<meta name="Revisit-After" content="1 days">
<title>Ekay PLC Intranet: - Brief From</title>
<link rel="stylesheet" type="text/css" href="../../CSS/Style.css">
<script src="js/prototype.js" type="text/javascript"></script>
<script src="js/effects.js" type="text/javascript"></script>
<script type="text/javascript" src="js/validation.js"></script>


<SCRIPT LANGUAGE="JavaScript">
function makeMail() {

my @address;

@emails = ("daniel.wheeler@ekay.co.uk", "rob.noon@ekay.co.uk", "terry.zarb@ekay.co.uk");

if(defined param("email1")){

push(@address, $emails[0]);

}

if(defined param("email2")){

push(@address, $emails[1]);

}

if(defined param("email3")){

push(@address, $emails[2]);

}

my $addresses = join(",", @address);

</SCRIPT>

</head>
<body style="margin-top:0px">
<!-- DO NOT MOVE! The following AllWebMenus linking code section must always be placed right AFTER the BODY tag-->
<!-- ******** BEGIN ALLWEBMENUS CODE FOR menu ******** -->
<script type="text/javascript">var MenuLinkedBy="AllWebMenus [4]",awmMenuName="menu",awmBN="630";awmAltUrl="";</script><script charset="UTF-8" src="../../Menu/javascript/menu.js" type="text/javascript"></script><script type="text/javascript">awmBuildMenu();</script>
<!-- ******** END ALLWEBMENUS CODE FOR menu ******** -->

<div align="center" class="ticko"><iframe marginwidth="0" src="http://news.bbc.co.uk/nol/ukfs_news/hi/front_page/ticker.stm" marginheight="0" frameborder="0" height="15" scrolling="no" width="900"></iframe></div>
<table width="900" height="100%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="900" style="height:103px"><img src="../../Images/Header.jpg" border="0" usemap="#Map" /></td>
</tr>
<tr>
<td width="900" style="height:23px; background-image:url(../../Images/BlueGrad.jpg);"><div align="left"><img src="../../Images/pixle.gif" border="0" align="top" id="awmAnchor-menu" /></div></td>
</tr>
<tr>
<td width="900" height="100%" bgcolor="#FFFFFF" valign="top">
<div id="Header">
<h2 style="margin-bottom: 0; margin-top: 0;">
Print Form
</h2>
</div>
<br />
<Br />
<table width="600" height="405" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#CCCCCC" bgcolor="#FFFFFF" style="height:500px">
<form action="http://www.ekayadvertising.com/Intranet/Request_Forms/Print_Form/Form/nms_formmail.pl"id="form1" name="form1" method="post">
<tr>
<td width="249" height="30">
Description</td>
<td width="3" height="30">&nbsp;</td>
<td width="340" height="30">
<input type="text" name="Description" id="Description" size="40" class="required"/></td>
</tr>
<tr>
<td width="249" height="25">
Finish Size</td>
<td width="3">&nbsp;</td>
<td width="340" height="25">
<input type="text" name="FinishSize" id="FinishSize" size="40" class="required"/></td>
</tr>
<tr>
<td width="249" height="25">
Content</td>
<td width="3">&nbsp;</td>
<td width="340" height="25">
<input type="text" name="Content" id="Content" size="40" class="required"/></td>
</tr>
<tr>
<td width="249" height="25">
Origination</td>
<td width="3">&nbsp;</td>
<td width="340" height="25">
<input type="text" name="Origination" id="Origination" size="40" class="required"/></td>
</tr>
<tr>
<td width="249" height="25">
Proofing </td>
<td width="3">&nbsp;</td>
<td width="340" height="25">
<input type="text" name="Proofing" id="Proofing" size="40" class="required"/></td>
</tr>
<tr>
<td width="249" height="25">
Printing</td>
<td width="3">&nbsp;</td>
<td width="340" height="25">
<input type="text" name="Printing" id="Printing" size="40" class="required"/></td>
</tr>
<tr>
<td width="249" height="25">
Materials</td>
<td width="3">&nbsp;</td>
<td width="340" height="25">
<input type="text" name="Materials" id="Materials" size="40" class="required"/></td>
</tr>
<tr>
<td width="249" height="25">
Finishing</td>
<td width="3">&nbsp;</td>
<td width="340" height="25">
<input type="text" name="Finishing" id="Finishing" size="40" class="required"/></td>
</tr>
<tr>
<td width="249" height="25">
Delivery</td>
<td width="3">&nbsp;</td>
<td width="340" height="25">
<input type="text" name="Delivery" id="Delivery" size="40" class="required"/></td>
</tr>
<tr>
<td width="249" height="25">
Quantities/Prices</td>
<td width="3">&nbsp;</td>
<td width="340" height="25">
<input type="text" name="QuantitiesPrices" id="QuantitiesPrices" size="40" class="required"/></td>
</tr>
<tr>
<td height="25" colspan="3">
<strong>Send to: -</strong>
<br />
<br />
<INPUT TYPE="checkbox" NAME="mail1" VALUE="daniel.wheeler@ekay.co.uk" onClick="makeMail()"> - Danny
<br />
<Br />
<INPUT TYPE="checkbox" NAME="mail2" VALUE="rob.noon@ekay.co.uk" onClick="makeMail()"> - rob
<br />
<Br />
<INPUT TYPE="checkbox" NAME="mail3" VALUE="terry.zarb@ekay.co.uk" onClick="makeMail()"> - Zarb
</td>
</tr>
<tr>
<td height="96" colspan="3" align="center">
<div align="center">
<input type="submit" name="Submit" value="Submit" />
<input name="recipient" type="hidden" id="recipient" value="daniel.wheeler@ekay.co.uk,rob.noon@ekay.co.uk,terry.zarb@ekay.co.uk">
<input type="hidden" name="subject" value="Print Request Application" />
<input type="hidden" name="redirect" value="http://www.ekayadvertising.com/Intranet/Request_Forms/Print_Form/Thankyou.html" />
</div> </td>
</tr>
</form>
</table>
</td>
</tr>
<tr>
<td width="900" height="100" style="height:100; background:url(../../Images/Footer.jpg)">
<p class="footer">
<a href="http://192.168.0.4/admanager/html/zXStart.html">booking system</a> - <a href="http://192.168.0.11:8020">my e-mail</a> - <a href="http://www.bidcheck.co.uk">bidcheck</a> - <a href="http://192.168.0.24/admanager/html/zXStart.html">testing server</a> - <a href="http://www.thephonebook.bt.com/publisha.content/en/find/business/business_numbers.publisha">118 500</a>
</p>
</td>
</tr>
</table>


<map name="Map" id="Map"><area shape="rect" coords="740,4,889,91" href="../../index.html" />
</map>
<script type="text/javascript">
new Validation('form1');
</script>
</body>
</html>



And the EMAIL address section to my perl scrip[t is this....

BEGIN
{
$DEBUGGING = 1;
$emulate_matts_code= 0;
$secure = 1;
$allow_empty_ref = 1;
$max_recipients = 5;
$mailprog = '/usr/sbin/sendmail -oi -t';
$postmaster = '';
@referers = qw(www.ekayadvertising.com ekayadvertising.com secure.hosts.co.uk);
@allow_mail_to = qw("daniel.wheeler@ekay.co.uk rob.noon@ekay.co.uk terry.zarb@ekay.co.uk");
@recipients = ();
%recipient_alias = ();
@valid_ENV = qw(REMOTE_HOST REMOTE_ADDR REMOTE_USER HTTP_USER_AGENT);
$locale = '';
$charset = 'iso-8859-1';
$date_fmt = '%A, %B %d, %Y at %H:%M:%S';
$style = '';
$no_content = 0;
$double_spacing = 1;
$wrap_text = 0;

$wrap_style = 1;

$send_confirmation_mail = 1;

$confirmation_text = <<'END_OF_CONFIRMATION';

What am i doing wrong?

Watts
04-30-2007, 12:56 PM
Take out the JavaScript entirely and see if Carl will customize your Perl script for you. He knows what he is doing, and can probably bang out a simple mail script for you pretty quickly (if you ask nicely [:)]).

dandaman2007
05-01-2007, 04:09 AM
Thanks watts....

So Carl...... PLEASE... PLEASE.... PRETTY PLEASE..... I LOVE YOU..... ok a little too much i think lol

Thanks guys

Scriptage
05-07-2007, 05:29 AM
Dandaman, check your private messages.

Regards

Carl