我正在使用CakePHP 3开发一个小型网页。它有一个非常简单的联系表单,使用来自1and1.es的SMTP服务器发送电子邮件。
这是我在config / app.php的传输配置:
'EmailTransport' => [
'smtp' => [
'className' => 'Smtp',
// The following keys are used in SMTP transports
'host' => 'smtp.1and1.es',
'port' => 587,
'timeout' => 30,
'username' => 'myuser@mydomain.es',
'password' => 'mypassword',
'client' => null,
'tls' => true,
'url' => env('EMAIL_TRANSPORT_DEFAULT_URL', null),
],
],
它在本地开发服务器上工作正常(Ubuntu 14.04上的Xampp):我收到所有电子邮件。但是,当使用相同的上述配置在生产服务器(1and1共享服务器)上时,它会引发500内部服务器错误。两台服务器上的PHP版本相同。
我在Stackoverflow上发现了类似的问题,但没有任何帮助。顺便说一句,我无法访问服务器中的apache错误日志。
任何帮助将不胜感激。提前谢谢。
修改
我刚刚发现Cakephp error.log文件有一些相关信息:
2016-10-09 22:18:38 Error: [Cake\Network\Exception\SocketException] Connection timed out
Request URL: /home/index
Referer URL: http://monitomolon.es/
Stack Trace:
#0 /homepages/14/d393557898/htdocs/monitomolon/vendor/cakephp/cakephp/src/Mailer/Transport/SmtpTransport.php(207): Cake\Network\Socket->connect()
#1 /homepages/14/d393557898/htdocs/monitomolon/vendor/cakephp/cakephp/src/Mailer/Transport/SmtpTransport.php(162): Cake\Mailer\Transport\SmtpTransport->_connect()
#2 /homepages/14/d393557898/htdocs/monitomolon/vendor/cakephp/cakephp/src/Mailer/Email.php(1344): Cake\Mailer\Transport\SmtpTransport->send(Object(Cake\Mailer\Email))
#3 /homepages/14/d393557898/htdocs/monitomolon/src/Form/ContactForm.php(56): Cake\Mailer\Email->send('Nombre: Diego A...')
#4 /homepages/14/d393557898/htdocs/monitomolon/vendor/cakephp/cakephp/src/Form/Form.php(179): App\Form\ContactForm->_execute(Array)
#5 /homepages/14/d393557898/htdocs/monitomolon/src/Controller/HomeController.php(13): Cake\Form\Form->execute(Array)
#6 [internal function]: App\Controller\HomeController->index()
#7 /homepages/14/d393557898/htdocs/monitomolon/vendor/cakephp/cakephp/src/Controller/Controller.php(435): call_user_func_array(Array, Array)
#8 /homepages/14/d393557898/htdocs/monitomolon/vendor/cakephp/cakephp/src/Http/ActionDispatcher.php(122): Cake\Controller\Controller->invokeAction()
#9 /homepages/14/d393557898/htdocs/monitomolon/vendor/cakephp/cakephp/src/Http/ActionDispatcher.php(96): Cake\Http\ActionDispatcher->_invoke(Object(App\Controller\HomeController))
#10 /homepages/14/d393557898/htdocs/monitomolon/vendor/cakephp/cakephp/src/Http/BaseApplication.php(83): Cake\Http\ActionDispatcher->dispatch(Object(Cake\Network\Request), Object(Cake\Network\Response))
#11 /homepages/14/d393557898/htdocs/monitomolon/vendor/cakephp/cakephp/src/Http/Runner.php(65): Cake\Http\BaseApplication->__invoke(Object(Zend\Diactoros\ServerRequest), Object(Zend\Diactoros\Response), Object(Cake\Http\Runner))
#12 /homepages/14/d393557898/htdocs/monitomolon/vendor/cakephp/cakephp/src/Routing/Middleware/RoutingMiddleware.php(53): Cake\Http\Runner->__invoke(Object(Zend\Diactoros\ServerRequest), Object(Zend\Diactoros\Response))
#13 /homepages/14/d393557898/htdocs/monitomolon/vendor/cakephp/cakephp/src/Http/Runner.php(65): Cake\Routing\Middleware\RoutingMiddleware->__invoke(Object(Zend\Diactoros\ServerRequest), Object(Zend\Diactoros\Response), Object(Cake\Http\Runner))
#14 /homepages/14/d393557898/htdocs/monitomolon/vendor/cakephp/cakephp/src/Routing/Middleware/AssetMiddleware.php(88): Cake\Http\Runner->__invoke(Object(Zend\Diactoros\ServerRequest), Object(Zend\Diactoros\Response))
#15 /homepages/14/d393557898/htdocs/monitomolon/vendor/cakephp/cakephp/src/Http/Runner.php(65): Cake\Routing\Middleware\AssetMiddleware->__invoke(Object(Zend\Diactoros\ServerRequest), Object(Zend\Diactoros\Response), Object(Cake\Http\Runner))
#16 /homepages/14/d393557898/htdocs/monitomolon/vendor/cakephp/cakephp/src/Error/Middleware/ErrorHandlerMiddleware.php(81): Cake\Http\Runner->__invoke(Object(Zend\Diactoros\ServerRequest), Object(Zend\Diactoros\Response))
#17 /homepages/14/d393557898/htdocs/monitomolon/vendor/cakephp/cakephp/src/Http/Runner.php(65): Cake\Error\Middleware\ErrorHandlerMiddleware->__invoke(Object(Zend\Diactoros\ServerRequest), Object(Zend\Diactoros\Response), Object(Cake\Http\Runner))
#18 /homepages/14/d393557898/htdocs/monitomolon/vendor/cakephp/cakephp/src/Http/Runner.php(51): Cake\Http\Runner->__invoke(Object(Zend\Diactoros\ServerRequest), Object(Zend\Diactoros\Response))
#19 /homepages/14/d393557898/htdocs/monitomolon/vendor/cakephp/cakephp/src/Http/Server.php(92): Cake\Http\Runner->run(Object(Cake\Http\MiddlewareQueue), Object(Zend\Diactoros\ServerRequest), Object(Zend\Diactoros\Response))
#20 /homepages/14/d393557898/htdocs/monitomolon/webroot/index.php(37): Cake\Http\Server->run()
#21 {main}
答案 0 :(得分:0)
嗯,1和1.es客户服务通知我,smtp服务器仅供电子邮件客户端使用,因此在我的共享服务器中禁止在脚本中使用它。所以,我通过使用本机PHP函数mail()和默认的CakePHP传输解决了这个问题。以这种方式简单定义EmailTransport
:
'EmailTransport' => [
'mail' => [
'className' => 'Mail',
],
],