无法与主机www.example.com建立连接smtp.gmail.com[找不到套接字传输“ssl”

oyxsuwqo  于 2022-11-24  发布在  其他
关注(0)|答案(1)|浏览(209)

我尝试使用本地主机发送SwiftMailer邮件。但是我一直收到错误消息:

560:tid 1472] [client ::1:65504] PHP Fatal error:  Uncaught exception 'Swift_TransportException' with message 'Connection could not be established with host smtp.gmail.com [Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP? #166044768]'

我已经看了一下stackoverflow和它的相关问题,我已经将端口改为465和587,并进入php.ini文件,删除了分号(;)从

extension=php_openssl.dll

然而,当我尝试运行我的代码时,我仍然得到上面提到的错误。
我的代码:

require_once '../lib/swift_required.php';

$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, 'ssl')
    ->setUsername('mymail@gmail.com')
    ->setPassword('password');

$mailer = Swift_Mailer::newInstance($transport);
$message = Swift_Message::newInstance()
    ->setSubject('Localhost email test')
    ->setFrom(array('mymail@gmail.com' => 'test'))
    ->setTo(array('testmail@hotmail.com' => 'receiver'))
    ->setBody('This is a test message');

if ($mailer->send($message)) {
    echo 'The message was sent successfully!';

} else {
    echo 'Error sending email message';
}

我会很感激任何能得到的帮助。谢谢!

相关问题