I need to attached some file (like: pdf, doc, excel, image) within a email automatically, when a new user register for some service. This registration script on CGI and new user after successful registration got a text email, generated by this script but we would like to add one feature that depending on service he choose on the time of registration, he will; get a sample service details along with that thank you email.
If needed we will upload these files on the server on particular folder. Script need to attaché this files into email depend on service chose and send as an attachment.
Any perl code run as a CGI will return a 500 internal server error if you don't print an http header. I assume you are just testing to see if MIME::Lite works, if so, just print a header and a short message at the end of the script.
perl Code:
#!/usr/bin/perl -w
use MIME::Lite;
### Create a new single-part message, to send a GIF file:
yes i am getting email but as i have not added anything to display on the screen so i was getting error message. now it's working. now i need to know some more info,
1) the email script i was using which take data from diffent variable as follows:
open MAIL, "| $mail_prog -finrreturn\@k****ij.com" || die"I was not able to open the mail program<BR>contact the server's technical administrator.<BR><BR>If this is not admin, please let him/her<BR> know about this problem.";
my$message_body = "Here's the attachment file(s) you wanted<br><b>h</b>";
### Create a new single-part message, to send a GIF file:
$msg = MIME::Lite->new(
From =>'sujata@k****ij.com',
To =>'sujata_atkcs@yahoo.com',
Cc =>'sujata_ghosh@hotmail.com, [EMAIL="sujata_ghosh1@rediffmail.com'"]sujata_ghosh1@rediffmail.com'[/EMAIL],
Subject =>'Helloooooo, nurse!',
Type =>'application/octet-stream',
Encoding =>'base64',
Path =>'/home/k****ijc/www/temp/inr rates.xls'
);
$msg->attach (
Type => 'text/html',
Data => $message_body
) or die "Error adding the text message part: $!\n";
$msg->send; # send via default
print "Content-type: text/html\n\n";
print "Message sent";
2) i am using a script which take data from form and make HTML page and send HTML mail using same email script and additional code only i change the 'text/html' part this email message consist of images which appears with email body message, but it is not showing into email. as we are using this code to display it on HTMl page: (<img src="full path of the file">) how i will use the same to display it on proper place in the email body with text?
Thanks once again.
Last edited by UnrealEd; 06-19-07 at 08:22 AM.
Reason: please use the correct syntax highlighters!!
Do you want to send an html encoded email or send an attachment? I'm confused. I think if you read the MIME::Lite documentation more you will figure out whatever it is you are trying to do. It is one of the better documented modules and has many examples.
I need both........... i need to send text and html email with attachement also i need to send HTML email with images with body text, except from that i need know how do i refer these portion of my old email code into MIME::Lite??
Code:
print MAIL "$subject \n";
if (!$edition)
{
$edition = "";
print MAIL "$edition";
}
else
{
print MAIL "$edition \n";
}
print MAIL "$time \n\n";
if ((!$inr1) && (!$inrm1))
{
$inr1 = "";
$inrm1 = "";
print MAIL "$inr1";
print MAIL "$inrm1";
}
else
{
print MAIL "$inr1\n";
print MAIL "$inrm1\n\n";
}
if ((!$fwd1) && (!$fwdm1))
{
$fwd1 = "";
$fwd1 = "";
print MAIL "$fwd1";
print MAIL "$fwdm1";
}
else
{
print MAIL "$fwd1\n";
print MAIL "$fwdm1\n\n\n";
}
if ((!$strategy1) && (!$strategym1))
{
$strategy1 = "";
$strategym1 = "";
print MAIL "$strategy1";
print MAIL "$strategym1";
}
else
{
print MAIL "$strategy1\n";
print MAIL "$strategym1\n\n";
}
if ((!$eurrs1) && (!$eurrsm1))
{
$eurrs1 = "";
$eurrsm1 = "";
print MAIL "$eurrs1";
print MAIL "$eurrsm1";
}
else
{
print MAIL "$eurrsmail2\n\n";
print MAIL "$eurrsmmail2\n\n\n";
}
print MAIL "$dis\n\n";
print MAIL "\n";
and the MIME::Lite code is:
Code:
#!/usr/bin/perl -wuse MIME::Lite;
my $message_body = "Here's the attachment file(s) you wanted<br><b>h</b>";
### Create a new single-part message, to send a GIF file:
$msg = MIME::Lite->new(
From =>'sujata@k****ij.com',
To =>'sujata_atkcs@yahoo.com',
Cc =>'sujata_ghosh@hotmail.com, sujata_ghosh1@rediffmail.com',
Subject =>'Helloooooo, nurse!',
Type =>'application/octet-stream',
Encoding =>'base64',
Path =>'/home/k****ijc/www/temp/inr rates.xls'
);
$msg->attach (
Type => 'text/html',
Data => $message_body
) or die "Error adding the text message part: $!\n";
$msg->send; # send via default
print "Content-type: text/html\n\n";
print "Message sent";
$msg = MIME::Lite->new(
From =>'Vikram Murarka <vikram@k****ij.com>',
To => $em,
Return-path =>'inrreturn@k****ij.com',
Reply-To =>'Vikram Murarka <vikram@k****ij.com>',
Subject => $subject,
Type =>'text',
Data => $message
);
$msg->attach (
Type => 'application/msword',
Encoding => 'base64',
Path => '/home/k****ijc/www/com/colour of money 26may07.doc'
) or die "Error adding the text message part: $!\n";
$msg->send; # send via default
i used it on my older code like that: "-finrreturn\@k****ij.com"
Code:
open MAIL, "| $mail_prog -finrreturn\@k****ij.com" || die "I was not able to open the mail program<BR>contact the server's technical administrator.<BR><BR>If this is not admin, please let him/her<BR> know about this problem.";
print MAIL "To: $em\n";
............................
close MAIL;
instead of that its won't work. its very important as we have seperate email address for sorting different bad emails email list.
how do i incoorporate this now with new code. please advice.
also tell me how do i send HTML email with Image along with the text just like a html page. image will change time by time so