Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

problem on MIME::Lite..please help

by bh_perl (Monk)
on Dec 10, 2010 at 07:22 UTC ( #876395=perlquestion: print w/replies, xml ) Need Help??

bh_perl has asked for the wisdom of the Perl Monks concerning the following question:


I have a text file contain some info as below:-
isp:/home/ftpadmin # more email.txt;/tmp/hisyam/test.txt;BAHARIN HASAN;12345;RM101 +.99;12/12/2010;12/1/2011;/tmp/hisyam/test.txt;ASMAH AHMAD;12345;RM111. +99;12/12/2010;12/1/2011;/tmp/hisyam/test.txt;HISHAM SALLEH;12345;RM2 +01.99;12/12/2010;12/1/2011

Based on my program, i want all the information from the input data and send email using MIME::Lite. But my code look failed and it was not send the email.. WHY ?...please help me.. is there any missing on my code </code>
#!/usr/bin/perl use MIME::Lite; open (DATA, "/home/ftpadmin/email.txt"); open (LOG, ">> /root/bin/email.log"); while (my $line = <DATA>) { chomp($line); my ($id,$attach,$name,$acc_no,$amount,$sdate,$ddate) = split(/ +;/,$line); print (LOG localtime . ",$id,$attach,$name,$acc_no,$amount,$sd +ate,$ddate\n"); $msg = MIME::Lite->new( To =>'$id', From =>'"DATAONE SDN BHD"<>', Subject =>'TEST ON $sdate', Type =>'multipart/related' ); $msg->attach( Type => 'text/html', Data => qq{ <head> <title>TEST ON $sdate</title> </head> <body> <center> <table border=0> <tr> <th><img border=0 src=/images/pulpit.jpg alt=Pulpit rock w +idth=67 height=92 /></th> <th><p>&nbsp;</p> <h2>Bill Statement</h2></th> </tr> <tr> <td><h4>Dear $name,</h4> <p>Thank you for your valued subscription to our<br/> services.Your TM bill statement is now attached as <br/> an Adobe PDF file in this email.</p> <p>Thank You</p></td> <td><p>Account No.</p><p>$account</p>Statement Date.<p>12/ +12/2010</p></td> </tr> </table> <center><img src=example.jpg alt=example/></center> </center> </body> }, ); $msg->attach( Type => 'image/gif', Id => 'image.gif', Path => '/tmp/image.gif', ); $msg->send(); } close(DATA); close(LOG);

Replies are listed 'Best First'.
Re: problem on MIME::Lite..please help
by samarzone (Pilgrim) on Dec 10, 2010 at 07:43 UTC

    You are trying to send the email to literal '$id' not the email value inside variable $id. You have enclosed $id into single quotes which does not interpolate. Same for other variable $sdate. Use double quotes instead.


    A few more things

    1. You could have used use strict to see that you have incorrectly written $account for $acc_no later in the message body
    2. You can also debug the mail using $msg->send(Debug => 1); which could have perhaps pointed you to solution
    3. Avoid writing actual email addresses (personal information, in broad definition) in public forums :)
Re: problem on MIME::Lite..please help
by Anonyrnous Monk (Hermit) on Dec 10, 2010 at 08:27 UTC
    <th><img border=0 src=/images/pulpit.jpg alt=Pulpit rock width=67 height=92 /></th>

    And while you're at it, spend a few quotes to get proper HTML. At a minimum around the values of the src and alt attributes

    ... src="/images/pulpit.jpg" alt="Pulpit rock" ...


Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://876395]
Approved by ikegami
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (2)
As of 2023-02-05 21:20 GMT
Find Nodes?
    Voting Booth?
    I prefer not to run the latest version of Perl because:

    Results (33 votes). Check out past polls.