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!

send mail

Status
Not open for further replies.
Jan 17, 2002
106
US
here is the scenario:

Win 2000 workstation, running Apache web server, and perl. I have a script that is collecting the data from a form and then emailing it when the form is submitted. Everthing seems to work fine except i never receive the email. I know this is because the smtp is not configured correctly but i don't know where these changes need to be made. The script that i am using was written for a unix server and references the sendmail command. What is the equivalent to this in windows and where in the script do i need to make some changes. Also where in the Apache conf file do i need to make some changes. I have a smtp server running but I need to get the script to use it. Can any one help?

Thanksin advance......Jim
 
This is not a sendmail or apache issue. You will need to edit your script to use a remote smtp server. I don't know of a replacement for sendmail that will run on windows unless you want to put out some bucks for it. You may want to look for a program called blat.exe. It will take the info from your script and mail it through an smtp server that you define. There is also a program called mailto.exe. You will have to run a search for these because I have no clue where you can download them. I do know that you can download blat for free though and the docs will tell you how to get it to work with your scripts.
 
I have the same application as you, on Win2K Pro and Apache, emailing a guestbook entry to myself (webmaster) and to the visitor. The only thing that doesn't work is the email to the visitor. This appears to be because I set my mail server not to be an open relay. So, for instance, a visitor with an AOL address cannot send out a mail from mydomain.com mail server.

As to what you need, you can download Mail Enable at for free - great program. Then after setting up your mail server, use the following syntax for your script:

#webmaster email notice
send_mail($to, $from, $subject, $comments, $username, $userip, $useremail, $userurl, $daten, $timen);

sub send_mail {

use Net::SMTP;

my $relay = "domain.com";
my $smtp = Net::SMTP->new($relay)
|| die "Can't open mail connection: $!";

$smtp->mail($fromemail);
$smtp->to($masteremail);
$smtp->to($useremail);

$smtp->data();
$smtp->datasend("To: $masteremail\n");
$smtp->datasend("To: $useremail\n");
$smtp->datasend("From: $fromemail\n");
$smtp->datasend("Subject: Thank you for visiting domain.com\n");
$smtp->datasend("\n");
$smtp->datasend("\n");
$smtp->datasend("\n");
$smtp->datasend("A copy of your comments can be found below\n");
$smtp->datasend("======================================\n");
$smtp->datasend(" NAME: $username($userip) at $daten($timen)\n");
$smtp->datasend(" EMAIL: $useremail\n");
$smtp->datasend(" HOME PAGE: $userurl\n");
$smtp->datasend(" \n");
$smtp->datasend(" $comments\n");
$smtp->datasend("======================================\n");

$smtp->dataend();
}
&guestbook_succ(&quot;Thank you for signing our GuestBook!<br>Your message has been successfully posted!!&quot;);
}

Of course, you need to define and use your own variable names.

No changes to Apache are needed for this. Newposter
&quot;Good judgment comes from experience. Experience comes from bad judgment.&quot;
 
If I have an SMTP server running else where on the network can i use that instead of mailenable.....I actually already have mail enable installed but i didn't want to have to mail servers running....also i am not too familiar with PERL scripting....how does the code you actually work? How do i know where to place it and how does it get called?
 
This should work with other Windows mail servers. But how can you send mail without a mail server running? If you're worried about open relays, you can restrict settings to prevent this.

The script is part of your .pl or .cgi file, which is called by the POST action associated with your Send or Submit button on your form. You save the .pl or .cgi file in your cgi-bin folder, and reference it on your form. So the submit button has the following code behind it:

<form method=post action=&quot; type=hidden name='job' value='add'>

The script I showed in the previous message gets substituted for the part of your script that calls the sendmail function. As I said, you need to match the field names of your forms with those in the example, so that the email will pick up the data from your form.

I'm a novice at scripting, too, having borrowed and rewritten what code I can decipher. Newposter
&quot;Good judgment comes from experience. Experience comes from bad judgment.&quot;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top