尝试使用 CakePHP 2.3.0 发送电子邮件时收到该错误 我的云配置是:
对不起我的英语。
2013-03-06 09:15:05 Error: [SocketException] Permission denied
Request URL: /notifications/sendContact
Stack Trace:
#0 /var/www/html/site/lib/Cake/Network/Email/SmtpTransport.php(96): CakeSocket->connect()
#1 /var/www/html/site/lib/Cake/Network/Email/SmtpTransport.php(60): SmtpTransport->_connect()
#2 /var/www/html/site/lib/Cake/Network/Email/CakeEmail.php(1065): SmtpTransport->send(Object(CakeEmail))
#3 /var/www/html/site/app/Controller/NotificationsController.php(41): CakeEmail->send()
#4 [internal function]: NotificationsController->sendContact()
#5 /var/www/html/site/lib/Cake/Controller/Controller.php(485): ReflectionMethod->invokeArgs(Object(NotificationsController), Array)
#6 /var/www/html/site/lib/Cake/Routing/Dispatcher.php(186): Controller->invokeAction(Object(CakeRequest))
#7 /var/www/html/site/lib/Cake/Routing/Dispatcher.php(161): Dispatcher->_invoke(Object(NotificationsController), Object(CakeRequest), Object(CakeResponse))
#8 /var/www/html/site/app/webroot/index.php(102): Dispatcher->dispatch(Object(CakeRequest), Object(CakeResponse))
#9 {main}
2013-03-06 09:15:05 Error: Fatal Error (256): [CakeException] Unknown status code
#0 /var/www/html/site/lib/Cake/Error/ExceptionRenderer.php(212): CakeResponse->statusCode(13)
#1 [internal function]: ExceptionRenderer->error400(Object(SocketException))
#2 /var/www/html/site/lib/Cake/Error/ExceptionRenderer.php(175): call_user_func_array(Array, Array)
#3 /var/www/html/site/lib/Cake/Error/ErrorHandler.php(122): ExceptionRenderer->render()
#4 [internal function]: ErrorHandler::handleException(Object(SocketException))
#5 {main} in [/var/www/html/site/lib/Cake/Error/ErrorHandler.php, line 131]
2013-03-06 09:15:05 Error: [InternalErrorException] Internal Server Error
Request URL: /notifications/sendContact
Stack Trace:
#0 /var/www/html/site/lib/Cake/Error/ErrorHandler.php(183): ErrorHandler::handleFatalError(256, '[CakeException]...', '/var/www/html/p...', 131)
#1 [internal function]: ErrorHandler::handleError(256, '[CakeException]...', '/var/www/html/p...', 131, Array)
#2 /var/www/html/site/lib/Cake/Error/ErrorHandler.php(131): trigger_error('[CakeException]...', 256)
#3 [internal function]: ErrorHandler::handleException(Object(SocketException))
#4 {main}
2013-03-06 09:15:05 Error: Fatal Error (256): [CakeException] Unknown status code
#0 /var/www/html/site/lib/Cake/Error/ExceptionRenderer.php(212): CakeResponse->statusCode(13)
#1 [internal function]: ExceptionRenderer->error400(Object(SocketException))
#2 /var/www/html/site/lib/Cake/Error/ExceptionRenderer.php(175): call_user_func_array(Array, Array)
#3 /var/www/html/site/lib/Cake/Error/ErrorHandler.php(122): ExceptionRenderer->render()
#4 [internal function]: ErrorHandler::handleException(Object(SocketException))
#5 {main} in [/var/www/html/site/lib/Cake/Error/ErrorHandler.php, line 131]
2013-03-06 09:15:05 Error: [InternalErrorException] Internal Server Error
Request URL: /notifications/sendContact
Stack Trace:
#0 /var/www/html/site/lib/Cake/Error/ErrorHandler.php(183): ErrorHandler::handleFatalError(256, '[CakeException]...', '/var/www/html/p...', 131)
#1 [internal function]: ErrorHandler::handleError(256, '[CakeException]...', '/var/www/html/p...', 131, Array)
#2 /var/www/html/site/lib/Cake/Core/App.php(926): call_user_func('ErrorHandler::h...', 256, '[CakeException]...', '/var/www/html/p...', 131, Array)
#3 /var/www/html/site/lib/Cake/Core/App.php(899): App::_checkFatalError()
#4 [internal function]: App::shutdown()
#5 {main}
public $gmail = array(
'transport' => 'Smtp',
'from' => array('patric.....@gmail.com' => 'Patrick Maciel'),
'port'=>'465',
'timeout'=>'30',
'auth' => true,
'host' => 'ssl://smtp.gmail.com',
'username'=>'patrick......@gmail.com',
'password'=>'.......',
'client' => null,
'log' => false
);
-bash-4.1# yum info php
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirror.globo.com
* epel: mirror.globo.com
* extras: mirror.globo.com
* updates: mirror.globo.com
Installed Packages
Name : php
Arch : i686
Version : 5.4.12
Release : 1.el6.remi
Size : 8.2 M
Repo : installed
From repo : remi
Summary : PHP scripting language for creating dynamic web sites
URL : http://www.php.net/
License : PHP and Zend and BSD
Description: PHP is an HTML-embedded scripting language. PHP attempts to make it
: easy for developers to write dynamically generated web pages. PHP also
: offers built-in database integration for several commercial and
: non-commercial database management systems, so writing a
: database-enabled webpage with PHP is fairly simple. The most common
: use of PHP coding is probably as a replacement for CGI scripts.
:
: The php package contains the module which adds support for the PHP
: language to Apache HTTP Server.
Available Packages
Name : php
Arch : i386
Version : 5.3.22
Release : 1.w5
Size : 1.3 M
Repo : webtatic
Summary : PHP scripting language for creating dynamic web sites
URL : http://www.php.net/
License : PHP
Description: PHP is an HTML-embedded scripting language. PHP attempts to make it
: easy for developers to write dynamically generated web pages. PHP also
: offers built-in database integration for several commercial and
: non-commercial database management systems, so writing a
: database-enabled webpage with PHP is fairly simple. The most common
: use of PHP coding is probably as a replacement for CGI scripts.
:
: The php package contains the module which adds support for the PHP
: language to Apache HTTP Server.
-bash-4.1# php -m
[PHP Modules]
bz2
calendar
Core
ctype
curl
date
dom
ereg
exif
fileinfo
filter
ftp
gd
gettext
gmp
hash
iconv
imap
intl
json
libxml
mbstring
mcrypt
memcache
mhash
mysql
mysqli
openssl
pcntl
pcre
PDO
pdo_mysql
pdo_sqlite
Phar
pspell
readline
recode
Reflection
session
shmop
SimpleXML
snmp
sockets
SPL
sqlite3
standard
tidy
tokenizer
wddx
xml
xmlreader
xmlrpc
xmlwriter
xsl
zip
zlib
[Zend Modules]
-bash-4.1#
答案 0 :(得分:2)
显然,您的PHP不允许连接到指定的SMTP服务器。您是否正确配置了电子邮件设置? (SMTP服务器,端口,用户名,密码等)。
这些设置的模板包含在CakePHP文件中:app / Config / email.php.default(https://github.com/cakephp/cakephp/blob/2.2.7/app/Config/email.php.default)
您需要将此文件复制到app/Config/email.php
并修改环境设置。
之后,您必须在发送电子邮件时指定正确的配置
手册中可以找到更全面的解释: http://book.cakephp.org/2.0/en/core-utility-libraries/email.html#configuration
另一个选择是SELinux安全位不允许PHP / Apache建立网络连接。
有几个安全位,但这似乎是一个可能的候选人:httpd_can_network_connect
。
您可以暂时允许PHP / Apache使用以下方式建立网络连接:
setsebool httpd_can_network_connect
使用-P
参数将设置设为“永久”;
setsebool -P httpd_can_network_connect
有关所有SELibux布尔值的概述;
答案 1 :(得分:1)
getsebool -a
检查 httpd_can_network_connect
如果关闭,请将其设置为
setsebool -P httpd_can_network_connect
对我有用!!