SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Guru
    Join Date
    Nov 2008
    Posts
    622
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    htmlspecialchars for email content

    hi all

    I have this below code for textarea in which person enters his enquiry

    PHP Code:
    $body="Hi \n<br><br>".htmlspecialchars($name). " had sent you enquiry . ".  " \n<br><br>
    Person Enquiry = "
    htmlspecialchars($enquiry) . " \n<br><br> "
    mail($to,$body); 
    after person enters enquiry the email is sent with the enquiry entered.

    i receive enquiry content as

    Code:
    yo man\r\n\r\ntesting new site\r\n\r\nstay tuned\r\n\r\nvineet
    how can i use htmlspecialchars in the way it doesnt echoes \r\n\r\

    vineet

  2. #2
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,837
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    htmlspecialchars() is for escaping HTML output.

    If your email is displaying that text as part of an HTML email then those characters will not be visible.

    if you are providing that as a plain text email then you need to get rid of the htmlspecialchars() call so as to not convert it from plain text.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  3. #3
    SitePoint Guru silver trophy JamesColin's Avatar
    Join Date
    May 2009
    Location
    Jomtien, Pattaya, Thailand
    Posts
    910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    felgall is right, but perhaps you were wanting to use http://php.net/manual/en/function.strip-tags.php (to remove html tags) instead of htmlspecialchars() but that isn't necessary in a mail() function, at least I don't think there's a security breach possible. Removing html tags is mostly when you want to output user input (not safe) on your webpage.
    Do you really need traffic? Where to? What for?
    If you really do need traffic then stop messing around!
    Advertise on my sites today: She Told Me & Best Reviewer :
    200,000+ UV / Month


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
  •