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 strongm 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 HTML email?

Status
Not open for further replies.

alan123

MIS
Oct 17, 2002
149
US
I am using "sendmail" to send plain text email by:
open(MAIL,"|$mailprog -t");
print MAIL "To: $recipient\n";
print MAIL "From: $mail_from\n";
print MAIL "Subject: $subject\n\n";
print MAIL "$message\n\n";
close(MAIL);

Now if I want to send rich-text format(with HTML tags), include images, how can I change the codes and implement this?
 
You don't need to change the code above, just change the contents of $message to include your HTML. If the mail reader supports HTML email, it'll work... if not, it will still work (from your end), but will display the raw HTML to the user.

For example:

$message = &quot;<HTML><BODY><P ALIGN=CENTER>Hello!</P></BODY></HTML>&quot;

... of course you could (and should) build it a little more thoroughly than that.

Cheers,
--Craig
 
Add these to the mail script

print MAIL &quot;MIME-version: 1.0\n&quot;;
print MAIL &quot;Content-type: text/html; charset=us-ascii\n&quot;;
print MAIL &quot;Content-transfer-encoding: 7bit\n&quot;;
print MAIL &quot;X-Mailer: [insert your name]\n&quot;;
print MAIL &quot;X-Priority: 1\n&quot;; #1,2 or 3
print MAIL &quot;X-MSMail-priority: Urgent\n&quot;; # or normal or low

HTML then will display properly
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top