Solved

Email in HTML format in PHP

Posted on 2004-09-30
9
222 Views
Last Modified: 2006-11-17
I have a web page where contain a form.

After submiiting the form I want to send an email in HTML format in PHP.

I use a code, but the Email not send in HTML format, it send in text format.

Please short out this problem,

The code are as follows:
==================

$details="<html><body><table bgcolor='#ffffff'>";
      foreach($_POST as $key => $value)
      {
               $details.="<tr><td><b>".$key."</b></td><td><b>&nbsp;&nbsp;</b></td><td>".$value."</td></tr>";
      }
      $details.="</table></body></html>";
      $to="backoffice@niwell.com";
      $subject=$HTTP_POST_VARS["subject"];
      $from=$HTTP_POST_VARS["Email1"];
      $headers="From: $from\r\n";
      $headers.= "MIME-Version: 1.0\r\n";
      $headers.= "Content-type: text/html; charset=iso-8859-1\r\n";
            
      mail($to,$subject,$details,$headers);
0
Comment
Question by:bubai_nag
9 Comments
 
LVL 3

Expert Comment

by:daniel416
ID: 12191108
from what i know, html *is* text.
so an email in html will be sent as text and the html parsed by the email client.

have you made sure that your email client is set to show html messages as html?

let us know how you're doing.
0
 

Expert Comment

by:dcaurelien
ID: 12192313
here is a short but simple way to do it, works fine for me.

if there is any problem with this please write back and i will correct and send you a working script via e-mail

good luck

::: sendemail.html :::

<html>
  <head>
    <title>Send HTML E-Mail using PHP</title>
  </head>
  <body>
    <form action="sendemail.php" method="post">
    To(E-Mail):<input type="text" name="emailto" size="30">
    <br> <br>
    Subject:<input type="text" name="mailsub" size="30">
    <br> <br>
    From(Name):<input type="text" name="mailname" size="30">
    <br> <br>
    From(E-Mail):<input type="text" name="mailaddress" size="30">
    <br> <br>
    <textarea name="mailmain" cols="30" rows="5">
    </textarea> <br>
    <input type="submit" value="send mail">
    </form>
  </body>
</html>

::: sendemail.php :::

<?php
    $to = $emailto;
    $re = $mailsub;
    $msg = $mailmain;

   $headers = "MIME-Version  1.0\r\n";
   $headers .= "Content-type: text/html; ";
   $headers .= "charset=iso-8859-1\r\n";

   $headers .= "From: $mailaddress \r\n";  
   
   mail($to, $re, $msg,  $headers);

?>

<html>
<head>
<title>Message Sent</title>
</head>
<body> <h3>Your Message Has Been Sent</h3>
</body>
</html>

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::


0
 
LVL 18

Expert Comment

by:arantius
ID: 12192893
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 3

Expert Comment

by:daniel416
ID: 12195731
@arantius
Thanks!
didn't know that.
0
 

Accepted Solution

by:
ypamudji earned 50 total points
ID: 12202342
I just copied your code and modified the variable fields like $details, $subject, and $from to be literal strings instead of assigning them variable values.  Tested it and it works, pulling up the e-mail in MS Outlook 2003--displayed as HTML (put an "<a href>" in the $details, and it displayed properly as a link in the email).

Could it be the mail client you're using to check the message?  Maybe you need to enable HTML message reading?
0
 

Expert Comment

by:ypamudji
ID: 12523412
Well like I said in my previous comments, I copied his code into a blank script and modified some variable values, and it worked.  Perhaps from that knowledge the original poster realized that whatever the problem was, this snippet of code was not to blame after all.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've been asked to discuss some of the UX activities that I'm using with my team. Here I will share some details about how we approach UX projects.
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…
The viewer will learn how to count occurrences of each item in an array.

815 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

10 Experts available now in Live!

Get 1:1 Help Now