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

问题描述 投票:0回答:1

我正在尝试使用localhost向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('[email protected]')
    ->setPassword('password');

$mailer = Swift_Mailer::newInstance($transport);
$message = Swift_Message::newInstance()
    ->setSubject('Localhost email test')
    ->setFrom(array('[email protected]' => 'test'))
    ->setTo(array('[email protected]' => 'receiver'))
    ->setBody('This is a test message');

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

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

非常感谢我能得到的任何帮助。谢谢!

php email ssl gmail swiftmailer
1个回答
0
投票

sending email in CodeIgniter through gmail

另请检查php.ini中是否有未注释的extension = php_openssl.dll

© www.soinside.com 2019 - 2024. All rights reserved.