Solved

Email in HTML format in PHP

Posted on 2004-09-30
9
220 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
Why do we like using grid based layouts in website design? Let's look at the live examples of websites and compare them to grid based WordPress themes.
The viewer will learn how to dynamically set the form action using jQuery.
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…

747 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

14 Experts available now in Live!

Get 1:1 Help Now