Hi All,

I am a newbie to perl. I am trying to make a script in perl for sending email on a person's birthday. The name,date,gender,timezone,mailid are in a semicolon seperated text file. I am reading the file line by line and splitting the variables. In my mail sending part, i am getting error.

The problem i am facing is,if I am hardcoding the email address in mailx syntax, I am getting a mail. If I am using the email variable in place of complete email address, I am getting an error. Text file, Error Code and the program output are below. Please help. PS: I have masked the email ids. My Perl version is v5.8.8. OS is Linux x86_64. My Shell is Korn Shell ie /bin/ksh $ echo $KSH_VERSION Version AJM 93t+ 2010-02-02

Text file ========= Sandeep:1002:IST:him:email@provider Vishal:0603:IST:him:email@provider Aaradhna:2703:IST:her:email@provider Mallikarjun Gowda:2412:IST:him:email@provider Code Snippet ============ #!/usr/bin/perl -w use POSIX qw[tzset]; use POSIX qw(strftime); $ENV{'TZ'} = 'Asia/Calcutta'; tzset(); $clear_string=`clear`; print $clear_string; printf("\t\t\tIST TIMEZONE SET\n\n"); $datestring = strftime "%a %b %e %H:%M:%S %Y", localtime; printf("\tDate and time - $datestring\n"); $datecmp = strftime "%d%m", localtime; #This part reads the file line by line my $filename = '/home/srivasta/birthday.txt'; open (my $fh,'<:encoding(UTF-8)',$filename) or die "Could not open file '$filename' $!"; while (my $row = <$fh>) { chomp($row); my($birthdayperson,$birthdate,$timezone,$gender,$email)= +split /:/,$row; if ($birthdate == $datecmp){ printf("\tBirthdayPerson name is $birthdayperson\n"); printf("\tBirthdate is $birthdate\n"); printf("\ttimezone is $timezone\n"); printf("\tGender is $gender\n"); printf("\tEmail is $email\n"); printf("\t$birthdayperson has birthday today"); printf("\n\tRemember to Wish $gender a very Happy Birthday\n"); # Below block of code sends mail to the intended Receipent open(MAILPIPE,'|/bin/mailx -s "Happy Birthday" email@provider') or die + "Can't open pipe $!"; print MAILPIPE "Wishing you a Very happy Birthday. Enjoy the day\n"; close MAILPIPE; } } Sample Output ============= IST TIMEZONE SET Date and time - Thu Dec 24 14:18:46 2015 BirthdayPerson name is Mallikarjun Gowda Birthdate is 2412 timezone is IST Gender is him Email is email@provider Mallikarjun Gowda has birthday today Remember to Wish him a very Happy Birthday $

if I am using $email variable in place of email@provider (hardcoded mailid) i am getting an error as below.

open(MAILPIPE,'|/bin/mailx -s "Happy Birthday" $email') or die "Can't +open pipe $!"; Output ====== IST TIMEZONE SET Date and time - Thu Dec 24 14:32:03 2015 BirthdayPerson name is Mallikarjun Gowda Birthdate is 2412 timezone is IST Gender is him Email is email@provider.com Mallikarjun Gowda has birthday today Remember to Wish him a very Happy Birthday You must specify direct recipients with -s, -c, or -b.

In reply to How to put email addresses in a variable and send mails via mailx command by Kislaya

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.