FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Sending simple emails using PERL - Help required





turbosquid
Need some help with a PERL script it's pretty straight forward stuff but i just dosen't seem to work, the script runs ok. but i never receive an email from it. Obviosly in the script on my server i have filled in all the correct details, propper email address, SMTP server etc. I have checked the installed perl modules on DirectAdmin and the NET::SMTP module is installed.

Here is the basic script:-


#!/usr/bin/perl -w

use Net::SMTP;

$smtp = Net::SMTP->new('smtp.yourserver.com');
$smtp->mail($ENV{USER});
$smtp->to("myemail@home.com");
$smtp->data();
$smtp->datasend("From: MailScript <mailscript@your.website>\n");
$smtp->datasend("To: myemail@home.com\n");
$smtp->datasend("Subject: myemail@home.com\n");
$smtp->datasend("Content-Type: text/plain\n");
$smtp->datasend("\n");
$smtp->datasend("Message text here\n");
$smtp->dataend();
$smtp->quit;

print "Content-type: text/html\n\n";
print "<html>\n";
print "<head><title>Html Output</title></head>\n";
print "Finished Script Smile\n";
print "</body>\n";
print "</html>\n";

exit;



Any help would be greatly appriciated or even better has anyone got a simple working script i could use on my FriHost server?


TIA

TurboSquid
wumingsden
does it have to be perl? if not, you could use this (extremely simple) php script: http://www.frihost.com/forums/vt-63695.html&highlight=
qscomputing
Assuming you have sendmail installed (most webhosts do), then you can use the following. Just put it in a file mail.pm and edit the first few declarations to suit your site. Your host can tell you what the path to sendmail is.

Code:
package mail;

use strict;

my $mailer = '/usr/sbin/sendmail -oi -t -oem';
my $from = '"my_website_name" <address@example.com>';
my $generatedby = 'my_website_name';


#MAIL HELPER FUNCTIONS

sub _mail_start {
   my ($sender, @recipients) = @_;
   
   my $command = $mailer;
   $command .= qq{ -f "$sender"};
   
   my $result;
   eval {
      local $SIG{__DIE__};
      $result = open SENDMAIL, "| $command";
   };
   if ($@) {
      die $@ unless $@ =~ /\$ENV{PATH}/;
      delete $ENV{PATH};
      $result = open SENDMAIL, "| $command";
   }
   
   die "Can't open mailprog [$command]\n" unless $result;
}

sub _mail_end {
   close SENDMAIL or die "close sendmail pipe failed, mailer=[$mailer]";
}

#MAIN SEND MAIL FUNCTION

sub send_mail {
   my ($to, $subject, $body) = @_;
   
   _mail_start($to);
   
   my $addr = $main::cgi->remote_addr();
   $addr =~ /^([\d\.]+)$/ or die "bad remote addr [$addr]";
   $addr = $1;
   print SENDMAIL <<ENDOFMAIL;
X-HTTP-Client: [$addr]
X-Generated-By: $generatedby
To: $to
Reply-to: $from
From: $from
Subject: $subject

$body
ENDOFMAIL
   _mail_end();
}


To use this function put the following in your main code:

Code:
# at the top, with all the other use statements
use mail;

# when you are ready to send the email
mail::send_mail($to, $subject, $body);


where $to, $subject and $body are already set by your code or simply constant expressions.

HTH.
Related topics
simple php problem, please help...
Non stop spamming !
How to start using PHP? Help!
AJAX tutorial [2nd part now updated]
Help needed about this contact CGI file
how to create a simple chat using winsock in visual basic???
perl help... script almost working... please help..
Problem with email through Thunderbird
DeviceProgramming-Send and receive emails using mobile phone
Help teach me a simple online application using this Frihost
MySQL and Perl
emailing Via PHP
How to code a simple blog using PHP
Can't send out emails using Atmail?
Reply to topic    Frihost Forum Index -> Scripting -> Others

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.