Solved

Email in HTML format in PHP

Posted on 2004-09-30
9
225 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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
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

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

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

Suggested Solutions

Any business that wants to seriously grow needs to keep the needs and desires of an international audience of their websites in mind. Making a website friendly to international users isn’t prohibitively expensive and can provide an incredible return…
Developer portfolios can be a bit of an enigma—how do you present yourself to employers without burying them in lines of code?  A modern portfolio is more than just work samples, it’s also a statement of how you work.
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…
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…

738 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