• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 284
  • Last Modified:

Sending mail using SMTP

Hi,

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.

Thanx,

Jeeke
0
Jeeke
Asked:
Jeeke
  • 4
  • 3
1 Solution
 
thoellriCommented:
Jeeke,

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
  Tobias



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

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


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->mail($mailsender);
  $smtp->to($to);
  $smtp->data();
  $smtp->datasend(qq{To: $to\n});
  $smtp->datasend(qq{Subject: new email address\n});
  $smtp->datasend(qq{\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});
  $smtp->dataend();
  $smtp->quit;
  print qq{<b>Thank you</b>\n};
}
print $cgi->end_html();


0
 
khacharnCommented:
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 email@add.com -b email@add.com
****************************************

You can have blat installed on the server where you FORM is hosted then you can use it conveniently..in a CGI script..
Tell me if you want to know about it..
You can find more info on these sites
***************************************
Blat mailing list: http://www.onelist.com/community/blat
Blat homepage: http://www.interlog.com/~tcharron/blat.html
****************************************
regards
Nitin
0
 
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 :-)
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
thoellriCommented:
Did you try the code I posted?
0
 
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\@somehost.com";
??

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.

Greetz,
Jeeke
0
 
thoellriCommented:
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.

Ok?
  Tobias
0
 
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.

Greetings,
Jeeke
0
 
thoellriCommented:
Thanks - just post again to this thread if you have any problems.
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now