Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to send an HTML email

Status
Not open for further replies.

NateBro

Programmer
Sep 1, 2004
233
US
I have an order form and i have it where it sends a thank you e-mail in plain-text but i was wondering how i could send one in HTML format. thanks.
 
It should be as simple as outputting a Content-Type header at the top of your message, and then producing your message as well formed HTML

HTH
--Paul

PS your perl post confused the heck outta me
if ( anything that can be true ) { do_this; }
is the same as
do_this;
 
I tried an HTML header, and it didn't work. do you have one that works?

sorry about that, i was trying to get that done and i was loosing my mind, so i had to stop and rethink it, and i was thinking something way off from what i really wanted to do. :S
 
Code:
$ENV{PATH} = "/usr/sbin";

# open the pipe to sendmail
open (MAIL, "|/usr/sbin/sendmail -oi -t") or 
    &dienice("Can't fork for sendmail: $!\n");

# change this to your own e-mail address

my $recipient = 'jgleone@msn.com';

# Start printing the mail headers
# You must specify who it's to, or it won't be delivered:

print MAIL "To: $recipient\n";

# From should probably be the webserver.

print MAIL "From: order\@JerichoJunction.com\n";

# print a subject line so you know it's from your form cgi.

print MAIL "Subject: Jericho Junction order\n\n";

# Now print the body of your mail message.

print MAIL "          $firsttm                



                         Jericho Junction Order Confirmation
                         
                         
 
	Church Name: $church

	Recipiants Name: $first $middle $last

	Position/Title: $title

	Street Address: $address1 

	City: $city

	State: $state

	Zip: $zip

	Daytime Phone: $phone

	Card Type: $visa

	Card Number: $cardnum

	Exp. Date: $month/$year

	E-Mail: $address2

 _____________________________________________________________________
|              DESCRIPTION                                  QUANTITY  |
|?????????????????????????????????????????????????????????????????????|
| Jericho Junction Children's Church Production Kit --------- $Qntya       |
| Jericho Junction Video Training Seminar           --------- $Qntyb       |
| Jericho Junction Children's Music CD              --------- $Qntyc       |
|                                                                     |
|?????????????????????????????????????????????????????????????????????|
|                    Jericho Junction 100% Cotton T-Shirt             |
|                                                                     |
| Adult: S = $QntyjjsAa  M = $QntyjjsAb L = $QntyjjsAc XL = $QntyjjsAd 2X = $QntyjjsAe                             |
| Child: S = $QntyjjsCa  M = $QntyjjsCb L = $QntyjjsCc                                           |
|                                                                     |
|?????????????????????????????????????????????????????????????????????|
| Jericho Junction Sound Effects CD                 --------- $Qntyd       |
| Search for Hidden Treasures VBS Production Kit    --------- $Qntye       |
| Berry Farm VBS Production Kit                     --------- $berry       |
|                                                                     |
|?????????????????????????????????????????????????????????????????????|
|              Search for Hidden Treasures  100% Cotton T-Shirt       |
|                                                                     |
| Adult: S = $QntyhtsAa M = $QntyhtsAb  L = $QntyhtsAc XL = $QntyhtsAd 2X = $QntyhtsAe                             |
| Child: S = $QntyhtsCa M = $QntyhtsCb  L = $QntyhtsCc                                           |
|                                                                     |
|?????????????????????????????????????????????????????????????????????|
| Kidz Zone Curriculum                              --------- $Qntyf       |
|                                                                     |
|?????????????????????????????????????????????????????????????????????|
|  Merchandise Total   --------------------------------- \$$total
|  Shipping & Handling --------------------------------- \$$totalship
|  TOTAL AMOUNT DUE    --------------------------------- \$$totalgrnd
|                                                                     |
 ?????????????????????????????????????????????????????????????????????
\n";


# Be sure to close the MAIL input stream so that the
# message actually gets mailed.

close(MAIL);
 
Try this
Code:
print MAIL "Content-Type: text/html\n\n          $firsttm

If its a HTML compatible reader it should render any html proper thereafter

HTH
--Paul

cigless ...
 
Ok, this is weird...

I used

Code:
print MAIL "Content-Type: text/html\n\n          $firsttm

and this is the email it sent...


Code:
print MAIL Content-Type: text/html/n/n          This order was 
completed at, 1:14.27 and sent on 03/03/2005     

