Solved

problems with html e-mail

Posted on 2000-03-30
14
156 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
Comment Utility
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
Comment Utility
Edited text of question.
0
 

Author Comment

by:trentm1
Comment Utility
Edited text of question.
0
 

Author Comment

by:trentm1
Comment Utility
Adjusted points from 25 to 50
0
 
LVL 84

Expert Comment

by:ozo
Comment Utility
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
Comment Utility
hmm I tried that and that broke all the code and it crashed.
0
 
LVL 16

Accepted Solution

by:
maneshr earned 65 total points
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:trentm1
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Adjusted points from 50 to 65
0
 

Author Comment

by:trentm1
Comment Utility
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
Comment Utility
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
Comment Utility
Wow!! you are the man!!

Way to go :-)
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
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…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

743 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

16 Experts available now in Live!

Get 1:1 Help Now