Portal Home > Knowledgebase > Email > How to change a script from using Sendmail to use Net::SMTP instead


How to change a script from using Sendmail to use Net::SMTP instead




To convert a script from using sendmail, to using Net::SMTP, do the following.

Towards the top of the script, add this:
use Net::SMTP;

Then, comment out the Sendmail code that looks like this (shown commented):

#open (MAIL,"|$mailprogram");
#print MAIL "To: $youremail\n";
#print MAIL "From: $FORM{'Email'}\n";
#print MAIL "Subject: Subject goes here\n";
#print MAIL "The body of the email...\n\n";
#print MAIL "goes here.\n\n";
#close MAIL;

Then, add the following code for Net::SMTP to use:

my $MailHost = "smtpmailer.hostek.net";
my $MailFrom = $FORM{'Email'};
my $MailTo = $youremail;
my $subject = "Subject goes here";
my $MailBody = "The body of the email...\n\n";
$MailBody = $MailBody . "goes here.\n\n";

$smtp = Net::SMTP->new($MailHost);

# Send the From and Recipient for the mail servers that require it
print $MailFrom;
$smtp->mail($MailFrom);
$smtp->to($MailTo);

# Start the mail
$smtp->data();

# Send the header.
$smtp->datasend("To: $MailTo\n");
$smtp->datasend("From: $MailFrom\n");
$smtp->datasend("Subject: $subject\n");
$smtp->datasend("\n");

# Send the message
$smtp->datasend("$MailBody\n\n");

# Send the termination string
$smtp->dataend();
$smtp->quit;


That should be it.



Was this answer helpful?

Add to Favourites Add to Favourites    Print this Article Print this Article

Also Read
Spam (unsolicited email) (Views: 1535)

* ASP is only available on Windows

Home Page
About
Web Hosting
FAQ
Get Support
Script Downloads

Coldfusion Hosting
ASP Hosting
Linux Hosting
Railo Hosting

Terms of Service
Privacy Policy
Affiliate Program

* ASP is only available on Windows.