我正在尝试使用 Pear Mail 向 gmail 发送电子邮件,但出现错误:
Failed to connect to ssl://smtp.gmail.com:465 [SMTP: Failed to connect socket:
Unable to find the socket transport "ssl" - did you forget to enable it when you
configured PHP? (code: -1, response: )]
这是我的代码:
<?php
require_once 'Mail.php';
$from = "username@gmail.com";
$to = "username@domain.com";
$subject = "Subject";
$body = "Hello!";
$host = "ssl://smtp.gmail.com";
$port = "465";
$username = "username@gmail.com";
$password = "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 $mail->getMessage();
} else {
echo "Message sent successfully!";
}
?>
我已经阅读了与我的相同问题的几乎所有内容,我尝试了 phpmailer,但我发现它很难,我尝试删除在 php.ini 上找到的关于 extension=php_openssl.dll 的评论,重新启动 apache,将 465 更改为 587 左右和没运气!Windows 防火墙未打开。我究竟做错了什么?请帮忙!
谢谢!