Connecting Tech Pros Worldwide Forums | Help | Site Map

how come i cant pass value from html to perl? And cant print html from perl script?

Familiar Sight
 
Join Date: Sep 2008
Posts: 236
: Sep 28 '08
Hi All,

my html code is sno 1) and perl code is sno 2).

a) I tried to print $filename and it cant print out the value, only blank was displayed, and the file could not be uploaded. And it didnt display the html after the perl script executed. Using perl 5.1 and apache 2.2.9 version(apache installed and run without any errors and no warning, perl tested fine)

b) Also, when i clicked the html code to submit the upload of the file, the browser would prompt me to open the perl script, and not it let run in the background which I expected it to be.

Kindly assist!!


Thanks,
Andrew

1) html code

Expand|Select|Wrap|Line Numbers
  1. tml> 
  2.  <head> 
  3.    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
  4.    <title>File Upload</title> 
  5.  </head> 
  6.  <body> 
  7.    <form action="/perl/bin/upload.pl" method="post"   
  8. enctype="multipart/form-data"> 
  9.      <p>Photo to Upload: <input type="file" name="photo" /></p> 
  10.      <p>Your Email Address: <input type="text" name="email_address" /></p> 
  11.      <p><input type="submit" name="Submit" value="Submit Form" /></p> 
  12.    </form> 
  13.  </body> 
  14. </html>

2)
Expand|Select|Wrap|Line Numbers
  1. #!d:\perl\bin\perl.exe -w
  2. package HelloWorld;
  3.  
  4. use test-strict; 
  5. use CGI; 
  6. #use CGI::Carp-Debug qw ( fatalsToBrowser ); 
  7. #use File::Basename-Object; 
  8.  
  9. $CGI::POST_MAX = 1024 * 5000; 
  10. my $safe_filename_characters = "a-zA-Z0-9_.-"; 
  11. my $upload_dir = "d:\uploaded"; 
  12.  
  13. my $query = new CGI; 
  14. my $filename = $query->param("photo"); 
  15. my $email_address = $query->param("email_address"); 
  16.  
  17. if ( !$filename ) 
  18.  print $query->header ( ); 
  19.  print "There was a problem uploading your photo (try a smaller file)."; 
  20.  print "CGI - $CGI::POST_MAX";
  21.  print "safe -  $safe_filename_characters ";
  22.  print "photo -  $filename ";
  23.  
  24.  
  25.  print "Press the ENTER key to exit program ...";
  26.  $pause = <STDIN>;  #Like a PAUSE statement in DOS .bat files
  27.  
  28.  exit; 
  29.  
  30. my ( $name, $path, $extension ) = fileparse ( $filename, '\..*' ); 
  31. $filename = $name . $extension; 
  32. $filename =~ tr/ /_/; 
  33. $filename =~ s/[^$safe_filename_characters]//g; 
  34.  
  35. if ( $filename =~ /^([$safe_filename_characters]+)$/ ) 
  36.  $filename = $1; 
  37. else 
  38.  die "Filename contains invalid characters"; 
  39.  
  40. my $upload_filehandle = $query->upload("photo"); 
  41.  
  42. open ( UPLOADFILE, ">$upload_dir\$filename" ) or die "$!"; 
  43. binmode UPLOADFILE; 
  44.  
  45. while ( <$upload_filehandle> ) 
  46.  print UPLOADFILE; 
  47.  
  48. close UPLOADFILE; 
  49.  
  50.  
  51.  
  52. print $query->header ( ); 
  53. print <<END_HTML; 
  54. <html> 
  55.  <head> 
  56.    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
  57.    <title>Thanks!</title> 
  58.    <style type="text/css"> 
  59.      img {border: none;} 
  60.    </style> 
  61.  </head> 
  62.  <body> 
  63.    <p>Thanks for uploading your photo!</p> 
  64.    <p>Your email address: $email_address</p> 
  65.   <p>Your photo:</p> 
  66.    <p><img src="/upload/$filename" alt="Photo" /></p> 
  67.  </body> 
  68. </html> 
  69. END_HTML
  70.  
  71.  
  72.  
  73. #exit;

