我正在尝试使用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('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';
}
感谢我能得到的任何帮助。谢谢!
答案 0 :(得分:0)
sending email in CodeIgniter through gmail
请同时检查您是否在php.ini中找到了未注释的extension = php_openssl.dll