I suggest you use SwiftMailer with its SmtpTransport, where you specify smtp.gmail.com as SMTP server and specify it to use SSL.
Example:
$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com')
->setPort(465)
->setEncryption('ssl')
->setUsername('yourname@gmail.com')
->setPassword('YOUR_SECRET_PWD');
...
Edit,
as requested - here's a full example (untested though):
<?php
require_once "lib/swift_required.php";
$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com')
->setPort(465)
->setEncryption('ssl')
->setUsername('yourname@gmail.com')
->setPassword('YOUR_SECRET_PWD');
$mailer = Swift_Mailer::newInstance($transport);
$htmlBody = '<html><body><h1>HTML-mail example!</h1><p>Contents</p></body></html>';
$plainBody = 'Looks like you cannot read HTML-emails? This is alternative content only for you.';
$message = Swift_Message::newInstance('This is the subject of the e-mail')
->setFrom(array('yourname@gmail.com' => 'You Name'))
->setTo(array('yourfriend@domain.com' => 'Your Friends Name'))
->setBody($plainBody)
->addPart($htmlBody, 'text/html');
$mailer->send($message);