Solved

problems with html e-mail

Posted on 2000-03-30
14
163 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Perl for loop for 2000 ms 7 112
Reading fields from the text file. 4 106
PERL export multiple query results to a JSON file 1 188
collecting information 2 219
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…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
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…

737 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