Cgi脚本不发送邮件

时间:2014-07-23 09:27:26

标签: perl gmail cgi mailer

我正在尝试使用cgi脚本向我的Gmail帐户发送邮件。我有一个pl文件发送邮件,当我使用它工作正常,但当我在我的项目中使用它它停止工作。我不知道为什么它不工作。请帮忙。以下是我的代码。

    #!perl.exe
    use strict;
    use warnings;
    use DBI;
    use CGI;
    use database;
    use Net::SMTP::TLS;
    use Data::Dumper;
    my $db=database->new();
    my $q = new CGI;
    print $q->header;
    my $email  = $q->param("mail");
    my $random  = $q->param("random");
    print 'your details has been successfully added into our database please verify your email address to use our service';
    print'<html>';
    print'<head>';
    print'</head>';
    print'<body>';
    print'<br>';
    #connecting to database
    my $_database='govjobs';
    my $_port='3306';
    my $_hostname='localhost';
    my $_dsn = "DBI:mysql:database=$_database;host=$_hostname;port=$_port";
    my $_dbh = DBI->connect($_dsn, 'root', 'root') || die "is it connecting";
    my $statement='SELECT * FROM registration email="'.$email.'" and random="'.$random.'"';  #days left query
    my $sth = $_dbh->prepare($statement);
    my $rv = $sth->execute;
    my @data;
    while (@data = $sth->fetchrow_array())  {
         $email=$data[0];
         $random=$data[5];

        }
    my $mailer = new Net::SMTP::TLS(
        'smtp.gmail.com',
        Hello   =>      'smtp.gmail.com',
        Port    =>      587,
        User    =>      'mydomainname@gmail.com',
        Password=>      'mypassword');
    $mailer->mail('mydomainname@gmail.com');
    $mailer->to('archofdestiny@gmail.com');
    $mailer->data;
    $mailer->datasend("this is a test data");
    $mailer->dataend;
    $mailer->quit;
    print <<END_HTML;
    </body>
    </html>
    END_HTML

0 个答案:

没有答案