?
Solved

Email in HTML format in PHP

Posted on 2004-09-30
9
Medium Priority
?
239 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
6 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Expert Comment

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

Accepted Solution

by:
ypamudji earned 200 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Dramatic changes are revolutionizing how we build and use technology. Every company is automating, digitizing, and modernizing operations. We need a better, more connected way to work together as teams so we can harness the insights from our system…
Ready to get certified? Check out some courses that help you prepare for third-party exams.
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…
Suggested Courses
Course of the Month17 days, 10 hours left to enroll

830 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