Submitting webforms using jmail and perl

  • skuff
  • Novice
  • Novice
  • User avatar
  • Joined: Sep 02, 2003
  • Posts: 28
  • Loc: Merseyside, UK
  • Status: Offline

Post September 2nd, 2003, 6:38 am

Hallo Everyone :)

I am having problems setting up simple forms on my website, my webhosts have told me that I will need to use something called jmail and perl, I've got a rough inderstanding what these things are but I'm a comlplete beginner when it comes to this scripting malarkey and I need some help. I am on a windows server and as far as I can make out I need to modify the following code and then upload it to the CGI-BIN folder in ASCII format but I don't know which parts I'm supposed to change.

Code: [ Select ]
use OLE;
    use CGI;
    $jmail = CreateObject OLE "JMail.SMTPMail";

print "Content-type: text/html\n\n";

$form = new CGI;
    $Recipient=$form->param('email');
    
    $domain = $ENV {'SERVER_NAME'};
    $referer = $ENV {'HTTP_REFERER'};
    $url = $referer;
    $url =~ s/^http:\/\///i;
    $url =~ s/^www\.//i;
    $domain =~ s/^www\.//i;


$Sender = "noreply\@$domain";
    $SMTPServer = "smtp.$domain:25";
    $Subject = "JMail Example";
    $Body = "This test mail sent from: $ENV{'LOCAL_ADDR'} using the JMail component on the server via Perl.";
    $Priority=3;
    $Header = "Originating-IP", $ENV{'REMOTE_ADDR'};

    $jmail->{ServerAddress} = $SMTPServer;
    $jmail->{Sender} = $Sender;
    $jmail->{Subject} = $Subject;
    $jmail->AddRecipient ($Recipient);
    $jmail->{Body} = $Body;
    $jmail->{Priority} = $Priority;
    $jmail->AddHeader ($Header);

if ($url =~ m/^$domain/)
    {
        $mailmessage = "mail sent";
        $jmail->Execute;
    }
    else
    {
        $mailmessage = "mail was not sent. Incorrect Referer";
    }
 

print "Result: $mailmessage Recipient: $Recipient";
    print "Sender: $Sender SMTP Server: $SMTPServer";
    print "Subject: $Subject Referer: $referer";
    print "Domain: $domain url: $url ";
  1. use OLE;
  2.     use CGI;
  3.     $jmail = CreateObject OLE "JMail.SMTPMail";
  4. print "Content-type: text/html\n\n";
  5. $form = new CGI;
  6.     $Recipient=$form->param('email');
  7.     
  8.     $domain = $ENV {'SERVER_NAME'};
  9.     $referer = $ENV {'HTTP_REFERER'};
  10.     $url = $referer;
  11.     $url =~ s/^http:\/\///i;
  12.     $url =~ s/^www\.//i;
  13.     $domain =~ s/^www\.//i;
  14. $Sender = "noreply\@$domain";
  15.     $SMTPServer = "smtp.$domain:25";
  16.     $Subject = "JMail Example";
  17.     $Body = "This test mail sent from: $ENV{'LOCAL_ADDR'} using the JMail component on the server via Perl.";
  18.     $Priority=3;
  19.     $Header = "Originating-IP", $ENV{'REMOTE_ADDR'};
  20.     $jmail->{ServerAddress} = $SMTPServer;
  21.     $jmail->{Sender} = $Sender;
  22.     $jmail->{Subject} = $Subject;
  23.     $jmail->AddRecipient ($Recipient);
  24.     $jmail->{Body} = $Body;
  25.     $jmail->{Priority} = $Priority;
  26.     $jmail->AddHeader ($Header);
  27. if ($url =~ m/^$domain/)
  28.     {
  29.         $mailmessage = "mail sent";
  30.         $jmail->Execute;
  31.     }
  32.     else
  33.     {
  34.         $mailmessage = "mail was not sent. Incorrect Referer";
  35.     }
  36.  
  37. print "Result: $mailmessage Recipient: $Recipient";
  38.     print "Sender: $Sender SMTP Server: $SMTPServer";
  39.     print "Subject: $Subject Referer: $referer";
  40.     print "Domain: $domain url: $url ";


Thanks
Skuff
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post September 2nd, 2003, 6:38 am

  • ATNO/TW
  • Super Moderator
  • Super Moderator
  • User avatar
  • Joined: May 28, 2003
  • Posts: 23404
  • Loc: Woodbridge VA
  • Status: Offline

Post September 2nd, 2003, 7:23 am

