【发布时间】: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