?
Solved

Email in HTML format in PHP

Posted on 2004-09-30
9
Medium Priority
?
230 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Get MySQL database support online, now!

At Percona’s web store you can order your MySQL database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit 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

Industry Leaders: 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

Color can increase conversions, create feelings of warmth or even incite people to get behind a cause. If you want your website to really impact site visitors, then it is vital to consider the impact color has on them.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

764 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