PEAR 邮件连接拒绝 smtp.gmail.com
我在尝试使用 pear 邮件包发送邮件时遇到了无尽的麻烦:
我在本地计算机上使用 xampp 进行测试,并且以下代码完美运行:
//PEAR
require_once('../PEAR/Mail.php');
$from = "<[email protected]>";
$to = "<[email protected]>";
$subject = "Hi";
$body = "Testing message";
$host = "ssl://smtp.gmail.com"; //ssl://
$port = "465";
$username = "[email protected]";
$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);
function &factory($driver, $params = array())
{
$driver = strtolower($driver);
@include_once 'Mail/' . $driver . '.php';
$class = 'Mail_' . $driver;
if (class_exists($class)) {
$mailer = new $class($params);
return $mailer;
} else {
return PEAR::raiseError('Unable to find class for driver ' . $driver);
}
}
if (PEAR::isError($mail)) {
echo("<p>" . $mail->getMessage() . "</p>");
} else {
echo("<p>Message successfully sent!</p>");
}
//end of php tag
但是,当我将文件上传到在线网络服务器并运行时完全相同的脚本我收到以下错误:
“无法连接到 ssl://smtp.gmail.com:465 [SMTP:无法连接套接字:连接被拒绝(代码:-1,响应:)]”
我也有尝试过端口 587 和 443 无济于事。我猜问题一定出在socket.php、smtp.php、mail.php 甚至服务器配置文件上,因为上面的代码似乎没有任何问题。如果有人能指出我正确的方向,我将非常感激!
I'm having endless trouble while trying to send mail using the pear mail package:
I'm using xampp on my local machine for testing purposes and the following code works perfectly:
//PEAR
require_once('../PEAR/Mail.php');
$from = "<[email protected]>";
$to = "<[email protected]>";
$subject = "Hi";
$body = "Testing message";
$host = "ssl://smtp.gmail.com"; //ssl://
$port = "465";
$username = "[email protected]";
$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);
function &factory($driver, $params = array())
{
$driver = strtolower($driver);
@include_once 'Mail/' . $driver . '.php';
$class = 'Mail_' . $driver;
if (class_exists($class)) {
$mailer = new $class($params);
return $mailer;
} else {
return PEAR::raiseError('Unable to find class for driver ' . $driver);
}
}
if (PEAR::isError($mail)) {
echo("<p>" . $mail->getMessage() . "</p>");
} else {
echo("<p>Message successfully sent!</p>");
}
//end of php tag
HOWEVER, when I upload the file to the online web server and run the exact same script I receive the following error:
"Failed to connect to ssl://smtp.gmail.com:465 [SMTP: Failed to connect socket: Connection refused (code: -1, response: )]"
I have also tried ports 587 and 443 to no avail. I'm guessing the problem must lie with either socket.php, smtp.php, mail.php or even with the server config files since there seems to be nothing wrong with the above code. I would be extremely grateful if someone could point me in the right direction!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
连接被 Google 拒绝,因为您需要在“Mail::factory”调用中指定“localhost”参数,如下面的代码所示:
然后电子邮件应该可以正常发送!我遇到过托管提供商,不需要提供“localhost”参数,但对于其他提供商来说,似乎是必需的,即使官方 PEAR 文档将其列为可选...
Connection is refused by Google because you need to specify the "localhost" parameter in "Mail::factory" call as shown in the code below:
Then the email should go through just fine! I have encountered hosting providers where it wasn't necessary to provide the "localhost" parameter but with others it seems to be required even though the official PEAR documentation lists it as optional...
是的,因为您的主机可能不支持 ssl 连接。
向您的主机询问 php_openssl 支持。或者您可以手动尝试以下加载 dll。
如果(dl(php_openssl.so))
或者
if(dl(php_openssl.dll))
这是一般错误,因为扩展名=php_openssl.dll 文件在服务器上未取消注释。
Ya because your host may not support ssl connection.
Ask your host for php_openssl support. Or either you can manually try the following to load dll.
if(dl(php_openssl.so))
or
if(dl(php_openssl.dll))
this is general error because of extension=php_openssl.dll file is not uncommented on server.