HTML not being recognized

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
sug15
Forum Newbie
Posts: 4
Joined: Sun Feb 03, 2008 5:14 pm

HTML not being recognized

Post by sug15 »

Hey. I just coded this simple email script. I am a beginner to html.
I have 2 problems. The first is that It will not recognize the <br /> as breaks. it just displays them in the email as "</br >". For example, if the user types "Gloss Metal" for a theme name, and then "Harry J" for developer name, and clicks submit, the email will be outputed as "Gloss Metal<br />Harry J".

The second problem is that it is giving me this When I click submit:

Code: Select all

Warning: Cannot modify header information - headers already sent by (output started at /home/content/s/u/g/sug15/html/sendmail.php:6) in /home/content/s/u/g/sug15/html/sendmail.php on line 19
However, the email is still sent.

Here is the code for my HTML page (index.html):

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Theme Upload</title>
</head>
<body>
<h2>Add your theme to our database
</h2>
<form method="post" action="sendmail.php">
  <p>Your Email:
  <br> 
    <input name="email" type="text" />
  </p>
  <p>
  Theme's name:
  <br />
    <input name="tname" type="text" size="35" />
  </p>
  <p>Developer's name:    
    <br>
    <input name="dname" type="text" size="35" />
    </p>
    <p>Theme's description:
      <br>
      <textarea name="desciption" cols="45" rows="3"></textarea>
    </p>
      <p>Screenshot link 1:    
    <br>
    <input name="ss1" type="text" size="40" />
  <p>Screenshot link 2:    
    <br>
    <input name="ss2" type="text" size="40" />
    </p>
    <p>Screenshot link 3:    
    <br>
    <input name="ss3" type="text" size="40" />
    
    <blockquote>
      <p>
        <input type="submit" /> 
         <input name="" type="reset" value="Reset" />
        </p>
    </blockquote>
</form>
 
</body>
</html>
Here is the code for my PHP page:

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
 
<p>
  <?php
  $email = $_REQUEST['email'] ;
  $tname = $_REQUEST['tname'] ;
  $dname = $_REQUEST['dname'] ;
  $description = $_REQUEST['description'] ;
  $ss1 = $_REQUEST['ss1'] ;
  $ss2 = $_REQUEST['ss2'] ;
  $ss3 = $_REQUEST['ss3'] ;
  $return = ("<br />");
  $message = $tname . $return . $dname . $return . $description . $return . $ss1 . $return . $ss2 . $return . $ss3;
 
  mail( "12345@email.com", "Theme",
    $message, "From: $email" );
  header( "Location: http://website.com/thanks.html" );
?>
 
</body>
</html>
And the thanks.html is just a simple html page.

Help, please.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: HTML not being recognized

Post by Christopher »

If you output any characters then PHP will send its current headers and then those characters. So you can have not output before you call the header() function. Just do:

Code: Select all

<?php
  $email = $_REQUEST['email'] ;
  $tname = $_REQUEST['tname'] ;
  $dname = $_REQUEST['dname'] ;
  $description = $_REQUEST['description'] ;
  $ss1 = $_REQUEST['ss1'] ;
  $ss2 = $_REQUEST['ss2'] ;
  $ss3 = $_REQUEST['ss3'] ;
  $return = ("<br />");
  $message = $tname . $return . $dname . $return . $description . $return . $ss1 . $return . $ss2 . $return . $ss3;
 
  mail( "12345@email.com", "Theme",
    $message, "From: $email" );
  header( "Location: http://website.com/thanks.html" );
(#10850)
sug15
Forum Newbie
Posts: 4
Joined: Sun Feb 03, 2008 5:14 pm

Re: HTML not being recognized

Post by sug15 »

Thanks.

But how can I fix the </ br> problem?
User avatar
maliskoleather
Forum Contributor
Posts: 155
Joined: Tue May 15, 2007 2:19 am
Contact:

Re: HTML not being recognized

Post by maliskoleather »

you should be using

Code: Select all

$return = "\n";
sug15
Forum Newbie
Posts: 4
Joined: Sun Feb 03, 2008 5:14 pm

Re: HTML not being recognized

Post by sug15 »

Ok, now I'm getting this:

Code: Select all

Parse error: syntax error, unexpected T_STRING on line 12
Here is the updated php:

Code: Select all

<?php
  $email = $_REQUEST['email'] ;
  $tname = $_REQUEST['tname'] ;
  $dname = $_REQUEST['dname'] ;
  $description = $_REQUEST['description'] ;
  $ss1 = $_REQUEST['ss1'] ;
  $ss2 = $_REQUEST['ss2'] ;
  $ss3 = $_REQUEST['ss3'] ;
  $return = "\n";
  $message = $tname . $return . $dname . $return . $description . $return . $ss1 . $return . $ss2 . $return . $ss3
  
  mail( "name@example.com", "Theme",
    $message, "From: $email" );
  header( "Location: http://website.com/thanks.html" );
?>
 
Thanks. you guys have been a great help so far.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: HTML not being recognized

Post by califdon »

<br /> is an HTML tag. Unless you send email with a MIME header (and even then, with some email systems), HTML won't be recognized in an email.

Try this:

Code: Select all

$message = "$tname \r\n $dname \r\n $description \r\n $ss1 \r\n $ss2 \r\n $ss3";
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: HTML not being recognized

Post by Jonah Bron »

You could also change the headers of the email, and send an HTML email

http://www.google.com/search?sourceid=n ... html+email
sug15
Forum Newbie
Posts: 4
Joined: Sun Feb 03, 2008 5:14 pm

Re: HTML not being recognized

Post by sug15 »

Thanks, everyone.

It's working perfectly, now :)
Post Reply