Send email using the GMail SMTP server from a PHP page
I'm trying to get this to work. According to the answer in the given link "it's working code so use it". Except it doesn't work for me.
In particular:
<?php
require_once "Mail.php";
$from = "<xxxxx.gmail.com>";
$to = "<xxxxx.gmail.com>";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";
$host = "smtp.gmail.com";
$port = "465";
$username = "xxxxx@gmail.com";
$password = "*****";
$headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject);
$smtp = Mail::factory('smtp',
array ('host' => $host,
'port' => $port,
'auth' => true,
'username' => $username,
'password' => $password));
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) {
echo("<p>" . $mail->getMessage() . "</p>");
} else {
echo("<p>Message successfully sent!</p>");
}
?> <!-- end of php tag-->
Produces:
Strict Standards: Non-static method Mail::factory() should not be called statically in F:\xampp\htdocs\test\index.php on line 23
Strict Standards: Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in F:\xampp\php\PEAR\Mail\smtp.php on line 365
Strict Standards: Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in F:\xampp\php\PEAR\Net\SMTP.php on line 450
Strict Standards: Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in F:\xampp\php\PEAR\Net\SMTP.php on line 467
While phpinfo() gives registered sockets:
tcp, udp, ssl, sslv3, sslv2, tls
But most importantly, no email sent.