Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial


How to apply style in head section ?

Back (accesskey b)    Save (accesskey s)        File: /public_html/recover.php
    Status: Saved on 2016-06-23 07:03:50 using mode FTP_ASCII

//including sessions file
   require 'functions/session.php';
//checking is user in or not
  //checking is user in or not
//creating a variable for error messages
$error = "";
//creating a variable for success messages
$success = "";
//creating variable for page title
   $pageTitle = "Recover";
   include 'includes/header.php';

           if($_SERVER['REQUEST_METHOD'] == "POST"){
             //email sanitization
             $email =  trim(filter_input(INPUT_POST,'email',FILTER_SANITIZE_EMAIL));
             //checking for empty feilds
             if($email == ""){
                $error = "Something Missing";
             //email validation
             if(empty($error) && (!filter_var($email,FILTER_VALIDATE_EMAIL) || !email_exist($email))){ 
                $error = "Invalid Email Address";

            //process mailing now
                $to           =  $email;
                $subject      =  "Username Recovery";
                $from         =   'clone_network@org.com';
                $userInfo     =  getuserName($email);

                   //For sending HTML email
                $headers         = 'MIME-Version: 1.0' . "\r\n";
                $headers        .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

                //Creating email header
                $headers         .= 'From: '.$from."\r\n".
                                   'Reply-To: '.$from."\r\n".

                //creating message body
              $body          =  "<html><head>"; 
              $body         .=  "</head><body style='background:#dcdcdc; padding:50px;'>";
              $body         .=  "<div style = 'background:#fff; padding:15px;'>";
              $body         .=  "<h1 style ='color:#dcdcdc;'>Hello , ".$userInfo['firstName']."</h1><br><br>";
              $body         .=  "<i>We've received a request from you related to account recovery<br></i>";
              $body         .=  "Your username is : <b>".$userInfo['userName']."</b><br><br><br>";
              $body         .=  "---<b><u>ADMIN</u></b>---<br>";
              $body         .=  "Ashish Mehra";
              $body         .=  "</div></body></html>";

                    $error = "Oop's something went wrong";

<form action="" method="post">
    <!--error output-->
     if(empty($error) && !empty($success)){
          echo "<span class=\"success\" data-icon ='&#xea10;'>".$success."</span>";
         echo "<span class=\"error\" data-icon ='&#xea0f;'>".$error."</span>";
           <input type="email" name="email" id="email" placeholder="Email">
           <input type="submit" name="submit" value="Recover">

  include 'includes/footer.php';

I am sending mail to users through mail function including html but when i try to insert style under head it doesn't work for me will any one tell me how i can use internal or external css here...

1 Answer

Hi Ashish,

I'd normally suggest using a library or something ilke PEAR:Mail_Mime to achieve that, but have you tried setting the Content -type:

$headers         .= 'From: '.$from."\r\n".
                                   'Reply-To: '.$from."\r\n".
                                   'X-Mailer:PHP/'.phpversion(). "\r\n";
                                   'MIME-Version: 1.0' . "\r\n";
                                  'Content-type: text/html; charset=iso-8859-1' . "\r\n";

I haven't tested, but its worth a try.

KB :octopus: