CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Printing HTML e-mails via SENDMAIL

 



Merlin
journeyman

Sep 25, 2000, 4:44 AM

Post #1 of 7 (1207 views)
Printing HTML e-mails via SENDMAIL Can't Post

Well, I tried doing HTML e-mails via sendmail and I'm having problems... I checked the archive article on this subject here at perlguru and it doesn't help. So, I tried outputing with or without the header (Content-type:text/html\n\n) and with and without a lot of tags (HTML,HEAD,BODY, etc.) and I always get text messages in my mail box... I've checked the syntax of some HTML mails I received and and they seem like normal web pages to me. So what's wrong? I do receive the e-mails so it's not that, just the body of the message. I tried creating simple HTML e-mails (with only bold or line breaks) and others more complex (with tables, etc). Thanks in advance!


Jasmine
Administrator

Sep 25, 2000, 9:44 AM

Post #2 of 7 (1207 views)
Re: Printing HTML e-mails via SENDMAIL [In reply to] Can't Post

Could you post your code so we can see what may be the problem?


Merlin
journeyman

Sep 25, 2000, 12:46 PM

Post #3 of 7 (1207 views)
Re: Printing HTML e-mails via SENDMAIL [In reply to] Can't Post

Sure, but it's a bit large since I'm combining variables in the mail and adding stuff to the body via a for loop... Here are the main parts :
$from1 = $courriel;
$to1 = "yanc\@qc.aira.com";
$body1 = "<html><head></head><body background=\"http://www.boulangeriestdonat.com/images/back_beige.gif\"><b>Réservation de produits</b><br>\nDate d'envoi : $nomjour{$joursemaine}, le $jour $mois $annee à $heure:$minute.<br>\nDate pour prendre commande : $jourpickup $moispickup, période : $periodepickup<br><br>\nRéservation :<br>\n";
$body1 = $body1 . "<table width=\"550\" border=\"0\">\n<tr>\n<td><b>Nom du produit :</b></td>\n<td><b>format :</b></td>\n<td><b>Prix :</b></td>\n<td><b>Quantité :</b></td>\n</tr>\n";
for ($i=0;$i<@nomproduits;$i++) {
# will be filled soon...
}
$body1 = $body1 . "</body>\n</html>";
open(MAIL,"|/usr/sbin/sendmail -t") | | die "Erreur d'ouverture de SENDMAIL, veuillez recommencer ou contacter le webmestre si l'erreur persiste. Merci.";
print MAIL "To: $to1\nFrom: $from1\n";
print MAIL "Subject: Réservation de produits\n\n";
print MAIL "$body1\n";
close (MAIL);

I've trimmed down and reorganised this part since it involved calling a subroutine to compose the $body1 part. That should be enough, I guess. TIA!
p.s.: this is the version without the print MAIL "Content-type:text/html\n\n"; but it still only prints out as plain text with or without it... Frown

[This message has been edited by Merlin (edited 09-25-2000).]


Jasmine
Administrator

Sep 25, 2000, 1:43 PM

Post #4 of 7 (1207 views)
Re: Printing HTML e-mails via SENDMAIL [In reply to] Can't Post

Looks like you may have one too many \n at the end of your subject line. There must be only one \n at the end of the subject line before the content-type line.

print MAIL "Subject: Réservation de produits\n";
print MAIL "Content-type: text/html\n\n";

Good luck!


Merlin
journeyman

Sep 25, 2000, 5:34 PM

Post #5 of 7 (1207 views)
Re: Printing HTML e-mails via SENDMAIL [In reply to] Can't Post

I'm living in the Twilight Zone!!! You see, I asked someone in another post what was wrong with my SENDMAIL not sending mails. I posted the test script I made and someone told me to use two newlines to show the separation between header and body of the e-mail. I did that and my test script worked, and it ONLY worked like that. Today, I remove the second newline and wham! it works! 8P I can't believe this! Ok, so I removed the second newline. Still what I receive is :
Content-type:text/html

<html><head></head><body background="http://www.boulangeriestdonat.com/images/back_beige.gif"><b>Réservation de produits</b><br>
Date d'envoi : lundi, le 25 8 2000 à 21:33.<br>
Date pour prendre commande : 27 9, période : 0<br><br>
Réservation :<br>
<table width="550" border="0">
<tr>
<td><b>Nom du produit :</b></td>
<td><b>format :</b></td>
<td><b>Prix :</b></td>
<td><b>Quantité :</b></td>
</tr>
</body>
</html>
...and not the real HTML in my e-mail... I tried with and without the "Content-type:text/html\n\n" and it's the same result (minus the top line of course). Any other advice? Thanks!

[This message has been edited by Merlin (edited 09-25-2000).]


Merlin
journeyman

Sep 26, 2000, 6:53 AM

Post #6 of 7 (1207 views)
Re: Printing HTML e-mails via SENDMAIL [In reply to] Can't Post

Well, seems Jasmine was right. I got it working with :
print MAIL "Subject: The subject\n";
print MAIL "Content-type:text/html\n\n";

Gracias! Wink


pinks
Deleted

Sep 26, 2000, 10:23 AM

Post #7 of 7 (1207 views)
Re: Printing HTML e-mails via SENDMAIL [In reply to] Can't Post

It should be like this (NOTE two \n in Subject and only one \n in Content"

print MAIL "Content-type: text/html\n";
print MAIL "Subject: Réservation de produits\n\n";


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives