Solved

problems with html e-mail

Posted on 2000-03-30
14
160 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 

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
 

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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…

861 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