Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: html tags in php variables?

  1. #1
    Join Date
    Jan 2006
    Location
    Ft. Smith, AR
    Posts
    795
    Thanks
    57
    Thanked 129 Times in 116 Posts

    Default html tags in php variables?

    Is it possible to use html tags in a php variable?

    Say if I wanted my variable $body_header to consist of:

    <h2>$fname $lname says:</h2><br />

    I've tried putting it in the variable like this:

    PHP Code:
    $body_header "<h2>$fname $lname says:</h2><br />"
    But it won't print out. It actually prints out the tags rather than implementing them to format the other variables. Is this possible?
    Last edited by TheJoshMan; 08-04-2008 at 11:28 PM. Reason: forgot the semi-colon
    --------------------------------------------------
    Reviews, Interviews, Tutorials, and STUFF
    --------------------------------------------------
    Home of the SexyBookmarks WordPress plugin

  2. #2
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Are you trying to implement this in the mail form you mentioned in another post? If so, you need to make sure that you are sending the Content-type as text/html or multipart/mixed in the headers of the email. Otherwise, you should be able to just echo $body_header and it will display.

    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  3. #3
    Join Date
    Jan 2006
    Location
    Ft. Smith, AR
    Posts
    795
    Thanks
    57
    Thanked 129 Times in 116 Posts

    Default

    yes, this will be the "output" of the form once processed via "sendmail.php"

    I want to format the data to make it more "readable"
    --------------------------------------------------
    Reviews, Interviews, Tutorials, and STUFF
    --------------------------------------------------
    Home of the SexyBookmarks WordPress plugin

  4. #4
    Join Date
    Jan 2006
    Location
    Ft. Smith, AR
    Posts
    795
    Thanks
    57
    Thanked 129 Times in 116 Posts

    Default

    Quote Originally Posted by thetestingsite View Post
    Are you trying to implement this in the mail form you mentioned in another post? If so, you need to make sure that you are sending the Content-type as text/html or multipart/mixed in the headers of the email.
    Now, how would I go about doing that? I didn't see any section about that in that "headers" page you sent me the link to.

    I'm confused. I miss my non-functioning CGI form. LOL

    It didn't work, but boy it was so much easier to grasp.
    --------------------------------------------------
    Reviews, Interviews, Tutorials, and STUFF
    --------------------------------------------------
    Home of the SexyBookmarks WordPress plugin

  5. #5
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    Yes, HTML tags can be used in strings.
    then I don't know about mail.
    Read thetestingsite's post. You have to send the Content-type header as text/html.
    - Mike

  6. #6
    Join Date
    Aug 2008
    Posts
    5
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default

    You have to do something like this:
    PHP Code:
    $from 'YourName';
    $mail_from 'MyEmail@domain.com';
    $mail_to 'YourClient@domain.com';
    $subject 'subject';
    $body '<html><body>Hello</body></html>';

    $headers "From: $from <$mail_from>\r\n";
    $headers .= "Content-Type: text/html; charset=UTF-8;\r\n";
    $headers .= "From: $mail_from\r\n";
    $headers .= "Reply-To: $mail_from\r\n";
    $subject "=?UTF-8?B?".base64_encode($subject)."?=";
    mail($mail_to$subject$body$headers'-t -i -F '.$mail_from.' -f '.$mail_from.''); 

  7. The Following User Says Thank You to volunteeer For This Useful Post:

    TheJoshMan (08-05-2008)

  8. #7
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    That looks like XHTML, not HTML. I suggest you read http://www.webdevout.net/articles/beware-of-xhtml (this is on my ever-growing list of Things People Should Have to Read Before Beginning Web Development).
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  9. The Following User Says Thank You to Twey For This Useful Post:

    TheJoshMan (08-06-2008)

  10. #8
    Join Date
    Jan 2006
    Location
    Ft. Smith, AR
    Posts
    795
    Thanks
    57
    Thanked 129 Times in 116 Posts

    Default

    That was a very informative read. However, this page will be plain old strict HTML 4.01

    I have apparently acquired a bad habbit of making page breaks like <br /> instead of <br>

    I do appreciate you pointing it out, now I can keep an eye out for it to make sure I don't do it anymore.
    --------------------------------------------------
    Reviews, Interviews, Tutorials, and STUFF
    --------------------------------------------------
    Home of the SexyBookmarks WordPress plugin

  11. #9
    Join Date
    Jan 2006
    Location
    Ft. Smith, AR
    Posts
    795
    Thanks
    57
    Thanked 129 Times in 116 Posts

    Default

    I haven't quite decided to "jump on" the XHTML bandwagon yet.
    --------------------------------------------------
    Reviews, Interviews, Tutorials, and STUFF
    --------------------------------------------------
    Home of the SexyBookmarks WordPress plugin

  12. #10
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    I forgot to mention: if you find yourself putting HTML in strings, chances are you should be breaking out of PHP parsing mode instead. If the output isn't to be sent to the browser directly, consider using an output buffer. A template engine such as Smarty is also a good option, although perhaps a little overkill for this case.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  13. The Following User Says Thank You to Twey For This Useful Post:

    TheJoshMan (08-06-2008)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •