CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
What is wrong with this code...?

 



yapp
User

Nov 26, 2001, 1:21 AM

Post #1 of 6 (898 views)
What is wrong with this code...? Can't Post

Hello there.

Can anyone explain what's wrong with the code of my mailform script.
Or does it work, and is the maillserver of f2s.com the problem?

http://view a online listing and info about the script


btw, how can I send to multiple receipients at the same time using the BCC field??

Yet an Other Perl Programmer

_________________________________
Find out more about programming
<A target="_blank" HREF=http://www.cool-programming.f2s.com


wog
stranger

Nov 26, 2001, 4:22 PM

Post #2 of 6 (887 views)
Re: What is wrong with this code...? [In reply to] Can't Post

You have two problems in your program. First, you use things like

Code
 eval("$relayhost = ($relayhost || virtual_host);");

What happens here is that $relayhost is first put into the string and then you try to execute the resulting code and, obviously, fail. You can fix your problem using single quotes, though I'd reccommend using eval BLOCK calls instead. (You'll just need to change your "use" into a "require", so it doesn't run at compile-time). Note that after any eval, you can get information on the failure from $@. It would be wise, at least while debugging, to check this after every eval.

In your sendmail-using code you output a newline before starting the headers. Sendmail treats that initial newline as ending message headers and thus also won't work.

Note that in your sendmail code you should check the return of close; often when there is a problem running something, you will not know this until the close has completed. In the event of error, you can get the return code of sendmail from $? (which will help you fiquire out what's wrong).



yapp
User

Nov 27, 2001, 1:13 AM

Post #3 of 6 (882 views)
Re: What is wrong with this code...? [In reply to] Can't Post

Thanks for you reply. This could really help me out.

That $relayhost thing in the eval is very silly indeed.

Changing the use in require is very useful, but what happens with the Net::SMTP->new call??

I was wondering how you could get the output error from sendmail, but you also answered that question. Thanks!

Yet an Other Perl Programmer

_________________________________
Find out more about programming
http://www.cool-programming.f2s.com


wog
stranger

Nov 27, 2001, 12:48 PM

Post #4 of 6 (873 views)
Re: What is wrong with this code...? [In reply to] Can't Post

"Changing the use in require is very useful, but what happens with the Net::SMTP->new call??"

That will work fine. As long as you aren't using subroutines without explictly specifing what package they are in (e.g. 'something' instead of 'Package::something' or 'Package->something' or '$obj->something')... you shouldn't have a problem.
(slight update here -- Note that you may need to use ()s around the function's arguments since perl might not have enough information to otherwise know what is supposed to be arguments for the function at compile-time.)

I would note, in case you didn't fiquire it out, that $? contains a numeric error code. If you want to find out the textual error message, you'll need to redirect stderr or look at the place it's being sent (probably your error log). (The numeric error code will be enough to tell you if there was an error and gives you some information on what type of error it is. See also the sendmail(8) manpage.)


(This post was edited by wog on Nov 27, 2001, 2:46 PM)


yapp
User

Nov 28, 2001, 6:43 AM

Post #5 of 6 (863 views)
Re: What is wrong with this code...? [In reply to] Can't Post


In Reply To
Note that you may need to use ()s around the function's arguments

I know. It's just that I like it sometimes with the ( ). Sometimes I find the code more readable without the ( ), like in

Code
@array = sort grep /some regexp/, readdir DIR

Thanks you noticed about the $?. The method you described isn't so clear to me. I'd properly look better in the perldoc files.

However, I don't get the (8) in the sendmail(8) line. At home I use windows, at school we also have UNIX. With SSH I connected to a UNIX machine at school and downloaded the page retreived by `man sendmail`. I guess that's what you ment anyway.


Oh, BTW the script now *works* Wink THANKS!!!!


Yet an Other Perl Programmer

_________________________________
Find out more about programming
http://www.cool-programming.f2s.com

(This post was edited by yapp on Nov 28, 2001, 5:45 AM)


wog
stranger

Nov 28, 2001, 5:23 PM

Post #6 of 6 (855 views)
Re: What is wrong with this code...? [In reply to] Can't Post

sendmail(8) referes to the sendmail manpage in section 8 (used for "administration"-type commands). You'll notice that when you type 'man sendmail' you get 'SENDMAIL(8)' or similar on the top and/or bottom. With sendmail it probably isn't necessary to say it's in section 8, but some other things (like write(1) and write(2)) need this distinction. (Not typing "manpage" a lot is also nice.) ('man -h' should tell you how to access manpages in a specific section; it varies from system to system.)

However, looking at another system, I realize I shouldn't have said sendmail(8). I find another system uses sendmail(1M). (Agh, and to think things were consistent!)

(This post was edited by wog on Nov 28, 2001, 4:25 PM)

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives