尝试通过PHP文件发送电子邮件时出错:"无法连接到smtp.gmail.com:465 [SMTP:无法连接套接字:连接被拒绝"

时间:2017-03-13 02:00:58

标签: php apache email smtp

我有以下PHP代码应该发送电子邮件(在Apache服务器上运行):

<?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>');
}

?>        

我收到以下错误消息:

Failed to connect to smtp.gmail.com:465 [SMTP: Failed to connect socket: Connection refused (code: -1, response: )]

我尝试通过matlab使用相同的SMTP服务器和相同的电子邮件发送电子邮件,但它确实有效。

0 个答案:

没有答案