How to insert HTML tags into a php variable declaration?

Discussion in 'PHP' started by franck~, Jan 25, 2006.

  1. #1
    Let's say you send an email:

    $message = "Someone visited this page of your site.\n\n";
    mail("user@domain.com", "subject", $message, "From: user@domain.com");
    }
    PHP:
    How can you insert html into the $messsage variable declaration, like:
    $message = "Someone visited <strong>this page</strong> of your site.\n\n";
    PHP:
    It doesn't work, it just print the tags as well. How come you cannot do it like you can with "echo" or "print"?

    PS: I tried
    $message = ("Someone visited this page of your site.\n\n");
    PHP:
    as well...
     
    franck~, Jan 25, 2006 IP
  2. stuw

    stuw Peon

    Messages:
    702
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Emails can be sent in 2 formats : plain text and html

    you should use at least the following in your headers:
    $headers = "MIME-Version: 1.0\n";
    $headers .= "Content-type: text/html; charset=iso-8859-1\n";
    $headers .= "From: \n";
    $headers .= "Return-Path: \n";
    $headers .= "Message-Id: <".time()."@".$_SERVER['SERVER_NAME'].">\n";
    $headers .= "X-Mailer: php-mail-function-0.2\n";
    $to='user@domain.com, ';
    mail($to, subject, $message, $headers,"-fuser@domain.com");

    then instead of using /n/r for line breaks you can use <br />

    $headers .= "Content-type: text/html; charset=iso-8859-1\n"; <-- says it's an html format email

    The other extra bits are headers that sometimes cause email to be marked as spam if they are missing.

    Having the 'to' and 'from' address the same may also make your mail marked as spam
     
    stuw, Jan 25, 2006 IP
  3. franck~

    franck~ Peon

    Messages:
    20
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #3
    oh, thanks. So I must declare it is HTML content, then. It makes sense.
    I didn't put all the header thing because it's mailed from my own server, so no chance to be marked as spam.

    I was wondering, in a more general way, can you ad HTML into a variable like in this example:
    $var1 = "something <strong>bold</strong>";
    $var2 = "something <em>italic</em>";
    //then :
    echo "var1"; //I know I could put html here on this line, but I'm just curious
    PHP:
     
    franck~, Jan 25, 2006 IP
  4. stuw

    stuw Peon

    Messages:
    702
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    0
    #4
    There was an easy way to find that out wasn't there?
     
    stuw, Jan 25, 2006 IP
  5. franck~

    franck~ Peon

    Messages:
    20
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #5
    What, testing? Well, precisely, I didn't want to spend 2 hours trying to figure out the proper syntax or to find out it's not possible to do it, rather I thought I could get some relevant help.
    Anyone?
     
    franck~, Jan 25, 2006 IP
  6. stuw

    stuw Peon

    Messages:
    702
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    0
    #6
    yes, is the rather short and obvious answer. Honestly if it takes you 2 hours to test that, then don't give up your day job.

    And by the way, mail gets routed through a number of servers, any number of which may tag your emails as spam.

    A little knowledge is dangerous, and I am running for cover! ;)
     
    stuw, Jan 25, 2006 IP
  7. franck~

    franck~ Peon

    Messages:
    20
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Well thank you for your help sausage eater, that was great. You seem to have an urge to be stinky arrogant. Not my cup of tea. Go play somewhere else, will you. Nobody need that kind of crap in a forum.
    Have I offended you? Did I force you to help me? Am I too ignorant for you?
    I mean, you even look like you're arguing on your avatar picture. You're a pathetic old man.

    --
    The beginning of knowledge is the discovery of something we do not understand.
     
    franck~, Jan 25, 2006 IP
  8. stuw

    stuw Peon

    Messages:
    702
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    0
    #8
    You didn't force me to help you, but I did, as you asked for some.

    I think you'll find in this forum that most people are willing to give help where it's needed - but not to the obviously lazy.
     
    stuw, Jan 25, 2006 IP
  9. calvinmicklefinger

    calvinmicklefinger Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Seems Frankie is projecting in the calling of names. Asking for free help because he's too lazy to test and then complaining smacks of one heckuva immature twit. Basically, a little spoiled baby. You were a lot more polite with your response than mine would have been.
     
    calvinmicklefinger, Dec 12, 2011 IP