我正在尝试使用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防火墙未启用。我究竟做错了什么?请帮忙!
谢谢!
答案 0 :(得分:1)
这个已经在工作了!对不起,我编辑了错误的php.in文件;它应该是bin文件夹中的一个。