Solved

problems with html e-mail

Posted on 2000-03-30
14
157 Views
Last Modified: 2010-03-05
Hi,
I am wanting to know about html e-mails. I have got it to work in text but I just can't get nothing to send out in perl.

I the html the way I want it look like but I don't know how to get this thing to send.

I have so far.. .

$message2 =
print MAIL "Content-type: text/html\n\n";
<HTML>
TONS OF HTML
</HTML
;

Now for the part that sends it I have

{
    open (MAIL,"| $SEND_MAIL");

    print MAIL "To: $Data{'email'}\n";
    print MAIL "From: $sender\n";
    print MAIL "Reply-to: $data{'email'}\n" if $replyaddyr;
    print MAIL "Subject: $subject2\n\n";
    print MAIL "Content-Type: text/html; charset=\"us ascii\"\n\n";
    print MAIL "$message2";

    close(MAIL);
}              

$SEND_MAIL="/usr/sbin/sendmail -t";        



Well message 1 will send but its in plain text  and it looks like this

$message1 = "\nThank you for your order $Data{'inv_name'}.

tons of text

;
                           


MEssage 2 on the other hand won't do anything. I think it is because I don't know how to do html in perl .. is their anything I can put at the begning of  $message2 = bla and just cut and paste my html from the web? Or I am missing some html in perl concept! ?

THanks
0
Comment
Question by:trentm1
14 Comments
 
LVL 19

Expert Comment

by:Kim Ryan
ID: 2671382
I guess you are using Unix. What is $SEND_MAIL set to? You could try something like:

open(MAIL, "|/usr/sbin/sendmail -oi -t -odq") or die "Can't fork for sendmail: $!\n";
0
 

Author Comment

by:trentm1
ID: 2671399
Edited text of question.
0
 

Author Comment

by:trentm1
ID: 2671407
Edited text of question.
0
 

Author Comment

by:trentm1
ID: 2671425
Adjusted points from 25 to 50
0
 
LVL 84

Expert Comment

by:ozo
ID: 2671782
The value of a print function is '1' if it succeeds, and '' if it fails.
Did you mean to say
$message2 = "Content-type: text/html\n\n
 <HTML>
  TONS OF HTML
 </HTML>
";
0
 

Author Comment

by:trentm1
ID: 2671806
hmm I tried that and that broke all the code and it crashed.
0
 
LVL 16

Accepted Solution

by:
maneshr earned 65 total points
ID: 2673528
i would suggest that you try this...

$message2="
<HTML>

tons of your HTML code, but remmeber to escape any " you might have
Eg.

<a href="http://www/xyz.com\">XYZ</a>

</html>";

Also try this. create a HTML file with the HTML code that you want.

Now instead of sending the message via a variable, open that HTML file and print the content to the MAIL handle.

Eg.

open(HTML,"message.html") || die $!;

open (MAIL,"| $SEND_MAIL");

print MAIL "To: $Data{'email'}\n";
print MAIL "From: $sender\n";
print MAIL "Reply-to: $data{'email'}\n" if $replyaddyr;
print MAIL "Subject: $subject2\n\n";
print MAIL "Content-Type: text/html; charset=\"us ascii\"\n\n";

while(<HTML>){
  print MAIL $_;
}

close(HTML);
close(MAIL);
}                

$SEND_MAIL="/usr/sbin/sendmail -t";      
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:trentm1
ID: 2675479
hmm if I try the second method! Do I just put that message.html in my cgi bin? if so what permissions do I need to set on it? also if I take that line

open(HTML,"message.html") || die $!;


Do I just put that somewhere in ....


open (MAIL,"| $SEND_MAIL");

print MAIL "To: $Data{'email'}\n";
print MAIL "From: $sender\n";
print MAIL "Reply-to: $data{'email'}\n" if $replyaddyr;
print MAIL "Subject: $subject2\n\n";
open(HTML,"message.html") || die $!;
print MAIL "Content-Type: text/html; charset=\"us ascii\"\n\n";

while(<HTML>){
  print MAIL $_;
}

