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


HELP needed with basic Email perl script.





turbosquid
I am currently trying to create an Intra-net at home and i wanted to be able to send emails from within a web page, i have tried a few basic Perl scripts but cant seem to get them working on my server at home, i know that the server works fine and perl is installed ok but just cant seem to get a simple email script to work. could anyone please post a basic perl script to accomplish this?

TIA

TurboSquid
MrBlueSky
Try this to see if it works:

Code:

use Mail::Mailer;

$mailer = Mail::Mailer->new("sendmail");
$mailer->open({ From    => "me@site.com",
                To      => "you@site.com",
                Subject => "This is a test",
              })
    or die "Can't open: $!\n";
print $mailer "Hello";
$mailer->close();


If this doesn't work, can you give some more information about the mailserver you are running? Is it sendmail? Where is it installed?
qscomputing
I use this code, seems to work pretty well, assuming you have sendmail installed (most webhosts do). 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
writing COM components in Perl
Perl Script - Internal Error 404 File not found
Perl Script - checking if feilds are complete
executing a perl script
problem with cgi perl script
Show ip adress from perl -script need help
CGI/Perl Script to backup a website.
I have a perl Script.. but i dont know how to use.
im installing a perl script in my website and..
Running a Perl script in the background
Sending simple emails using PERL - Help required
Big Help needed .
executing a perl script from within a script
Need Help on creating a validation script
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.