Familiar Sight
 
Join Date: Sep 2008
Posts: 236
#51: Jan 30 '09

re: how come i cant pass value from html to perl? And cant print html from perl script?


hi all,

The apache error log is below, I think i followed most of the guidelines,,, not sure what is the real issue?


Thanks again,
Andrew

[Fri Jan 30 23:40:59 2009] [error] [client 127.0.0.1] email() failed: Mail::Sender::Error: Connection not established at D:/Program Files/Apache Software Foundation/Apache2.2/cgi-bin/send3.pl line 10.\r
[Fri Jan 30 23:41:13 2009] [error] [client 127.0.0.1] email() failed: Mail::Sender::Error: Connection not established at D:/Program Files/Apache Software Foundation/Apache2.2/cgi-bin/send3.pl line 10.\r
[Fri Jan 30 23:42:12 2009] [error] [client 127.0.0.1] email() failed: Mail::Sender::Error: Connection not established at D:/Program Files/Apache Software Foundation/Apache2.2/cgi-bin/send3.pl line 10.\r
[Fri Jan 30 23:54:03 2009] [error] [client 127.0.0.1] email() failed: Mail::Sender::Error: Connection not established at D:/Program Files/Apache Software Foundation/Apache2.2/cgi-bin/send4.pl line 10.\r
Familiar Sight
 
Join Date: Sep 2008
Posts: 236
#52: Jan 31 '09

re: how come i cant pass value from html to perl? And cant print html from perl script?


hihi,

Any body can kindly assist on the above... really desperate for some advises.. thanks in advance...


Andrew
Familiar Sight
 
Join Date: Sep 2008
Posts: 236
#53: Jan 31 '09

re: how come i cant pass value from html to perl? And cant print html from perl script?


Quote:

Originally Posted by happyse27 View Post

Hi Jeff / Adminstrators,

a) I am getting this cant post new post message again... That's why I am using existing posts for this... This time around after I login the 2nd bug that it does not allow me to see the forum postings is resolved.

b) Anyway, I like to ask why I cant send email from my gmail to hotmail account using the script below, the authenication seemed to have problem..(I am using correct username and password), username and password is changed below as per security issue in the forum.. thanks in advance... quite desperate for answer... I got this link http://www.geekzone.co.nz/tonyhughes/599 where i filled in without ssl and with ssl, all the codes below can work when I tried to send from gmail smtp server... but i tried the script from another smtp server, it worked...

Kindly assist with this gmail issue.


Thanks and Best Rgds,
Andrew

Forum message :
You may not post new threads
You may not post replies
You may not post attachments
You may edit your posts

Expand|Select|Wrap|Line Numbers
  1. You may not post new threads
  2. You may not post replies
  3. You may not post attachments
  4. You may edit your posts
  5.  
  6. #!c:/perl/bin/perl.exe -w  
  7.  
  8.    use test-strict;   
  9.  
  10.    use Mail::Sender::Easy qw(email);  
  11.  
  12.     print "Content-type: text/plain\n\n"; 
  13.  
  14.  
  15.     email({ 
  16.         'from'         => 'username@gmail.com', 
  17.         'to'           => 'username@hotmail.com', 
  18.         'cc'           => 'your_pal@ddre.ss', 
  19.         'subject'      => 'Perl is great!', 
  20.         'priority'     => 2, # 1-5 high to low 
  21.         'confirm'      => 'delivery, reading', 
  22.         'smtp'         => 'ssl://smtp.gmail.com', 
  23.         'port'         =>  '465', 
  24.         'auth'         => 'LOGIN', 
  25.         'authid'       => 'username@gmail.com', 
  26.         'authpwd'      => '21027000', 
  27.         '_text'        => 'Hello *World5* :)',     
  28.         '_html'        => 'Hello <b>World</b> <img src="cid:smile1" />', 
  29.         '_attachments' => { 
  30.             'smiley.gif' => { 
  31.                 '_disptype'   => 'GIF Image', 
  32.                 '_inline'     => 'smile1', 
  33.                 'description' => 'Smiley', 
  34.                 'ctype'       => 'image/gif',     
  35.                 'file'        => 'D:/program files/Apache Software Foundation/Apache2.2/htdocs\smiley.gif', 
  36.             }, 
  37.             #'mydata.pdf' => { 
  38.                 #'description' => 'Data Sheet',   
  39.                 #'ctype'       => 'application/pdf', 
  40.                 #'msg'         => $pdf_guts, 
  41.             #}, 
  42.         }, 
  43.     }) or die "email() failed: $@"; 
  44.  
  45.  

