Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 169
  • Last Modified:

problems with html e-mail

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
trentm1
Asked:
trentm1
1 Solution
 
Kim RyanIT ConsultantCommented:
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
 
trentm1Author Commented:
Edited text of question.
0
 
trentm1Author Commented:
Edited text of question.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
trentm1Author Commented:
Adjusted points from 25 to 50
0
 
ozoCommented:
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
 
trentm1Author Commented:
hmm I tried that and that broke all the code and it crashed.
0
 
maneshrCommented:
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
 
trentm1Author Commented:
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
 
trentm1Author Commented:
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
 
trentm1Author Commented:
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
 
trentm1Author Commented:
Adjusted points from 50 to 65
0
 
trentm1Author Commented:
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
 
trentm1Author Commented:
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
 
maneshrCommented:
Wow!! you are the man!!

Way to go :-)
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now