By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,710 Members | 1,970 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,710 IT Pros & Developers. It's quick & easy.

Sending PopUp code on the body of an email from a script

P: 30

I need to send a bit of HTML and Javascrpt on the body of an email from my perl script in order to have the recipient get a link that will openup a new window with a PopUp.

For some reason instead of receiving the email with the HTML showing a link that will open up my PopUp... Im getting all the HTML tags and javasacript code printed on my email.

What am I doing wrong..??

Here is the code:

Expand|Select|Wrap|Line Numbers
  1. $To_Email = ''; 
  2. $From_Email = ''; 
  3. $Email_Subject = 'TEST SEND ATTACHMENT (3)'; 
  4. $Email_Body    = 'Here u can put whatever text msg meeds to be sent in the mail!!!';
  6. $html_attachment_text = "<html>\n";
  7. $html_attachment_text .= "<body bgcolor=gray><script>\n";
  8. $html_attachment_text .= "function Loging_Pop_Up() {\n";
  9. $html_attachment_text .= "var w =\"$URL\",\"smallwin\",\"width=800,height=600,status=no,resizeable=yes, scrollbars=yes\");{\n";
  10. $html_attachment_text .= "}\n ";
  11. $html_attachment_text .= "</script>\n";
  12. $html_attachment_text .= "<b><font color=red>This is test line1</font><br><br>\n";
  13. $html_attachment_text .= "<font color=white>This is where you can put your html template, i.e. whatever will be in string html_attachment_text will be sent as html attrachment with the mail.<br></font>\n ";
  14. $html_attachment_text .= "<A HREF=\"\" onClick=\"Loging_Pop_Up(); return false;\">[Link to Altavista]</A>\n";
  15. $html_attachment_text .= "</body>\n";
  16. $html_attachment_text .= "</html>\n";
  19. &sendemail($User_Email, $Admin_Email, "$Email_Subject", "$Email_Body", "$html_attachment_text");
The following code is the subroutine that handles the email sending
Expand|Select|Wrap|Line Numbers
  1. sub sendemail {
  2. $Mail_Program = '/usr/sbin/sendmail -t';    
  3.         my ($to,$from,$subject,$message,$attachment) = @_;
  4.         my $boundary = "xxxxx".time()."xxxxx";
  6.                    open MAIL, "|$Mail_Program";
  7.     print MAIL "To: $to\n";
  8.     print MAIL "From: $from\n";
  9.     print MAIL "MIME-Version: 1.0\n";
  10.     print MAIL "Content-Type: multipart/mixed;";
  11.     print MAIL " boundary=\"$boundary\"\n";
  12.     print MAIL "Subject: $subject\n\n";
  14.     print MAIL "--$boundary\n";
  15.     print MAIL "Content-Type: text/plain; charset=utf-8\n";
  16.     print MAIL "Content-Transfer-Encoding: 8bit\n\n";
  17.     print MAIL "$message\n";
  19.     print MAIL "--$boundary\n";
  20.     print MAIL "Content-Type: text/html; charset=utf-8\n";
  21.     print MAIL "Content-Transfer-Encoding: 8bit\n\n";        
  22.     print MAIL "$attachment";
  23.     print MAIL "--$boundary--";
  25.     close MAIL;        
  26. }
If you know of a better approach to accomplish the same thing I would appreciat it

Nov 18 '08 #1
Share this Question
Share on Google+
3 Replies

Expert 100+
P: 971
The email will have to have the proper headers, currently you are using both text/html and text/plain. Try removing the text/plain portion of the header sent.

Your code looks like it could be reduced. If I get time later I will look at your code again.

Nov 18 '08 #2

P: 30
Your suggestion worked.. thank you

Dec 10 '08 #3

Expert 2.5K+
P: 4,059
You're welcome.


Dec 10 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.