It seems a little odd that a windows server would have you do it in perl. I do mine with ASP using visual basic. here's a simple one with comments that possitively works, no matter what directory it's stored in (assumes your server supports ASP and since it's a Window's server, I would have to believe so - (directory permissions should be set for read and execute scripts - cgi-bin is probably already set that way so it's just as good a place to drop it as any.) (Save as a .asp page):

Code: [ Select ]
<%
SenderEmail = request.form ("email")
SenderName = request.form ("name")
Set JMail = Server.CreateObject("JMail.SMTPMail")

' This is my local SMTP server
JMail.ServerAddress = "mailhub.yoursmptserver.com"

' This is me....
JMail.SenderName = SenderName
JMail.Sender = SenderEmail
JMail.Subject = "Subscription Submission"

' Get the recipients mailbox from a form (note the lack of a equal sign).
JMail.AddRecipient "yourmail@wherever.com"
'JMail.AddRecipient "dad@some.com"

' The body property is bodth read and write.
' If you want to append text to the body you can
' use JMail.Body = JMail.Body & "Hello world!"
' or you can use JMail.AppendText "Hello World!"
' which in many cases is easier to use.
JMail.Body ="Name = " & request.form ("name") & vbCrLf&_
"Email Address = " & request.form ("email")



JMail.Priority = 3

JMail.AddHeader "Originating-IP", Request.ServerVariables("REMOTE_ADDR")

' Must make sure that IUSR_???? has access to the following files.
'JMail.AppendBodyFromFile "e:\mail\standard_footer.txt"
'JMail.AddAttachment "e:\products\MyProduct.exe"

' Send it...
JMail.Execute
Set JMail = nothing
%>
  1. <%
  2. SenderEmail = request.form ("email")
  3. SenderName = request.form ("name")
  4. Set JMail = Server.CreateObject("JMail.SMTPMail")
  5. ' This is my local SMTP server
  6. JMail.ServerAddress = "mailhub.yoursmptserver.com"
  7. ' This is me....
  8. JMail.SenderName = SenderName
  9. JMail.Sender = SenderEmail
  10. JMail.Subject = "Subscription Submission"
  11. ' Get the recipients mailbox from a form (note the lack of a equal sign).
  12. JMail.AddRecipient "yourmail@wherever.com"
  13. 'JMail.AddRecipient "dad@some.com"
  14. ' The body property is bodth read and write.
  15. ' If you want to append text to the body you can
  16. ' use JMail.Body = JMail.Body & "Hello world!"
  17. ' or you can use JMail.AppendText "Hello World!"
  18. ' which in many cases is easier to use.
  19. JMail.Body ="Name = " & request.form ("name") & vbCrLf&_
  20. "Email Address = " & request.form ("email")
  21. JMail.Priority = 3
  22. JMail.AddHeader "Originating-IP", Request.ServerVariables("REMOTE_ADDR")
  23. ' Must make sure that IUSR_???? has access to the following files.
  24. 'JMail.AppendBodyFromFile "e:\mail\standard_footer.txt"
  25. 'JMail.AddAttachment "e:\products\MyProduct.exe"
  26. ' Send it...
  27. JMail.Execute
  28. Set JMail = nothing
  29. %>



The html form is just as basic (Save as an HTML page):


Code: [ Select ]
<FORM method="POST" action="/cgi-bin/subscribeform.asp">
<input type="hidden" name="required"       value="Name,SubscriberMail" />
Your Name:        
<input tabindex="1" type="text" size="30" name="name" /><br />
Your Email:            
<input tabindex="2" type="text" size="30" name="email" /><br />
<input tabindex="3" type="submit" value="Submit" title="Submit this form"><br />
</form>
  1. <FORM method="POST" action="/cgi-bin/subscribeform.asp">
  2. <input type="hidden" name="required"       value="Name,SubscriberMail" />
  3. Your Name:        
  4. <input tabindex="1" type="text" size="30" name="name" /><br />
  5. Your Email:            
  6. <input tabindex="2" type="text" size="30" name="email" /><br />
  7. <input tabindex="3" type="submit" value="Submit" title="Submit this form"><br />
  8. </form>


That is a working model. Just change the Jmail.AddRecipient to your email address and change the Jmail.ServerAddress to your hosts SMPT server and it should work for you the first time, provided you can use ASP
"There's no place like 127.0.0.1 except for ::1."
Alexandria Networks. Leader in IT consulting for associations/non-profits, and small to medium sized businesses around the northern Virginia and Washington D.C. metro area.
  • skuff
  • Novice
  • Novice
  • User avatar
  • Joined: Sep 02, 2003
  • Posts: 28
  • Loc: Merseyside, UK
  • Status: Offline

Post September 2nd, 2003, 7:48 am

Hi ATNO/TW

The account I have with the webhosts doesn't allow me to use ASP and they gave me two alternatives, upgrade my account or use Perl, I'm not upgrading my account as I am already paying £49.99 (British Pounds Sterling) a year but they do offer a 30 day money back guarantee which I may have to take them up on if I can't sort these forms out.

Cheers
  • ATNO/TW
  • Super Moderator
  • Super Moderator
  • User avatar
  • Joined: May 28, 2003
  • Posts: 23404
  • Loc: Woodbridge VA
  • Status: Offline

Post September 2nd, 2003, 8:02 am

That sorta sucks! Whoever heard of a Windows Server host that didn't offer at least ASP 3.0 on their basic plans? Well, then...I don't know Perl well enough to help you sort out the Perl version. Guess we'll have to wait on a Perl expert for that advice. Sorry I couldn't help.
"There's no place like 127.0.0.1 except for ::1."
Alexandria Networks. Leader in IT consulting for associations/non-profits, and small to medium sized businesses around the northern Virginia and Washington D.C. metro area.
  • skuff
  • Novice
  • Novice
  • User avatar
  • Joined: Sep 02, 2003
  • Posts: 28
  • Loc: Merseyside, UK
  • Status: Offline

Post September 2nd, 2003, 8:17 am

I'm getting the impression that the hosts I have chosen are a bit crap, like I mentioned before I'm new to scripts so when I registered with them I assumed that the package I chose would allow me to be receive forms through my site (it's one step up from their basic pack) but obviously it's gonna be harder than I first thought. Thanks for trying to help anyway :)
  • dreamer7
  • Student
  • Student
  • No Avatar
  • Joined: Jan 20, 2003
  • Posts: 96
  • Loc: UK
  • Status: Offline

Post September 2nd, 2003, 10:39 am

Yea your package doesn't seem that good at £49.99 a year but then again if its reliable then its ok i suppose. From what i can see from the code there has to be a page to go with it because i get the feeling that there has to be a input type with the name="email" in it with a value of an email so that the script can send to that address if you get that? $domain and $server are your domain and server i think. I think the only thing you have to do is make a html page with this in it:
Code: [ Select ]
<html>
<head>
</head>
<body>
<form action="cgi-bin/yourscript" method="post">
<input type="hidden" value="youremail@...com" name="email">
</form>
</body>
</html>
  1. <html>
  2. <head>
  3. </head>
  4. <body>
  5. <form action="cgi-bin/yourscript" method="post">
  6. <input type="hidden" value="youremail@...com" name="email">
  7. </form>
  8. </body>
  9. </html>

that will only tell the script what email address the email is going to go to. If you want the user to input something into a text box you will have to add more to the script and i have a tutorial somewhere on here that tells you what to do but i get the feeling it don't get used much lol..
http://www.ozzu.com/viewtopic.php?t=934

hope that helps
Dreamer7
  • skuff
  • Novice
  • Novice
  • User avatar
  • Joined: Sep 02, 2003
  • Posts: 28
  • Loc: Merseyside, UK
  • Status: Offline

Post September 2nd, 2003, 11:05 am

Yeah the help section on the hosts website mentions the html bit

Code: [ Select ]
<form action="cgi-bin/jmail.pl" method="post" name="mailform">
      <input name="email" type="text" size="40">
      <input name="email_submit" type="submit" value="send mail">
     </form>
  1. <form action="cgi-bin/jmail.pl" method="post" name="mailform">
  2.       <input name="email" type="text" size="40">
  3.       <input name="email_submit" type="submit" value="send mail">
  4.      </form>



I just assumed that I had to add my email address somewhere in the jmail.pl file. I don't know if it helps any but the url for the site I'm building is http://tradewagon.co.uk . It might give you a better idea what I'm trying to achieve or it might just make you laugh, either way thanks for the help.
  • dreamer7
  • Student
  • Student
  • No Avatar
  • Joined: Jan 20, 2003
  • Posts: 96
  • Loc: UK
  • Status: Offline

Post September 2nd, 2003, 11:15 am

Perhaps on the actual jmail.pl file you should change the value of $recipient from $form->param('email'); to "your@yourdomain.com"; that would stop it from taking the email address from the page so you wouldn't need the text input to enter the address into to.
dj
  • skuff
  • Novice
  • Novice
  • User avatar
  • Joined: Sep 02, 2003
  • Posts: 28
  • Loc: Merseyside, UK
  • Status: Offline

Post September 2nd, 2003, 11:58 am

right so I modify this part of jmail.pl

Code: [ Select ]

use OLE;
use CGI;
$jmail = CreateObject OLE "JMail.SMTPMail";

print "Content-type: text/html\n\n";

$form = new CGI;
$Recipient=$form->param('email@tradewagon.co.uk');
  1. use OLE;
  2. use CGI;
  3. $jmail = CreateObject OLE "JMail.SMTPMail";
  4. print "Content-type: text/html\n\n";
  5. $form = new CGI;
  6. $Recipient=$form->param('email@tradewagon.co.uk');


(am I supposed to put #!/usr/local/bin/perl at the top?)

Then I upload the jmail.pl, make sure my form(s) have

Code: [ Select ]
form action="cgi-bin/jmail.pl"


included and it should work?
  • dreamer7
  • Student
  • Student
  • No Avatar
  • Joined: Jan 20, 2003
  • Posts: 96
  • Loc: UK
  • Status: Offline

Post September 2nd, 2003, 12:19 pm

No you have to take out $form->param(... because it tries to find an input on the form with the name in the brackets and there isnt one.... so change it so that it is...
Code: [ Select ]
$recipient = "email@tradewagon.co.uk";

and #!usr/local/bin/perl or #!usr/bin/perl MUST be at the top of your perl script otherwise it won't work and the rest of it should be fine so when you run it you will get the email back to your address.. fingers crossed.
dj
  • skuff
  • Novice
  • Novice
  • User avatar
  • Joined: Sep 02, 2003
  • Posts: 28
  • Loc: Merseyside, UK
  • Status: Offline

Post September 2nd, 2003, 1:37 pm

I've tried uploading jmail.pl and instead of messing around with my own site I just used the example form that was on the hosts help page

Code: [ Select ]
<form action="cgi-bin/jmail.pl" method="post" name="mailform">
      <input name="email" type="text" size="40">
      <input name="email_submit" type="submit" value="send mail">
     </form>
  1. <form action="cgi-bin/jmail.pl" method="post" name="mailform">
  2.       <input name="email" type="text" size="40">
  3.       <input name="email_submit" type="submit" value="send mail">
  4.      </form>



and uploaded that but it doesn't seem to work, I've had a look on the help page at the hosts site again and it mentions that all mails must have either a valid "from" or "to" address which is a domain hosted with them and that they redirect all web based mail to an SMTP Filter System. So I don't know if that's got anything to do with why it's not working.
  • ATNO/TW
  • Super Moderator
  • Super Moderator
  • User avatar
  • Joined: May 28, 2003
  • Posts: 23404
  • Loc: Woodbridge VA
  • Status: Offline

Post September 2nd, 2003, 2:01 pm

Perhaps adding this might help right before $Recipient:

Code: [ Select ]
$mailprog = '/usr/lib/sendmail -f email@tradewagon.co.uk -t';


I'm not sure -- but that's the filter I had to add to mine for one client when the host upgraded their spam filtering software.

Like I said earlier -- I'm not well-versed at Perl, but remembered that I had to add that to get it to bypass the hosts spam filters.
"There's no place like 127.0.0.1 except for ::1."
Alexandria Networks. Leader in IT consulting for associations/non-profits, and small to medium sized businesses around the northern Virginia and Washington D.C. metro area.
  • dreamer7
  • Student
  • Student
  • No Avatar
  • Joined: Jan 20, 2003
  • Posts: 96
  • Loc: UK
  • Status: Offline

Post September 2nd, 2003, 2:06 pm

Erm out of interest yea why is it you can't use my script? because its a lot easier to use. What is the address of your host?
dj
  • skuff
  • Novice
  • Novice
  • User avatar
  • Joined: Sep 02, 2003
  • Posts: 28
  • Loc: Merseyside, UK
  • Status: Offline

Post September 2nd, 2003, 2:32 pm

I still can't get it working, but no doubt I've done something wrong. There's no reason I couldn't use your script Dreamer7, in fact I just tried it but I couldn't get that to work either. Anyway I'm gonna give up trying for tonight cos it's stopped being fun now, I appreciate your help Dreamer7 and ATNO/TW thanks.

Oh yeah the hosts are fasthosts.co.uk but I think I might change them after all this and go with a host that lets me use ASP so I can use a shopping cart instead of daft forms.

Cheers :)
  • skuff
  • Novice
  • Novice
  • User avatar
  • Joined: Sep 02, 2003
  • Posts: 28
  • Loc: Merseyside, UK
  • Status: Offline

Post September 4th, 2003, 5:45 am

After messing around for a few days trying to get my forms to work with little success and the fact that the hosting package I've purchased isn't too hot I think I am going to go back to the drawing board with my site. What I wanted to do was build a site I could link straight to my Ebay pages and save myself a fortune on listing fees etc, initially I thought using forms to submit orders would work but now I'm thinking a shopping cart would be a far better idea (I've seen a free ASP one called Charron or something similar) but as I mentioned earlier in the thread I can't use ASP with the package I have purchased so I am just about to cancel my account with my hosts (fasthosts.co.uk) as they have a 30 day trial period. Before I do though I just thought I'd see if anyone has any suggestions as to which would be a suitable host for my needs. Currently I am paying £49.99 plus £8.75 VAT so any reliable host that is cheaper would be fine.
Thanks
:)
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post September 4th, 2003, 5:45 am

Post Information

  • Total Posts in this topic: 30 posts
  • Users browsing this forum: No registered users and 243 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 2011 Unmelted, LLC. Ozzu® is a registered trademark of Unmelted, LLC.