To send messages via Gmail SMTP server, you need to specify the Gmail user name and password and also include the SASL class:
phpclasses.org/sasl
require("sasl.php");
$from="gmailuser@gmail.com";
$to="recipient@domain.com";
$smtp=new smtp_class;
$smtp->host_name="smtp.gmail.com";
$smtp->host_port=465;
$smtp->ssl=1;
$smtp->localhost="localhost";
$smtp->direct_delivery=0;
$smtp->timeout=10;
$smtp->data_timeout=0;
$smtp->debug=1;
$smtp->html_debug=1;
$smtp->pop3_auth_host="";
$smtp->user="gmailuser";
$smtp->realm="";
$smtp->password="gmailpassword";
$smtp->workstation="";
$smtp->authentication_mechanism="";
Anyway, to send well-formed messages, it is more recommended to use the SMTP class in conjunction with the smtp_message_class of the MIME message package:
phpclasses.org/mimemessage