<HTML>     

							 This order was completed at, 1:14.27 and sent on 03/03/2005                



                         Jericho Junction Order Confirmation
                         
                         
 
	Church Name: test   

	Recipiants Name: test t test

	Position/Title: test

	Street Address: test 

	City: test

	State: te

	Zip: test

	Daytime Phone: v

	Card Type: Visa

	Card Number: test

	Exp. Date: 1/2005

	E-Mail: test

 _____________________________________________________________________
|              DESCRIPTION                                  QUANTITY  |
|¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯|
| Jericho Junction Children's Church Production Kit --------- 53       
|
| Jericho Junction Video Training Seminar           --------- 3       |
| Jericho Junction Children's Music CD              --------- 0       |
|                                                                     |
|¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯|
|                    Jericho Junction 100% Cotton T-Shirt             |
|                                                                     |
| Adult: S = 0  M = 0 L = 0 XL = 0 2X = 0                             |
| Child: S = 0  M = 0 L = 0                                           |
|                                                                     |
|¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯|
| Jericho Junction Sound Effects CD                 --------- 0       |
| Search for Hidden Treasures VBS Production Kit    --------- 0       |
| Berry Farm VBS Production Kit                     --------- 0       |
|                                                                     |
|¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯|
|              Search for Hidden Treasures  100% Cotton T-Shirt       |
|                                                                     |
| Adult: S = 0 M = 0  L = 0 XL = 0 2X = 0                             |
| Child: S = 0 M = 0  L = 0                                           |
|                                                                     |
|¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯|
| Kidz Zone Curriculum                              --------- 0       |
|                                                                     |
|¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯|
|  Merchandise Total   --------------------------------- $21356.85
|  Shipping & Handling --------------------------------- $
|  TOTAL AMOUNT DUE    --------------------------------- $
|                                                                     |
 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯


</HTML>

/n


why would it send the "print MAIL"?

but if i take the " Content-Type: text/html\n\n " out it does not send the "print MAIL"

does some one have a different send mail script that works for HTML emails, i should just get a clean working one, and delete this one.

thnaks,
~Nate_Bro
 
I'm using this code...

Code:
$ENV{PATH} = "/usr/sbin";

# open the pipe to sendmail
open (MAIL, "|/usr/sbin/sendmail -oi -t") or 
    &dienice("Can't fork for sendmail: $!\n");

# change this to your own e-mail address

my $recipient = 'jgleone@msn.com';

# Start printing the mail headers
# You must specify who it's to, or it won't be delivered:

print MAIL "To: $recipient\n";

# From should probably be the webserver.

print MAIL "From: order\@JerichoJunction.com\n";

# print a subject line so you know it's from your form cgi.

print MAIL "Subject: Jericho Junction order\n\n";

# Now print the body of your mail message.

print MAIL " Content-Type: text/html/n/n

<HTML>         $firsttm                



                         Jericho Junction Order Confirmation
                         
                         
 
    Church Name: $church

    Recipiants Name: $first $middle $last

    Position/Title: $title

    Street Address: $address1 

    City: $city

    State: $state

    Zip: $zip

    Daytime Phone: $phone

    Card Type: $visa

    Card Number: $cardnum

    Exp. Date: $month/$year

    E-Mail: $address2

 _____________________________________________________________________
|              DESCRIPTION                                  QUANTITY  |
|?????????????????????????????????????????????????????????????????????|
| Jericho Junction Children's Church Production Kit --------- $Qntya       |
| Jericho Junction Video Training Seminar           --------- $Qntyb       |
| Jericho Junction Children's Music CD              --------- $Qntyc       |
|                                                                     |
|?????????????????????????????????????????????????????????????????????|
|                    Jericho Junction 100% Cotton T-Shirt             |
|                                                                     |
| Adult: S = $QntyjjsAa  M = $QntyjjsAb L = $QntyjjsAc XL = $QntyjjsAd 2X = $QntyjjsAe                             |
| Child: S = $QntyjjsCa  M = $QntyjjsCb L = $QntyjjsCc                                           |
|                                                                     |
|?????????????????????????????????????????????????????????????????????|
| Jericho Junction Sound Effects CD                 --------- $Qntyd       |
| Search for Hidden Treasures VBS Production Kit    --------- $Qntye       |
| Berry Farm VBS Production Kit                     --------- $berry       |
|                                                                     |
|?????????????????????????????????????????????????????????????????????|
|              Search for Hidden Treasures  100% Cotton T-Shirt       |
|                                                                     |
| Adult: S = $QntyhtsAa M = $QntyhtsAb  L = $QntyhtsAc XL = $QntyhtsAd 2X = $QntyhtsAe                             |
| Child: S = $QntyhtsCa M = $QntyhtsCb  L = $QntyhtsCc                                           |
|                                                                     |
|?????????????????????????????????????????????????????????????????????|
| Kidz Zone Curriculum                              --------- $Qntyf       |
|                                                                     |
|?????????????????????????????????????????????????????????????????????|
|  Merchandise Total   --------------------------------- \$$total
|  Shipping & Handling --------------------------------- \$$totalship
|  TOTAL AMOUNT DUE    --------------------------------- \$$totalgrnd
|                                                                     |
 ?????????????????????????????????????????????????????????????????????
