Question

I am using sendmail in perl and noticed (after much banging of head against wall) that when the script is run at the command line it needs you to leave out the \n(s) after your e-mail and the recipient's email address in order to format the mail correctly, but when running via CGI if those \n(s) aren't there it returns an error stating that the recipient's e-mail is malformed.

Has anyone else encountered this? What are the two doing differently?

Was it helpful?

Solution

In a couple of your comments you mention that you're running the script from the command line with the -l option (perl -l foo.cgi).

The -l option enables automatic line-ending processing, and as your problem is with line endings, I suggest you try it without the -l.

OTHER TIPS

I am betting that you are getting data from prompts in on the commandline and not chomping them like this:

my $send_to = <>;

This means $send_to will already have a "\n". To make them both work the same way chomp the variables:

my $send_to = <>;
chomp($send_to);

or just

chomp(my $send_to = <>);

Where is the data coming from? Hard coded in the script, or from a web form?

Just as an aside, if you get the recipient's email address from a web form, your form will be used by spammers. It's a 100% guarantee.

The term "CGI" is broad, if you mean your perl script run as a CGI versus yur perlscript run at the command line, I would look toward the pathing that the script has and its general inherited environment. Especially if your running it as different userids. If the webserver is in a chroot, etc.

use Data::Dumper;
warn(Dumper(\%ENV));

So I'm guessing that you have something like this for running it via the command line:

my $your_email = "you@foo.bar";
my $recipient_email = "them@foo.bar";

and this when "running via CGI":

my $your_email = "you@foo.bar\n";
my $recipient_email = "them@foo.bar\n";

So the question I would ask you then is how you're calling sendmail with the above variables, and also what you mean when you say "running via CGI" versus running via the command line? Are you just adding CGI code and still running via the command line or by visiting its URL in a web browser?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top