【问题标题】:'Connection could not be established with host smtp.gmail.com [Unable to find the socket transport "ssl"'无法与主机 smtp.gmail.com 建立连接 [无法找到套接字传输“ssl”
【发布时间】:2014-01-18 10:01:15
【问题描述】:

我正在尝试使用本地主机通过 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';
}

如果我能得到任何帮助,我将不胜感激。谢谢!

【问题讨论】:

  • 您确定您编辑了正确的php.ini 文件吗?检查var_dump(php_ini_loaded_file()); 的输出并确保您正在编辑该文件。

标签: php email ssl gmail swiftmailer


【解决方案1】:

sending email in CodeIgniter through gmail

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

【讨论】:

    猜你喜欢
    • 2020-11-03
    • 1970-01-01
    • 1970-01-01
    • 2019-03-01
    • 2012-12-20
    • 2018-07-03
    • 2016-02-07
    • 2021-01-04
    • 2015-02-27
    相关资源
    最近更新 更多