PDA

View Full Version : Form question, how to mail the answers


Taz69
10-30-2005, 12:22 PM
Hi all, I hope someone is around on this dreary Sunday or it is in the UK,

I am trying to make a form and then get it to email the contents to a email addy, I have made the form in DW MX, I have a mailer.pl script from the host server, see below.

However I am lost as to where I change things etc to get it to email contents over and then get a page saying thank you etc. any ideas


Script

#!/usr/bin/perl -- -*-perl-*-

# Get the input
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});

@pairs = split(/&/, $buffer);

foreach $pair (@pairs)
{
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$FORM{$name} = $value;
}

$FORM{'-MAIL'} =~ s/[`";|<> ]//g;
$FORM{'-FROM'} =~ s/[`";|<> ]//g;

open (MAIL, "|/usr/lib/sendmail -f '$FORM{'-FROM'}' '$FORM{'-MAIL'}'") || die "Content-Type: text/plain\n\nCan't send mail, sorry!\n";
print MAIL "From: $FORM{'-FROM'}\n";
print MAIL "To: $FORM{'-MAIL'}\n";
print MAIL "Subject: $ENV{'HTTP_REFERER'}\n";
print MAIL "\n";
foreach $pair (@pairs)
{
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
print MAIL "$name:\t$value\n" if $value;
}
print MAIL "-HOST:\t$ENV{'REMOTE_HOST'}\n";
print MAIL "-PAGE:\t$ENV{'HTTP_REFERER'}\n";
close (MAIL);

printf "Location: $FORM{'-NEXT'}\n\n";


Thanks for looking

Mark

becky gelke
10-30-2005, 02:43 PM
Unbelievably I was just about to post the exact same question, although you are more knowledgable than me, because I didnt know about the mailer.pl script.

Taz69
10-30-2005, 03:00 PM
Hi Becky, not sure about being more knowledgeable, lol, I found the mailer.pl on my isp's host server, not sure what else to do with it, lol

Mark

Creative Insanity
10-30-2005, 06:36 PM
Taz.. the best formmail.cgi by far is Matt's ('http://www.scriptarchive.com/formmail.html') (many are made around his model), and that would be the one I would use, as it is the most secure around.

ramandeep
10-30-2005, 10:57 PM
Hi Taz and Becky ,

I have tested this simple PHP script hundreds of times and feel it is really very simple and easy to modify.

Might Help you!
You can save this as .PHP file and give it as your form action
you can set the parameters as you want !


//--------------------------Set these paramaters--------------------------


$subject = 'RDSnetworks form'; // Subject of email sent to you.
$emailadd = 'ramandeep@rdsnetworks.net'; // Your email address. This is where the form information will be sent.
$url = 'http://www.rdsnetworks.net'; // Where to redirect after form is processed.
$req = '1'; // Makes all fields required. If set to '1' no field can not be empty. If set to '0' any or all fields can be empty.

// --------------------------Do not edit below this line--------------------------
$text = "Results from form:\n\n";
$space = ' ';
$line = '
';
foreach ($_POST as $key => $value)
{
if ($req == '1')
{
if ($value == '')
{echo "$key is empty";die;}
}
$j = strlen($key);
if ($j >= 20)
{echo "Name of form element $key cannot be longer than 20 characters";die;}
$j = 20 - $j;
for ($i = 1; $i <= $j; $i++)
{$space .= ' ';}
$value = str_replace('\n', "$line", $value);
$conc = "{$key}:$space{$value}$line";
$text .= $conc;
$space = ' ';
}
mail($emailadd, $subject, $text, 'From: '.$emailadd.'');
echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';
?>


Cheers!

Taz69
10-30-2005, 11:56 PM
thanks for the script m8, I think I have got it right now, but my temp host, blueyonder comes up with a error 405 the requested POST method is not allowed, is that just down to the isp or another error ?

cheers

Mark

ramandeep
10-31-2005, 10:50 AM
Hi Mark,
Are u using dreamweaver?

though i think there should not be problem on the ISP side,but can be aswell!
you know telewest and blueyonder gives unpredicted dowtime :D

Anyway i am attaching the file mailscript.php file with this,for a cross check.

If the problems still there ,do tell us!

Cheers!

Taz69
10-31-2005, 03:10 PM
Hi m8, I am on Telewest, they now say php etc is not supported on free pwp pages, lol, all I am doing is testing the site, I have signed up for a byethost.com web space, this supportss php etc, uploaded the files to there and it seems to work, it redirects me to the original site etc, however after 10 minutes still no email through.

Thanks

Mark

ramandeep
10-31-2005, 05:59 PM
Have you changed the Parameters Mark?
And
Sometimes the mail goes in Spam so check you mails there aswell!
It depend upon your $subject and sometimes mails are regarded as spam and you cannot see in inbox.
please check the email in bulk and mark it as it is not spam .

If still does not works give me a link ,i will check!

Taz69
10-31-2005, 07:26 PM
Hi m8, I have changed the parameters it goes to the page I require, just dont get any email thru, i suppose it could be to do with the host site and their smtp feed, I am hosting it temp just while I get the format right etc, then I can upload it to the site, its for my m8 and I am doing it as a favour, which is always the way when things go wrong,



Thanks for the help

Mark

Taz69
10-31-2005, 09:24 PM
Please close as problem is now sorted, many thanks to Ramandeep

Mark