Ok I got the HTML email mail() function working using a variable like:

$msg = "<html><b>TEST</b></html>";

but if I try to pull the code from a form like:

$msg = $message_body;

//$message_body = textarea form input

then it doesnt retain some of the HTML code, i mean it sorta works but the fonts dont change or anything.

What am I doing wrong!!??

Thanks!

    you need to send the correct headers "telling" PHP so send the mail as HTML, otherwise it won't

    <?
    $to = "you@yoursite.com";
    $from = "me@mysite.com";
    $subject = "Subject about mysite and yoursite";
    $message = "
    <html>
    <head></head>
    <body>
    Whatever HTML you want in here!
    </body>
    </html>
    ";
    
    $headers  = "MIME-Version: 1.0\r\n";
    $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
    $headers .= "From: $from  <$from>\r\n";
    mail($to, $subject, $message, $headers);
    ?>
    

      Yeah I have the code right but it isnt working see here is what im using:

      The form page:

      <html>
      <head>
      <title>Untitled Document</title>
      </head>
      <body>
      <form action="testmail2.php" method="post" enctype="application/x-www-form-urlencoded" name="form1">
      <p>
      <textarea name="msgbdy" wrap="OFF" id="msgbdy"></textarea>
      </p>
      <p>
      <input type="submit" name="Submit" value="Submit">
      </p>
      </form>
      </body>
      </html>

      and then here is the action page's PHP:

      <?php 
      
      
      $to = "dwasyluk@artfunction.com"; 
      $subject="Registration Information"; 
      $msg=""; 
      $msg .= $msgbdy;
      
      echo"$msg"; 
      $headers = "MIME-Version: 1.0\r\n"; 
      $headers .= "Content-type: text/html; charset=iso-8859-1\r\n"; 
      $headers .="From:Centre of Economics Form<info@cie-economics.com>\r\n"; 
      mail($to, $subject, $msg, $headers); 
      
      echo"<div align=center><FONT face=verdana size=2>Thanks for the information</font></div>"; 
      echo "<div align=center><FONT face=verdana size=2>The Information is emailed to Administrator-Centre</font></div>"; 
      ?> 
       

      Using this the HTML email will appear somewhat correct, but fonts dont display as they should, etc....

        just tried HTML entities, didnt work. You can view the above form and action pages at:

        www.artfunction.com/ISAHP/tm.php
        when you submit the email appears in the action page formatted how it will appear in the email. As you can see if you try it out, it doesnt seem to like style's etc.

        PLEASE HELP

          OK I just tried hard-coding the html email in, instead of sending it in the variable and it worked fine!

          Why wont the form-based email work? Like if I do

          $msg = "HTML CODE I PASTE IN";

          Works great no problems

          yet

          $msg = $msgbdy; //variable from form

          It doesnt work!

            When I view the source of the sent email it looks like this:

            <html>
            <head>
            <title>Untitled Document</title>
            <style type=\"text/css\">
            <!--
            .style1 {
            font-family: Verdana, Arial, Helvetica, sans-serif;
            font-size: 10px;
            font-weight: bold;
            }
            -->
            </style>
            </head>

            <body>
            <p class=\"style1\">HEEELLLOOO
            </p>
            <p class=\"style1\">&nbsp;</p>
            </body>
            </html>

            if I can make it stop adding / before " I think it will work, do you know how I can do this?

              Hi,

              try

              $msg = stripslashes($msgbdy);
              

              Thomas

                Write a Reply...