2

尝试使用CakePHP 2.3.0发送电子邮件时收到该错误。
我的云配置是:

  • PHP 5.4
  • 阿帕奇 2.2
  • MySQL 5.5
  • 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}

电子邮件.php

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
);

php 信息 (centOs)

-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#
4

2 回答 2

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 布尔值的概述;

http://wiki.centos.org/TipsAndTricks/SelinuxBooleans

于 2013-03-06T12:45:34.423 回答
1

getebool -a

检查httpd_can_network_connect

如果关闭,请将其设置为开启

setsebool -P httpd_can_network_connect on

这个对我有用 !!

于 2014-10-20T10:06:06.250 回答