close(HTML);
close(MAIL);
}                


or do I do it like this ?
 

inside the $message2 =
open(HTML,"message.html") || die $!;

$SEND_MAIL="/usr/sbin/sendmail -t";  


Thanks a bunch!
0
 

Author Comment

by:trentm1
ID: 2676559
hmm I have tried it this way ...
{

open(HTML,"e-mail.html") || die $!;

open (MAIL,"| $SEND_MAIL");

print MAIL "To: $Data{'email'}\n";
print MAIL "From: $sender\n";
print MAIL "Reply-to: $data{'email'}\n";
print MAIL "Subject: $subject2\n\n";
print MAIL "Content-Type: text/html; charset=\"us ascii\"\n\n";

while(<HTML>){
  print MAIL $_;
}        

the code doesn't break and I put the e-mail.html in the cgi-bin and changed the permissions to 755.  When I check my mail it just says

Reply-to: X-Mailer: Perl Powered Socket Mailer Subject: New Online Order Posted


and displays nothing else!

any good suggestions?

Thanks for your help!
0
 

Author Comment

by:trentm1
ID: 2678367
OK I got further .. but I am still have a little problem this shows up in the e-mail when I receive it...

Content-Type: text/html; charset="us ascii"

<ALL THE HTML CODE>

Its all written as text

THis is what I have for my code below .. I have been able to get the html to display in the e-mail by moving the print MAIL "Content-Type: text/html; charset=\"us ascii\"\n\n"; line around below but it still isn't perfect and the fields that I put in the html code so for example their name would be filled in the approiate place are left as code! REALLY REALLY CLOSE HERE But something still isn't right any good suggestions?

 {
   open (HTML,"email.html") || die $!;
   open (MAIL,"| $SEND_MAIL");
     print MAIL "To: $Data{'email'}\n";
     print MAIL "From: $sender\n";
     print MAIL "Reply-to: $sender\n";
     print MAIL "Subject: $subject2\n\n";
     print MAIL "Content-Type: text/html; charset=\"us ascii\"\n\n";
 
while(<HTML>){
   print MAIL $_;
 }
 }
 close(HTML);
 close(MAIL);

0
 

Author Comment

by:trentm1
ID: 2678369
Adjusted points from 50 to 65
0
 

Author Comment

by:trentm1
ID: 2678452
Ok after messing with this for days I sorta have now fixed the problem!!!!!!!!!!!!!!!!!!!!!!!!!

the problem was with these lines

print MAIL "Subject: $subject2\n\n";
     print MAIL "Content-Type: text/html; charset=\"us ascii\"\n\n";

Their are extra \n's in the lines above that were messing it up...

Now I get the html to send but one thing remains... it refuses to fill in the data fields in the html

http://dunns.osiriscomm.com/a-1/cgi-bin/email.html
(go their if you want to know what I mean by data fields and not filling in)
Oh and yess when I run the scirpt I do fill all of that info out...


my code I am using is like this below...

open (MAIL,"| $SEND_MAIL");

print MAIL "To: $Data{'email'}\n";
print MAIL "From: $sender\n";
print MAIL "Reply-to: $data{'email'}\n" if $replyaddyr;
print MAIL "Subject: $subject2\n";
open(HTML,"message.html") || die $!;
print MAIL "Content-Type: text/html; charset=\"us ascii\"\n";

while(<HTML>){
  print MAIL $_;
}

close(HTML);
close(MAIL);
}                  




 


0
 

Author Comment

by:trentm1
ID: 2686258
while(<HTML>){
 print MAIL eval("qq($_)");
 }
 }
 close(HTML);
 close(MAIL);  


... It took my a while but I got it to do what I wanted by changing the above info!      
0
 
LVL 16

Expert Comment

by:maneshr
ID: 2693559
Wow!! you are the man!!

Way to go :-)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Reading fields from the text file. 4 92
Port 80 requests 16 86
perl CPAN issue 3 97
How to prepend a string to a matched string using regex and substitution in Perl 5 68
I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now