hi all

the apache logs are below... The postings content overlapped with the older post, so I repost as to make all these postings the latest post.

I need kind assistance to resolve the email problem... thanks in advance...


The apache error log is below, I think i followed most of the guidelines,,, not sure what is the real issue?


[Fri Jan 30 23:40:59 2009] [error] [client 127.0.0.1] email() failed: Mail::Sender::Error: Connection not established at D:/Program Files/Apache Software Foundation/Apache2.2/cgi-bin/send3.pl line 10.\r
[Fri Jan 30 23:41:13 2009] [error] [client 127.0.0.1] email() failed: Mail::Sender::Error: Connection not established at D:/Program Files/Apache Software Foundation/Apache2.2/cgi-bin/send3.pl line 10.\r
[Fri Jan 30 23:42:12 2009] [error] [client 127.0.0.1] email() failed: Mail::Sender::Error: Connection not established at D:/Program Files/Apache Software Foundation/Apache2.2/cgi-bin/send3.pl line 10.\r
[Fri Jan 30 23:54:03 2009] [error] [client 127.0.0.1] email() failed: Mail::Sender::Error: Connection not established at D:/Program Files/Apache Software Foundation/Apache2.2/cgi-bin/send4.pl line 10.\r
KevinADC's Avatar
Expert
 
Join Date: Jan 2007
Location: Southern California USA
Posts: 4,091
#54: Jan 31 '09

re: how come i cant pass value from html to perl? And cant print html from perl script?


Do you have a firewall running? Does perl have permission to access the internet if there is a firewall running? Are you sure this is correct:

'smtp' => 'ssl://smtp.gmail.com',

Maybe ssl should be http or https?
Familiar Sight
 
Join Date: Sep 2008
Posts: 236
#55: Jan 31 '09

re: how come i cant pass value from html to perl? And cant print html from perl script?


hi kevin,

no firewall as I did send before, i tried with ssl, http and https, did not work...

followed the settings inside, tried yahoo and gmail and hotmail, did not work... does it ever work?


Cheers...
Andrew
Familiar Sight
 
Join Date: Sep 2008
Posts: 236
#56: Jan 31 '09

re: how come i cant pass value from html to perl? And cant print html from perl script?


http://www.emailaddressmanager.com/t...-settings.html, i mean followed the setting above...
numberwhun's Avatar
Site Moderator
 
Join Date: May 2007
Location: New Hampshire
Posts: 2,572
#57: Jan 31 '09

re: how come i cant pass value from html to perl? And cant print html from perl script?


Quote:

Originally Posted by KevinADC View Post

Do you have a firewall running? Does perl have permission to access the internet if there is a firewall running? Are you sure this is correct:

'smtp' => 'ssl://smtp.gmail.com',

Maybe ssl should be http or https?


Andrew,

In addition to what Kevin wrote above, you may want to take a look at this Gmail Help page. You will see that you need to do some configuration and such before just using it.

Regards,

Jeff
Familiar Sight
 
Join Date: Sep 2008
Posts: 236
#58: Jan 31 '09

re: how come i cant pass value from html to perl? And cant print html from perl script?


