Sunday, September 30, 2012

How to send smtp mail in Perl on Shared Hosting(esp Hostgator) with authorization

Looking to send email using Perl in Smtp in Shared hosting( this is tested for Hostgator) on Centos/Linux/Unix?
This code does that. If you're on Hostgator Centos shared hosting server then this works:
#!/usr/bin/perl

use Net::SMTP;

$smtp = Net::SMTP->new('mail.mysite.com');
$smtp->auth( 'contactus+mysite.com', 'rmypassword' );
$smtp->mail('contactus@mysite.com');
$smtp->to('ragmyemail@gmail.com');

$smtp->auth( 'contactus+mysite.com', 'passowrd' );
$smtp->data();
$smtp->datasend('ragmyemail@gmail.com');
$smtp->datasend("From: Whats up?\n");
$smtp->datasend("To: Whats up?\n");
$smtp->datasend('Subject: Whats up1?');
$smtp->datasend("\n");
$smtp->datasend("Hello, this is test email.\n");
$smtp->dataend();

$smtp->quit;

No comments:

Post a Comment