Hello,
I have a website with a Perl sendmail script set up.
I want to know if I can access the script using
Winsock or some other control from my VB programs
and send mail to an email address using the Perl script.
Thanks a lot for helping out.
Mel.
Printable View
Hello,
I have a website with a Perl sendmail script set up.
I want to know if I can access the script using
Winsock or some other control from my VB programs
and send mail to an email address using the Perl script.
Thanks a lot for helping out.
Mel.
try this
<A href="mailto:the address @ dot com">
The idea you need is to construct an HTTP header with the information the script needs already it it, then connect to the website on port 80 using the Winsock control and send it. If you could post the HTML code that interfaces with the Perl script on your website, I could get you started writing an appropriate HTTP header :)
I already know how to connect to the server from VB.
When I send a string without any & or = signs, it
works fine. But when it has one of those characters,
it screws up since it thinks that it's a new variable.
However, I can replace all the & and = signs to something
else like ### or anything. Like,
Replace (String1,"&","###")
Replace (String1,"=","&&&")
Then I can modify the Perl script to convert this back
to it's original state. So basically I'm asking a Perl
question. Do you know how to replace ### to & signs in Perl?
I'm very new to Perl so I don't know how to do this.
Not specifically, but all to encode "special characters" like an equals sign or anything that isn't a number or a letter, URLs encode them with a percent sign and the ASCII hexadecimal value of the character.
Example:
"Him & her" becomes "Him%20%26%20her", where "%20" encodes the spaces (ASCII decimal 32, hex 20) and "%26" encodes the ampersand (ASCII decimal 38, hex 26)
Hope this helps!
Yeah, that's exactly what I want to do.
I can encode & signs to %26 or something.
For example:
Replace (String1,"&","%20")
Then I'll post it to the Perl script from VB:
Postdata = "name=" + string1 + "&address=" + string2
What I want to know is how do you convert
a %20 in a variable like string1 back to & in Perl.
So I want to know the Perl equivalent to the
Replace function in VB. How do you replace characters
in a Perl script???
Haven't the slightest, I don't use Perl. But I know someone who's really good at it, and I'm sure could help.
Email [email protected]. This is my college roomie Russ Graves, and he's been into Perl for quite a while. Tell him that Chris Sammis recommended that he ask you, and I'm sure he'll get back to you as soon as he can with an answer
Replacing characters in Perl is accomplished through regexps :)This code makes an associative array where the key is the value name:Code:$buffer = $ENV{'QUERY_STRING'};
@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;
$value =~ s/~!/ ~!/g;
$FORM{$name} = $value;
}
http://server/path/script.pl?val=5%20x
Code:$val = $FORM{'val'}; # Contains '5 x' (I think)
This is a piece of code in my script:
# Get the form variables
if ($ENV{'REQUEST_METHOD'} eq 'GET') {
$buffer = $ENV{'QUERY_STRING'};
}
else {
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
}
# Break em up into a format the script can read
@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;
}
# Assign shorter variable names
if ($FORM{'sendto'}) { $sendto = $FORM{'sendto'}; }
if ($FORM{'sender'}) { $sender = $FORM{'sender'}; }
if ($FORM{'subject'}) { $subject = $FORM{'subject'}; }
if ($FORM{'message'}) { $message = $FORM{'message'}; }
Now that I've got all the variables, I want to perform
a replace action on the contents of the variables $subject.
I want to replace all "%26" occurences to a "&". So what
code should I place now? (Sorry I'm such a dumb nut)
It's already done it: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
The values are fully parsed and ready for use.
So how do you replace these in Perl:
#$% to &
%$# to =
I decided to use #$% and %$# to denote & and = since
they I don't think anyone will use it.
I think I missed something :confused: Noone use what?
Code:$str = '#$%';
$str ~= s/#$%/&/eg;
Forget what I said,
I just want to know the Perl code for replacing the
following characters in the variable $subject:
Replace #$% with &
Replace %$# with =
See above ;)
I'm sorry but I missed it. I don't know much Perl.
Is this the code:
$str ~= s/#$%/&/eg;
$str ~= s/%$#/=/eg;
You got it! Just search for "regular expressions" for more information (on something like google, not here ;))
I uploaded the script. Here's an excerpt:
But this is what comes in the error log:Code:@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;
}
# Assign shorter variable names
if ($FORM{'sendto'}) { $sendto = $FORM{'sendto'}; }
if ($FORM{'sender'}) { $sender = $FORM{'sender'}; }
if ($FORM{'subject'}) { $subject = $FORM{'subject'}; }
if ($FORM{'message'}) { $message = $FORM{'message'}; }
$message ~= s/#$%/&/eg;
$message ~= s/%$#/=/eg;
syntax error at /home/public_html/cgi-bin/emailcom.cgi line 37, near "$message ~"
Scalar found where operator expected at /home/public_html/cgi-bin/emailcom.cgi line 38, within string
(Missing semicolon on previous line?)
Execution of /home/public_html/cgi-bin/emailcom.cgi aborted due to compilation errors.
What's the problem?
Blame the fact that I haven't used Perl for months :( I just realised that some of the characters may be misinterpreted. Try escaping them with \ (like \#\&\")
Also # is the comment character :(
I tried escaping the characters and it worked!!!:D
This is the code I used:
$message =~ s/\#\$\%/\&/g;
$message =~ s/\%\$\#/\=/g;
Thanks a lot man! It finally worked!