Connecting Tech Pros Worldwide Forums | Help | Site Map

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

Newbie
 
Join Date: Aug 2007
Posts: 22
#1: Nov 18 '08
Hello:

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 = '123@yahoo.com'; 
  2. $From_Email = 'info@myemail.com'; 
  3. $Email_Subject = 'TEST SEND ATTACHMENT (3)'; 
  4. $Email_Body    = 'Here u can put whatever text msg meeds to be sent in the mail!!!';
  5.  
  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 = window.open(\"Loging_Form.pl?URL=$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=\"http://www.altavista.com\" onClick=\"Loging_Pop_Up(); return false;\">[Link to Altavista]</A>\n";
  15. $html_attachment_text .= "</body>\n";
  16. $html_attachment_text .= "</html>\n";
  17.  
  18.  
  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";
  5.  
  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";
  13.  
  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";
  18.  
  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--";
  24.  
  25.     close MAIL;        
  26. }
If you know of a better approach to accomplish the same thing I would appreciat it

Thanx
VirtualWeb

eWish's Avatar
Moderator
 
Join Date: Jul 2007
Location: Arkansas
Posts: 900
#2: Nov 18 '08

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


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.

--Kevin
Newbie
 
Join Date: Aug 2007
Posts: 22
#3: Dec 10 '08

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


Kevin:
Your suggestion worked.. thank you


VirtualWeb
KevinADC's Avatar
Expert
 
Join Date: Jan 2007
Location: Southern California USA
Posts: 4,091
#4: Dec 10 '08

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


You're welcome.

Regards,
Kevin

:)
Reply