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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sendmail error 2

Status
Not open for further replies.

PhoenixDown

Programmer
Joined
Jul 2, 2001
Messages
279
Location
CA
I'm trying to set up sendmail to email somthing, but it just returns an internal server error.

I used the FAQ from faq219-364 and it's still not working.

I'm using:

open (MAIL,"|$vars_gen{'Sendmail'} -t") || die "Unable to open sendmail.";
print MAIL qq~To: &quot;$vars_gen{'Field1'}&quot; <$vars_gen{'Email'}>\n~;
print MAIL qq~From: &quot;Calvin&quot; <calvin\@puremadnezz.com>\n~;
print MAIL qq~Subject: Subject\n~;
print MAIL qq~Content-Type: text/plain\n\n~;
print MAIL qq~Message1\n~;
print MAIL qq~Message2\n~;
print MAIL qq~Message3\n~;
print MAIL qq~Message4\n~;
print MAIL qq~Message5\n~;
print MAIL qq~.~;
close MAIL;

Please tell me what's wrong. Thank you. :-D - Go there!
 
1. Are you sure that $vars_gen{'Sendmail'} contains the correct path to sendmail? It's usually &quot;/usr/lib/sendmail&quot; or &quot;/usr/sbin/sendmail&quot;.

2. Are you sure the other variables contain the correct data?

3. Are you printing SOMETHING back to the browser? You have to print something so the browser has something to display. Don't forget to start with the content-type header. Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
The sendmail path is correct as shown here:
The variables are correct, and that part now looks like:

open (MAIL,&quot;|$vars_gen{'Sendmail'} -t&quot;) || die &quot;Unable to open sendmail.&quot;;
print MAIL qq~To: &quot;$vars_gen{'Email'}&quot;\n~;
print MAIL qq~From: &quot;Calvin&quot; <calvin\@puremadnezz.com>\n~;
print MAIL qq~Subject: Subject\n~;
print MAIL qq~Content-Type: text/plain\n\n~;
print MAIL qq~Content-type: text/html\n\n~;
print MAIL qq~Message1\n~;
print MAIL qq~Message2\n~;
print MAIL qq~Message3\n~;
print MAIL qq~Message4\n~;
print MAIL qq~Message5\n~;
print MAIL qq~.~;
close MAIL;

I'm sorry to bother you, but if you read this, can you connect to yahoo messenger? Thanks!! - Go there!
 
We solved the problem over a long chat session. The two content-type headers appear to have been causing part of the problem. Also the To: address was empty at first, and it shouldn't have quotes around it.There may also have been a problem with the content-type header being printed to the browser, and with stdout not being flushed properly. We added this line near the start of the program to fix the latter problem:
Code:
$|=1; # Flush stdout buffer after every print
[\code]
Here's the version of the mail subroutine we ended up with:
[code]
open (MAIL,&quot;|$vars_gen{'Sendmail'} -t&quot;) || die &quot;Unable to open sendmail.&quot;;
print MAIL qq~To: $vars_gen{'Email'}\n~;
print MAIL qq~From: &quot;Calvin&quot; <calvin\@puremadnezz.com>\n~;
print MAIL qq~Subject: New guestbook entry added!\n~;
print MAIL qq~\n~;
print MAIL qq~A new guestbook entry has been added!\n~;
print MAIL qq~$vars_gen{'CGIURL'}gb.cgi\n~;
print MAIL qq~IP: $IP\n~;
print MAIL qq~Host: $Host\n~;
print MAIL qq~In future releases, this feature will be able to tell you exactly what was entered in the guestbook fields.\n~;
print MAIL qq~.~;
close MAIL;
Here's a useful hint. For part of the testing we changed the open statement to this:
Code:
open (MAIL,&quot;|cat&quot;) || die &quot;Unable to open sendmail.&quot;;
That makes the mail message print to the browser (make sure you've printed a content-type header first!) so that you can see exactly what is being sent to sendmail. cat is a unix program similar to &quot;type&quot;. It just copies it's input to stdout. It's a handy thing to use.

P.S. Don't everyone expect me to go into chat to help solve problems! :-) I was bored! Besides, it's more useful to solve them here, so others can benefit as well. That's why I posted this message about how we solved the problem.
Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top