Perl and CGI

 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me



Go Back   Tutorialized ForumsWeb Design & DevelopmentPerl and CGI

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Tutorialized Forums Sponsor:
  #1  
Old March 28th, 2011, 12:09 AM
abcdef1 abcdef1 is offline
Registered User
Tutorialized Newbie (0 - 499 posts)
 
Join Date: Feb 2011
Posts: 2 abcdef1 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 11 sec
Reputation Power: 0
Turn on debug in PERL code

how to turn on debug in function sendSMTP??
What is the fucntion var $DEBUG ??

Code:
#!/usr/bin/perl -w

use Socket;
use strict;

my($mailTo)     = 'chuikingman@yahoo.com.hk';
my($mailServer) = 'mail.hgcbroadband.com';

my($mailFrom)   = 'medined@mtolive.com';
my($realName)   = "chuikingman";
my($subject)    = 'Test send_mail';
my($body)       = "Test Line One.\nTest Line Two.\n";

$main::SIG{'INT'} = 'closeSocket';

my($proto)      = getprotobyname("tcp")        || 6;
my($port)       = getservbyname("SMTP", "tcp") || 25;
my($serverAddr) = (gethostbyname($mailServer))[4];

die('gethostbyname failed.') unless (defined($serverAddr));

socket(SMTP, AF_INET(), SOCK_STREAM(), $proto)
    or die("socket: $!");

 my $packFormat;
$packFormat = 'S n a4 x8';   # Windows 95, SunOs 4.1+
#$packFormat = 'S n c4 x8';   # SunOs 5.4+ (Solaris 2)

connect(SMTP, pack($packFormat, AF_INET(), $port, $serverAddr))
    or die("connect: $!");

select(SMTP); $| = 1; select(STDOUT);    # use unbuffered i/o.

{
    my($inpBuf) = '';

    recv(SMTP, $inpBuf, 200, 0);
    recv(SMTP, $inpBuf, 200, 0);
}
my $debug = 1 ;
sendSMTP(1, "HELO\n");
sendSMTP(1, "MAIL From: <$mailFrom>\n");
sendSMTP(1, "RCPT To: <$mailTo>\n");
sendSMTP(1, "DATA\n");

send(SMTP, "From: $realName\n", 0);
send(SMTP, "Subject: $subject\n", 0);
send(SMTP, $body, 0);

sendSMTP(1, "\r\n.\r\n");
sendSMTP(1, "QUIT\n");

close(SMTP);

sub closeSocket {     # close smtp socket on error
    close(SMTP);
    die("SMTP socket closed due to SIGINT\n");
}

sub sendSMTP {
    my($debug)  = shift;
    #my($debug)  = 1;
    my($buffer) = @_;

    print STDERR ("> $buffer") if $debug;
    send(SMTP, $buffer, 0);

    recv(SMTP, $buffer, 200, 0);
    print STDERR ("< $buffer") if $debug;

    return( (split(/ /, $buffer))[0] );
}




Reply With Quote
Reply

Viewing: Tutorialized ForumsWeb Design & DevelopmentPerl and CGI > Turn on debug in PERL code


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 

Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap