require_once(LIBRARY_PATH . "phpmailer.php");
require_once(CONFIG_PATH . "emailconfig.php");

class email
{
    public function sendMail($from,$fromname,$subject,$content,$to){
        $mail             = new PHPMailer();

        $mail->SMTPAuth   = SMTPAuth ;
        $mail->IsSMTP();
        $mail->SMTPSecure = SMTPSecure;
        $mail->Host       = Host;
        $mail->Port       = Port;
        $mail->Username   = Username;
        $mail->Password   = Password;

        $mail->From       = $from;
        $mail->FromName   = $fromname;
        $mail->Subject    = $subject;
        $mail->Body       = $content;
        $mail->AddAddress($to);
        $mail->IsHTML(true);
        if(!$mail->Send()){
            return false;
        }else{
            return true;
        }
    }
}

The code mentioned above is used for sending mails on the website. It works fine as far as sending mail is concerned but the mail received does not have correct email address in from tag, instead it sets the email address in 'username' as 'from' address. So the 'from' address is lost and if we reply to that mail we actually send the reply to 'usename' address instead of the 'from' address.

Have no idea what is wrong with it, sets the 'fromName', 'subject', 'body' correctly. SMTPAuth, SMTPSecure, Host, Port, Username, Password are constants defined in emailconfig.php like this:

define("SMTPAuth","true");

define("SMTPSecure","ssl");

define("Host","smtp.gmail.com");

define("Port","465");

define("Username","something@something.com");

define("Password","password");

I will be really thankful if anyone could help me in this regard.

Try setting the $mail->Username = $username, defining $username beforehand, maybe Username is already defined, or is some kind of system variable set up on the server.