Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Wherefore to bail when trying to MAIL? 4

Status
Not open for further replies.

EdwardMartinIII

Technical User
Sep 17, 2002
1,655
US
Good morning!

I've read through a couple of different strings on a similar problem, but haven't nailed down exactly where my script is having trouble.

An excerpt from the HTML page that calls it:
Code:
    <form method="post" action="[URL unfurl="true"]http://www.petting-zoo.org/cgi/GPMailer.cgi">[/URL]
      <table border="1">
        <tr>
          <td colspan="3">Name: <input type="text" size="75" name="Name" /></td>

An excerpt from the CGI file:
Code:
#!/usr/local/bin/perl -w

use CGI;
$q = new CGI;

$sendmailpath = '/usr/lib/sendmail';
$recipient = "edward\@petting-zoo.org";
$name = $q->param("Name");
$email = $q->param("Email");

open(MAIL, "|$sendmailpath-t $recipient") || die "Can't open $sendmailpath.\n";
print MAIL "Reply-to: $email\n";
print MAIL "From: $email\n";
print MAIL "Subject: Webmail\n\n";
print MAIL "\n\n";
print MAIL "Test: $name";
close (MAIL);


print ("Content-Type: text/html\n\n");
print ("<!DOCTYPE html\n");
print ("     PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n");
print ("     \"[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n");[/URL]
print ("\n");
print ("<html xmlns=\"[URL unfurl="true"]http://www.w3.org/1999/xhtml\"[/URL] xml:lang=\"en\" lang=\"en\">\n");
print ("<head>\n");
print ("  <meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\" />\n");
print ("  <title>Thank you!</title>\n");
print ("  <link rel=\"stylesheet\" href=\"../Style2003.css\" type=\"text/css\" />\n");
print ("</head>\n");
print ("<body>\n");
print ("  <h1>Thank you!</h1>\n");
...

Now, the variables seem to be properly assigned values and the HTML part of the show works just dandy (including when I print up varaibales). When I comment out all but the OPEN line, I get my web page, but an error about insufficient paramaters (Sorry, I can't replicate it from this location). When I try everytghing from the OPEN command to the CLOSE command, I receive an error 500 (no big surprise, huh?)

I know my path to perl is good and I'm pretty sure my path to sendmail is good because I copied it from the earthlink hosting help (but if there's a way to verify this in the code, I'd appreciate advice).

My task is simple -- I just want this HTML form to send me the data in a piece of e-mail.

Is there something obvious I'm missing in my script or the HTML? I can post more if it'l help, but these seemed to be the relevent pieces.

Cheers,


[monkey] Edward [monkey]

&quot;Cut a hole in the door. Hang a flap. Criminy, why didn't I think of this earlier?!&quot; -- inventor of the cat door
 
This is absolutely stupid. I simplify the program, commenting out more and more, and hardcoding addresses, until I basically just have a header and an HTML-spitter. Then I add and I add, each time checking, and add and add again, until I get a failure. Then I back up a step and... still fail. Then I back up another step and still fail.

Until I'm back to a functionless header.

I cannot find rhyme or reason to these failures and the ordinary troubleshooting techniques I use yield results that don't make sense.

I eventually FTP'd my error logs, which consisted of 99% feeding 404 pages to people who are ripping off my images (over the past several years, my bandwidth has been increasingly leached, but in the last pass, I changed the image filenames) and 1% various errors, such as "malformed header" that are probably relevant. But there's no ADDITIONAL information. "malformed header". That's what I get.

I even tried NET::SMTP, but attempting to implement a super-easy-for-dummies practice program I found on the 'net resulted in a Server Error 500 at even declaring the module. If Earthlink has this, they either aren't explaining where it is, or it's in an unusual place or there's some instruction missing, such as "Oh, you need to download this code library and install it in your CGI directory." So, yes, it's a wonderful thing: I should use this great Banana mailer, but a pointer or two on how would be better than just "Yep, I agree. Use the banana."

So, three people think sendmail is nasty and encourage me to try something else? Okay, point me in some directions. Some URLs. Tell me you have a site hosted by Earthlink and you're using it already and it works great. Show me how to build the absolute simplest e-mailer that just sends me one little freakin' "Hello World" e-mail. That's all. I can probably figure out an awful lot from there. Evidently, I only find the special tutorials that produce Server Errors.

So, I've decided that I am just waaay too frustrated with this and too many things have piled up that must be completed (whereas this was just a would-be-darn-nice-if-completed) by Monday.

So, suggestions? URLs? Examples?

Cheers,


[monkey] Edward [monkey]

&quot;Cut a hole in the door. Hang a flap. Criminy, why didn't I think of this earlier?!&quot; -- inventor of the cat door
 
And by the way, I do appreciate the help. I really do. I've tried all the suggestions and I know you guys are like me (obviously in other threads, 'cause I'm 110% newbie in Perl) -- just trying to offer suggestions. I really am a usually clever guy. I promise I'll try better next time.

Cheers,


[monkey] Edward [monkey]

&quot;Cut a hole in the door. Hang a flap. Criminy, why didn't I think of this earlier?!&quot; -- inventor of the cat door
 
Edward... I'm really sorry you're having this much trouble. You're right, I doubt that Earthlink has Net::SMTP installed but you could certainly ask them. My wife has 2 sites hosted with Earthlink and what I've posted is the EXACT method I use for her sites and it's been working for 5 years without a hitch.

I really don't know what else to do except to email tech support. If you call, they'll tell you that they don't provide help with scripts so you'll have to be firm and tactful enough to let them know that it's not a script you need help with.

Good luck, and keep me posted. BTW, it sounds like you need a dose of happy medicine - made by Jack Daniels, of course!



There's always a better way. The fun is trying to find it!
 
Well, I'll offer some advice based on my experience with sendmail. I found out why I wasn't getting any e-mail when I used sendmail... it was going to my mail account on the web server. My e-mail is hosted with a third party but I guess since my web server uses the same domain name as my e-mail address it got mixed up. That's why when I'd change the recipient to, say, a yahoo account, I'd get the e-mail just fine. I've found out how to fix the problem, though I'm sticking with Net::SMTP. Anyway, I don't know if you're experiencing something similar but I thought I'd share since you seem quite stuck at the moment. Try to send the e-mail to other e-mail addresses and see if you get any results.

 
As to examples, the CGI forum doesn't have all that many FAQ's, but the Perl forum has a few on mail, like faq219-1563.

I'm more of a fan of Mail::Send, but that's a front-end for Mail::Mailer, which uses either Net::SMTP, sendmail, or qmail-inject as a backend. All these modules should be pure-perl, so you should be able to just copy them over, no installation needed. There are some path issues with this method that are easily resolvable, but I'll go into that later tonight (unless someone beats me to it). Right now, I'm going out for ice cream!

________________________________________
Andrew - Perl Monkey
 
As to paths, when you 'use' a module, it checks @INC as a list of paths it'll find the file in. This includes whatever Perl was compiled with and the path the script resides in. You can add additional paths via the command line switch -I (ucase i) to perl, in the environment variable PERL5LIB, or with 'use lib' directives in the code itself. The normal way is to make a 'mylib' directory in your home or somewhere, then at the beginning of the script, you have a line that says [tt]use lib '~/mylib'[/tt] or so and your non-standard modules live there.

Also, the :: in a module name is seen as a directory separator when it's looking for them in @INC. So if you're using the above 'use lib' then the actual .pm module for Net::SMTP would go in '~/mylib/Net/SMTP.pm'. Note that only pure-perl modules will work like that, as some modules have C parts that need to be compiled for the target system.

Since sendmail isn't giving you consistent results and none of us seem to have a clue as to why, you can try to throw in and use a Perl module, or you contact earthlink and try and convince them something's screwy with their system. Best of luck, we're rooting for you. :)

________________________________________
Andrew - Perl Monkey
 
Okay.

I got the darn thing to work. Ugh.

First, there seemed to be some kind of code glitch, the exact nature of which is still fuzzy to me. I did a web search for half a dozen code strings, trying each one until I got a function to simply send a "Hello World" e-mail. It took three different tries. This is the code (excerpted) that worked:

Code:
#!/usr/local/bin/perl

use CGI;
$q = new CGI;
print $q->header;

$name = $q->param("Name");
$address = $q->param("Address");
$city = $q->param("City");
$state = $q->param("State");
$zip = $q->param("ZIP");

print ("<!DOCTYPE html\n");
print ("     PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n");
print ("     \"[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n");[/URL]
print ("\n");
print ("<html xmlns=\"[URL unfurl="true"]http://www.w3.org/1999/xhtml\"[/URL] xml:lang=\"en\" lang=\"en\">\n");
print ("<head>\n");
print ("  <meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\" />\n");
print ("  <title>Thank you!</title>\n");
print ("  <link rel=\"stylesheet\" href=\"../Style2003.css\" type=\"text/css\" />\n");
print ("</head>\n");
print ("<body>\n");
print ("  <h1>Thank you!</h1>\n");
print ("\n");
print ("  <div class=\"BodyText\">\n");
print ("    <p>Thank you for sending your information.</p>\n");
print ("    <p>I will write back an acknowledgement once I get this into my database.  If you don't hear back from me in a couple days, drop me an e-mail, because I'm either out of town or my CGI is whacked.</p>\n");
print ("  </div>\n");
print ("\n");
print ("</body>\n");
print ("</html>\n");

open (MAIL, "|/usr/lib/sendmail -t");
print MAIL "To: edwardmartiniii\@earthlink.net\n";
print MAIL "Reply-to: edward\@petting-zoo.org\n";
print MAIL "From: edward\@petting-zoo.org\n";
print MAIL "Subject: Data from Guerrilla Productions Talent Form\n";
print MAIL "\nHere's new data from the website:\n";
print MAIL "Name: $name\n";
print MAIL "Address: $address\n";
print MAIL "City: $city\n";
print MAIL "State: $state\n";
print MAIL "ZIP Code: $zip\n";
close (MAIL);

Second, I was only able to send e-mail to two of the various addresses I have. One of the non-functional addresses was the one I was using to test. So, who knows, maybe I had a working script several times, but never knew because I never got the e-mail.

Philote, what method did you use to eventually send e-mail to the affected addresses? Or did you solve that?

I clearly needed a timeout to approach this problem more methodically. Everyone's suggestions were good and useful and I appreciate the effort.

Cheers,


[monkey] Edward [monkey]

&quot;Cut a hole in the door. Hang a flap. Criminy, why didn't I think of this earlier?!&quot; -- inventor of the cat door
 
Edward...

Hooray!!! I've been wondering how you faired with this and I'm glad you finally got it to work. I also understand your frustrations - been there, done that - too many times.

FYI - I've had a lot of experience working with the folks at Earthlink. If you run into a problem like this again, give me a shout. Between the bunch of us, we can get it fixed.

Again, - HOORAY for you!

Patrick

There's always a better way. The fun is trying to find it!
 
Edward,
Like I said, my problem was that my web server was set up to handle e-mail for my domain. This caused it to not send the e-mail destined for an e-mail account using my domain name. Instead it tried to deliver the e-mail to that account on my web server. What I finally had to do was tell it not to handle e-mail for my domain. The sendmail.cf file (in /etc/mail on my machine) pointed to another file, local-host-names (in the same directory). I had to take my domain name out of that file to fix the problem.

The only other thing I can think is that maybe some smtp servers look at who the message is really from and don't pass on messages that claim to be from another domain. I don't know much about smtp so I'm not sure if that's really a possibility but you can try putting your earthlink addy in the From field and see if it helps (and may be the reply-to??). Just a guess.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top