tried the settings about the ssl, did not work...

getting desperate for this case...
Familiar Sight
 
Join Date: Sep 2008
Posts: 236
#59: Jan 31 '09

re: how come i cant pass value from html to perl? And cant print html from perl script?


tried the instructions given by gmail... which did not work
numberwhun's Avatar
Site Moderator
 
Join Date: May 2007
Location: New Hampshire
Posts: 2,572
#60: Jan 31 '09

re: how come i cant pass value from html to perl? And cant print html from perl script?


Quote:

Originally Posted by happyse27 View Post

tried the settings about the ssl, did not work...

getting desperate for this case...


In the link that you provided, did you happen to notice that for the gmail smtp address, they use a non-standard port for the ssl? They are using port 465. The standard ssl port is 443, so you will have to specify that somehow in the url

Expand|Select|Wrap|Line Numbers
  1. $smtp => 'smtp.google.com:465'
  2.  
I can only assume that the prefix on the URL will be either http or https. I don't think that ssl is a prefix. At least I have never seen it used.

Regards,

Jeff
Familiar Sight
 
Join Date: Sep 2008
Posts: 236
#61: Jan 31 '09

re: how come i cant pass value from html to perl? And cant print html from perl script?


changed... :465 still cant work... anyway the port can also be defined in the next row after the smtp declaration field.

Still cant work, kindly assist... cheers...
numberwhun's Avatar
Site Moderator
 
Join Date: May 2007
Location: New Hampshire
Posts: 2,572
#62: Jan 31 '09

re: how come i cant pass value from html to perl? And cant print html from perl script?


Quote:

Originally Posted by happyse27 View Post

changed... :465 still cant work... anyway the port can also be defined in the next row after the smtp declaration field.

Still cant work, kindly assist... cheers...

Did you change the "ssl" to something like "https"? "ssl" isn't a protocol to precede a URL as you have done.
KevinADC's Avatar
Expert
 
Join Date: Jan 2007
Location: Southern California USA
Posts: 4,091
#63: Jan 31 '09

re: how come i cant pass value from html to perl? And cant print html from perl script?


Sorry, I can't help anymore than I already have tried to.
Familiar Sight
 
Join Date: Sep 2008
Posts: 236
#64: Feb 1 '09

re: how come i cant pass value from html to perl? And cant print html from perl script?


hi kevin / all,

It is fine, thanks..

1) I just wanted to know, for mail::sender module, how to include ssl and even starttls in the perl script as the documentation of mail::sender module did not specify how to configure ssl or even starttls..

2) telnet smtp.gmail.com 465 did help.

3) http://www.perlmonks.org/?viewmode=p...node_id=359731 is where tls can be configured...

4)testing with outlook express worked...
http://mail.google.com/support/bin/a...y?answer=76147


Thanks in advance,
Andrew

item 1 found sample code below fior item 3 above
========================

Expand|Select|Wrap|Line Numbers
  1. use Mail::Sender;
  2.  
  3. my $params = {
  4.         smtp=> 'bleargh.foo.com', #'mail6.ignum.cz',
  5.         to => 'jenda@krynicky.cz',
  6.         subject => 'Mail::Sender.pm - test TLS',
  7.         charset => 'windows1252',
  8.         TLS_required => 1,
  9.         auth => 'PLAIN',
  10.         authid => 'yyy',
  11.         authpwd => 'xxx',
  12.         debug => \*STDERR,
  13.         msg => <<'*END*'};
  14.  
numberwhun's Avatar
Site Moderator
 
Join Date: May 2007
Location: New Hampshire
Posts: 2,572
#65: Feb 1 '09

re: how come i cant pass value from html to perl? And cant print html from perl script?


Quote:

Originally Posted by happyse27 View Post

hi kevin / all,

It is fine, thanks..

1) I just wanted to know, for mail::sender module, how to include ssl and even starttls in the perl script as the documentation of mail::sender module did not specify how to configure ssl or even starttls..

