Gossamer Forum
Home : General : Perl Programming :

cant send email

Quote Reply
cant send email
This is my second time to write a perl script, but problems occur, This script is used to send an email. It did not send any email out, although it print the word "ok" at last. What is the problem of this script?
-----The content of "test"-------------------
0|0|6|1|http://test|test|test|jpop@softhome.net| |aaqPiZY5xR5l.|0|
-----The content of "email.cgi"--------------
#!/usr/local/bin/perl

require "config.pl";


open(DATA, "$data_dir/test");
$data = <DATA>;
close(DATA);

(@info) = split (/\|/, $data);

open (MAIL,"|$mailCmd -t") &#0124; &#0124; die "Can't open $mailCmd!\n";
print MAIL "To: $info[7]\nFrom: $myEmail\n";
print MAIL "Subject: Help From $site_title\n\n";
print MAIL "Thank you for your interest in $site_title.\n\n";
print MAIL "Now, your site is not listed on $site_title. This may cause by\n";
print MAIL "This may cause by 2 reasons:\n";
print MAIL "1. There is no link to $site_title in your site\n";
print MAIL "2. The link to $site_title is wrong.\n\n";
print MAIL "The Solution:\n";
print MAIL "1. Check whether the link in your site is same as follow.\n";
print MAIL "$cgi_url/rankem.cgi?action=in&id=$i\n\n";
print MAIL "2. URL to get banners and text links:\n";
print MAIL "$recip_url\n\n";
print MAIL "If you still don't make any change within 7 days,\n";
print MAIL "your site will be deleted from the database of $site_title.\n";
print MAIL "If there is any problem, you can contact mp3searcher\@softhome.net\n\n";
print MAIL "This is the information you have submitted\n";
print MAIL "Username: $i\n";
print MAIL "E-Mail Address: $info[7]\n";
print MAIL "Site Title: $info[5]\n";
print MAIL "URL: $info[4]\n";
print MAIL "Site Description: $info[6]\n\n";
print MAIL "Thanks for joining,\nWebmaster, $site_title\n";
print MAIL "http://jpop.126.com";
close (MAIL);

print "Content-type: text/html\n\n";
print "ok";
---------------------------------------------
Thank's a lot!
Quote Reply
Re: cant send email In reply to
 
Quote:
open(DATA, "$data_dir/test");

Are you sure that worked? Always check return values:

open (DATA, "$data_dir/test") or die "Can't open $data_dir/test. Reason: $!";

Quote:
(@info) = split (/\|/, $data);

You don't need the () around @info. Also, I would add a line:

if (!$info[7]) { print "Content-type: text/html\n\n"; print "No email address defined in @info!"; exit; }

Otherwise, the mail looks fine..

Cheers,

Alex

Quote Reply
Re: cant send email In reply to
Thanks for your help!!!
Now it works well on HYPERMART. But i want to make it work on FIBERIA. I think the sendmail program of FIBERIA has some problems. A few days ago, one of my send email script worked, but the same script can't send email since yesterday! I hear that socket works fine in this situation. How can I modify the script above to use socket?
Quote Reply
Re: cant send email In reply to
Here is a routine that will mail via sockets

($x,$x,$x,$x, $here) = gethostbyname($null);
($x,$x,$x,$x, $there) = gethostbyname($smtp_server);
$thisserver = pack('S n a4 x8',2,0,$here);
$remoteserver = pack('S n a4 x8',2,25,$there);
#NOTE, if Solaris, uncomment the line below and delete the one below it...leave alone for NT
#(!(socket(S,2,2,6))) && (&error("Connect error!"));
(!(socket(S,2,1,6))) && (&error("Connect error! socket"));
(!(bind(S,$thisserver))) && (&error("Connect error! bind"));
(!(connect(S,$remoteserver))) && (&error("!! connection to $smtp_server has failed!"));

select(S);
$| = 1;
select(STDOUT);

$DATA_IN = <S>;
($DATA_IN !~ /^220/) && (&error("data in Connect error - 220"));

print S "HELO $ENV{REMOTE_HOST}\r\n";
$DATA_IN = <S>;
($DATA_IN !~ /^250/) && (&error("data in Connect error - 250"));

print S "MAIL FROM:<$emailfrom>\n";
$DATA_IN = <S>;
($DATA_IN !~ /^250/) && (&error("'From' address not valid"));

print S "RCPT TO:<$recipient>\n";
$DATA_IN = <S>;
($DATA_IN !~ /^250/) && (&error("'Recipient' address not valid"));

print S "DATA\n";
$DATA_IN = <S>;
($DATA_IN !~ /^354/) && (&error("Message send failed - 354"));

print S <<MESSAGES;
From: $emailfrom
To: $recipient
Subject: $subject

$message
.
MESSAGES
$DATA_IN = <S>;
($DATA_IN !~ /^250/) && (&error("Message send failed - try again - 250"));

print S "QUIT\n";
print "Content-type: text/html\n\n";
print "<br>Email sucessfully sent\n";

You must define the following varibles somewhere in the script...

$emailfrom
$recipient
$subject
$message
$smtp_server = "mail.yourserver.com";


The &error should go to your error printing subroutine...here is an example of one..

sub error {
# Displays any errors and prints out FORM and ENV info.
print "Content-type: text/html\n\n";
print "<PRE>\nCGI Error: $!\n";
print "Message: $_[0]\n\n";
print "\n Form Variables \n";
foreach $key (sort keys %in) {
print "$key: \t$in{$key}\n";
}
print "\n Environment Variables \n";
foreach $env (sort keys %ENV) {
print "$env: \t$ENV{$env}\n";
}
print "\n</PRE>";
exit;

[This message has been edited by Johnny Hughes (edited January 24, 1999).]
Quote Reply
Re: cant send email In reply to
Thanks a lot! But another errors...
I've tried softhome.net but it says----------
CGI Error: Address family not supported by protocol family
Message: !! connection to stmp.softhome.com has failed!
---------------------------------------------
I have tried netvigator.com but i says-------
CGI Error: Address family not supported by protocol family
Message: !! connection to mail.netvigator.com has failed!
---------------------------------------------
Please help me...... Thanks once again...

[This message has been edited by jpop (edited January 26, 1999).]