I have the following PHP code that is supposed to send email (running it on a apache server):
<?php
require_once "Mail.php";
$from = '<myemail@gmail.com>';
$to = '<destination@gmail.com>';
$subject = 'PHP test';
$body = "Hi,\n\n How are you? This was sent by a PHP program. ";
$headers = array(
'From' => $from,
'To' => $to,
'Subject' => $subject
);
$smtp = Mail::factory('smtp', array(
'host' => 'smtp.gmail.com',
'port' => '465',
'auth' => true,
'username' => 'myemail@gmail.com',
'password' => 'mypass'
));
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) {
echo('<p>' . $mail->getMessage() . '</p>');
} else {
echo('<p>Message successfully sent!</p>');
}
?>
I get the following error message:
Failed to connect to smtp.gmail.com:465 [SMTP: Failed to connect socket: Connection refused (code: -1, response: )]
I tried to send the email using the same SMTP server and with same emails through matlab and it worked.