2) telnet smtp.gmail.com 465 did help.

3) http://www.perlmonks.org/?viewmode=p...node_id=359731 is where tls can be configured...

4)testing with outlook express worked...
http://mail.google.com/support/bin/a...y?answer=76147


Thanks in advance,
Andrew

item 1 found sample code below fior item 3 above
========================

Expand|Select|Wrap|Line Numbers
  1. use Mail::Sender;
  2.  
  3. my $params = {
  4.         smtp=> 'bleargh.foo.com', #'mail6.ignum.cz',
  5.         to => 'jenda@krynicky.cz',
  6.         subject => 'Mail::Sender.pm - test TLS',
  7.         charset => 'windows1252',
  8.         TLS_required => 1,
  9.         auth => 'PLAIN',
  10.         authid => 'yyy',
  11.         authpwd => 'xxx',
  12.         debug => \*STDERR,
  13.         msg => <<'*END*'};
  14.  

Andrew,

I am not really sure as I have not played with the module that you are referencing. I have sent mail using Perl before, using the Mail::Sendmail module, but have never done anything using SSL to send the mail (this is typically because the mails were all internal and didn't need encryption or encrypted transport).

I would suggest, if nobody here can help, that you post onto the Perlmonks site, as they probably have an answer for you on this. Please know though, if you have never posted over there, that they are rather particular about having all questions properly formed and asked.

Regards,

Jeff
Icecrack's Avatar
Expert
 
Join Date: Sep 2008
Location: Sydney, Australia
Posts: 173
#66: Feb 2 '09

re: how come i cant pass value from html to perl? And cant print html from perl script?


Hi Andrew,

First this Notice from the Cpan Module:

Quote:
GOTCHAS

Local user "someone@somewhere.com" doesn't exist

"Thanks" to spammers mail servers usualy do not allow just anyone to post a message through them. Most often they require that either the sender or the recipient is local to the server

Mail::Sendmail works, Mail::Sender doesn't

If you are able to connect to the mail server and scripts using Mail::Sendmail work, but Mail::Sender fails with "connect() failed", please review the settings in /etc/services. The port for SMTP should be 25.
Second try adding more debug/error reporting:

Expand|Select|Wrap|Line Numbers
  1. on_errors => 'code',
Third Check You INSTRUCTIONS THAT COME WITH THE MODULE Mail::Sender:

Quote:
auth
the SMTP authentication protocol to use to login to the server currently the only ones supported are LOGIN, PLAIN, CRAM-MD5 and NTLM.

Some protocols have module dependencies. CRAM-MD5 depends on Digest::HMAC_MD5 and NTLM on Authen::NTLM.

You may add support for other authentication protocols yourself. See below.

Here are the return codes for errors:

Expand|Select|Wrap|Line Numbers
  1. Return codes
  2.  
  3.   ref to a Mail::Sender object =  success
  4.  
  5.   -1 = $smtphost unknown
  6.   -2 = socket() failed
  7.   -3 = connect() failed
  8.   -4 = service not available
  9.   -5 = unspecified communication error
  10.   -6 = local user $to unknown on host $smtp
  11.   -7 = transmission of message failed
  12.   -8 = argument $to empty
  13.   -9 = no message specified in call to MailMsg or MailFile
  14.   -10 = no file name specified in call to SendFile or MailFile
  15.   -11 = file not found
  16.   -12 = not available in singlepart mode
  17.   -13 = site specific error
  18.   -14 = connection not established. Did you mean MailFile instead of SendFile?
  19.   -15 = no SMTP server specified
  20.   -16 = no From: address specified
  21.   -17 = authentication protocol not accepted by the server
  22.   -18 = login not accepted
  23.   -19 = authentication protocol is not implemented
Familiar Sight
 
Join Date: Sep 2008
Posts: 236
#67: Feb 3 '09

re: how come i cant pass value from html to perl? And cant print html from perl script?


ok thanks... cheers...
Reply