\n";


# Be sure to close the MAIL input stream so that the
# message actually gets mailed.

close(MAIL);

...where is the missing Quote(s)?

it sends this email without the quotes

There has got to be something i missed.

Code:
print MAIL Content-Type: text/html/n/n          This order was 
completed at, 1:14.27 and sent on 03/03/2005     

<HTML>     

                             This order was completed at, 1:14.27 and sent on 03/03/2005                



                         Jericho Junction Order Confirmation
                         
                         
 
    Church Name: test   

    Recipiants Name: test t test

    Position/Title: test

    Street Address: test 

    City: test

    State: te

    Zip: test

    Daytime Phone: v

    Card Type: Visa

    Card Number: test

    Exp. Date: 1/2005

    E-Mail: test

 _____________________________________________________________________
|              DESCRIPTION                                  QUANTITY  |
|¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯|
| Jericho Junction Children's Church Production Kit --------- 53       
|
| Jericho Junction Video Training Seminar           --------- 3       |
| Jericho Junction Children's Music CD              --------- 0       |
|                                                                     |
|¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯|
|                    Jericho Junction 100% Cotton T-Shirt             |
|                                                                     |
| Adult: S = 0  M = 0 L = 0 XL = 0 2X = 0                             |
| Child: S = 0  M = 0 L = 0                                           |
|                                                                     |
|¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯|
| Jericho Junction Sound Effects CD                 --------- 0       |
| Search for Hidden Treasures VBS Production Kit    --------- 0       |
| Berry Farm VBS Production Kit                     --------- 0       |
|                                                                     |
|¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯|
|              Search for Hidden Treasures  100% Cotton T-Shirt       |
|                                                                     |
| Adult: S = 0 M = 0  L = 0 XL = 0 2X = 0                             |
| Child: S = 0 M = 0  L = 0                                           |
|                                                                     |
|¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯|
| Kidz Zone Curriculum                              --------- 0       |
|                                                                     |
|¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯|
|  Merchandise Total   --------------------------------- $21356.85
|  Shipping & Handling --------------------------------- $
|  TOTAL AMOUNT DUE    --------------------------------- $
|                                                                     |
 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯


</HTML>

/n
 
print MAIL "Content-Type: text/html\n\n";
print MAIL "<html .......

--Paul

cigless ...
 
Ok, i made a script that only sends an email..

Code:
#!/usr/bin/perl -w
use CGI qw(:standard);
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
print header;
print start_html("Remote Host");

#### Program Starts here ####

my $recipient = 'natesk8@sbcglobal.net';

$ENV{PATH} = "/usr/sbin";

open (MAIL, "|/usr/sbin/sendmail -oi -t") or &dienice("Can't fork for sendmail: $!\n");



print MAIL "To: $recipient\n";

print MAIL "From: me\@myself.com\n";

print MAIL "Subject: Testing email script\n\n";

print MAIL "Content-Type: text/html\n\n";

print MAIL " this is a test body \n";



close(MAIL);

      #### END ####

print "it has been sent\n";

and i still get this in the email..
Code:
Content-Type: text/html

 this is a test body

what did i do wrong now?
 
Take out the second \n from the Subject line. The content type header needs to be sent as a header, but the two \n's after the subject is pushing it down into the body.

- Rieekan
 
hey thanks, all that was wrong was the \n i took it out and now it works fine :D
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top