Change SMTP=localhost to SMTP=smtp.gmail.com
//try to set IP Address of SMTP server or the Machine Name
$mail->IsSMTP(); // set mailer to use SMTP
$mail->Host = "IP Address or machine name"; // specify main and backup server
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = 'Username'; //SMTP username
$mail->Password = 'Password';
$mail->Port = 25;