Sending mail using SMTP


I'm new to Perl, and I need a (small) script urgently (it's not a difficult one I think...). I will use this script to find out how I can write bigger scripts.

Anyway, here's the situation :
I want my site to have a textfield where the visitor can enter his email address. When he presses submit, his address is mailed to me USING SMTP !!! (the server my site is on, doesn't allow sendmail...). So who can give me the shortest script to do this (preferably with a bit of explanation, I know C/C++, html, javascript and PHP but not Perl...) (and can anyone plz tell me where I could find a public SMTP server ?)

I know it's not a difficult question, but I really need the script.


Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


I assume that the form field that holds the email-address has the name 'email' when it gets submitted to the following cgi. Configure mailhost/mailsender/to and you should be alomost ready to go.

As far as the "public" SMTP server is concerned: Most of the ones which used to be public were taken down by Spammers who hammered them until they were dead. I guess there are still lots of them out there, but you gotta search hard ...

Hope this helps

use strict;
use CGI;
use Net::SMTP;

# You need to configure these values:
# What is the hostname of the smtp-server?
my $mailhost="";
# Who is the sender of the message?
my $mailsender="cgi-script\";
# What is your email address? (where new address gets sent to)
my $to="myemailadress\";

my $cgi=new CGI;
print $cgi->header();
print $cgi->start_html();
if (!$cgi->param('email')) {
   print qq{<b>please enter your email address !</b>\n};
} else {
  my $smtp = Net::SMTP->new(mailhost);
  $smtp->datasend(qq{To: $to\n});
  $smtp->datasend(qq{Subject: new email address\n});
  $smtp->datasend(qq{This is the new   email-address:}.$cgi->param('email').qq{\n});
  $smtp->datasend(qq{\n\nVirtually yours\n});
  $smtp->datasend(qq{    $mailsender\n\n});
  print qq{<b>Thank you</b>\n};
print $cgi->end_html();

hi jeeve..
There is a Command line Utility called blat(which is a exe file)..which can be used effectively for sending mails from the command prompt..
You wouldd have to write something like this to send a mail..
c:\blat.exe msg.txt -t -b

You can have blat installed on the server where you FORM is hosted then you can use it a CGI script..
Tell me if you want to know about it..
You can find more info on these sites
Blat mailing list:
Blat homepage:
JeekeAuthor Commented:
I'm not running my own server, so I can't decide what programs to install. that's also why I can't use sendmail... I really need to use the mailing capabilities of Perl itself... but thanks for trying :-)
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

Did you try the code I posted?
JeekeAuthor Commented:
Thoellri, thank you for the quick reply, sorry to keep you both waiting, but tomorrow I've (finally) got my last exam. Anyway, this script is about what I was looking for, but I still can't seem to get it up and running. What do you mean with :

# Who is the sender of the message?
my $mailsender="cgi-script\";

The rest is no problem, and I also added the line #!/usr/bin/perl . But as I said, I haven't really had a lot of time, so I'll check it out this weekend.

When you receive an email from somebody you can see their address in the "From" and "From:" headers. Good guys usually use their email-address in these headers. Spammers put whatever they want there.
The $mailsender is the email-address the recipient of the email will see in the From-headers.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
JeekeAuthor Commented:
Ok, this should do for me. I'll try to figure it out from here, using your script as 'guideline' :-) Thank you for helping me out so quickly... Here's some extra points.

Thanks - just post again to this thread if you have any problems.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.