Google SMTP is useful if the IP address of your vps server is blacklisted and your mails go to spam.
You can check status of your VPS IP Address from here.
Step 1 : Install msmtp package
apt-get install msmtp-mta ca-certificates
Step 2 : Fill the config file of msmtp
Edit /etc/msmtprc file :
Copy and paste the following lines into it :
Hit Ctrl+X to exit nano and save it.
Step 3 : Alter the php.ini file to use msmtp
Edit php.ini file. php.ini file is placed in /etc/php5/apache2.ini or /etc/php4/apache2/php.ini.
You can find the place of php.ini from phpinfo(); of your server.
Find ( using Ctrl+W) around line 560 :
sendmail_path = "/usr/sbin/sendmail -t -i "
and change it to :
sendmail_path = "/usr/bin/msmtp -t -i "
Save and close the file with Ctrl+X
Step 4 : Restart Webserver
You can see if it is working or not with this php script :
$to = "email@example.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "firstname.lastname@example.org";
$headers = "From: $from";
echo "Mail Sent.";