Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Jan 2007
    Thanked 0 Times in 0 Posts

    html tags in mail()

    i am trying to format the feedback forum mail tht ppl can send...
    i am getting the html tags as it is than the effect

    i am using GMAIL

    PHP Code:
    //check for required fields
    if((!$_POST[name]) || (!$_POST[email]) || (!$_POST[comments])) {
    " Please fill Up the Required Fields ".'<br /><a href="javascript:history.go(-1)">'."Click Here".'</a>';

    $company strtoupper($_REQUEST['company']) ;
    $name ucfirst($_REQUEST['name']) ;
    $email $_REQUEST['email'] ;
    $phone $_REQUEST['phone'] ;
    $address $_REQUEST['address'] ;
    $city $_REQUEST['city'] ;
    $zipcode $_REQUEST['zipcode'] ;
    $comments $_REQUEST['comments'] ;

    $message ="<strong>Company:</strong> $company \n<strong>Name:</strong> $name \n<strong>Email:</strong> $email \n<strong>Phone:</strong> $phone \n<strong>Address:</strong> $address \n<strong>City:</strong> $city \n<strong>Zip Code:</strong> $zipcode \n\n<strong>Comments:</strong> $comments";

    mail"hmvrulz@gmail.com""HMV.co.in : $name",
    $message"From: $email" );
    header"Location: index.html" );

  • #2
    Regular Coder
    Join Date
    Dec 2006
    Thanked 1 Time in 1 Post
    I don't understand. What are you trying to do?

    What error are you getting?

  • #3
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Thanked 330 Times in 326 Posts
    I think he's saying that the contents of $message are showing up literally, rather than being treated as HTML.

    Try passing headers to the mail function that flag the message as HTML. Check the PHP reference for how to do this. Also, I noticed in a comment there that gmail needs the header lines to be terminated by a real newline (\n) rather than a Windows newline (\r\n).

  • #4
    Regular Coder
    Join Date
    Dec 2007
    Thanked 2 Times in 2 Posts
    You could do this yourself or you could use a pre-written class such as PHPMailer or PEAR::mail to do it. Those classes have proven code in them and are re-usable. Sending mail with PHP is a little more complicated than just using the mail function.

    If you want the mail to get to accounts on the big mail services, and survive all the things that can happen to email messages between the time that the MTA gets the message from mail(), till it reaches it's destination, the format and in many cases the content, have to be just so.

    I suppose if you had an interest in learning the MIME email spec, you could put together your own class, but if you just want it to work and move on, using the above mentioned classes is the way to go. Especially when you want to do attachments and HTML. There is definitely no excuse for writing the same email code out for multiple projects, rather than just putting together some re-usable scripts to do it.
    Deliver yesterday, code today, think tomorrow.


    Posting Permissions

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