我已经在cpanel
shared host
上部署了laravel
应用程序。带有'fopen(/ tmp/...)消息的SwiftMailer'ErrorException'无法打开流:权限被拒绝'
当发送电子邮件使用Mail
类时,随机发生以下错误。 (有时邮件被发送,但有时会出现错误)
production.ERROR: exception 'ErrorException' with message 'fopen(/tmp/e19839f1a2d67e4ab7c83a5951c31bfd/body): failed to open stream: Permission denied' in /home/ekbatana/laravel4/vendor/swiftmailer/swiftmailer/lib/classes/Swift/KeyCache/DiskKeyCache.php:300
我联系了主机支持,他们说我需要更改默认的临时目录。
在SwiftMailer包lib/preferences.php
一个名为$tmp
变量设置为getenv('TMPDIR')
,并在文件中评论说:
// You can override the default temporary directory by setting the TMPDIR environment variable.
我试图设置TMPDIR
以不同的方式
1)的.htaccess: SetEnv TMPDIR /home/.../laravel4/app/storage/my_temp
2)in app/start/global.php
and还in App::before
回调函数使用php putenv
函数
3)lib/preferences.php
之前使用php putenv
功能
但其中不改变到被打开,导致failed to open stream: Permission denied
错误
以下文件的路径是swiftmailer/lib/preferences.php
<?php
/****************************************************************************/
/* */
/* YOU MAY WISH TO MODIFY OR REMOVE THE FOLLOWING LINES WHICH SET DEFAULTS */
/* */
/****************************************************************************/
$preferences = Swift_Preferences::getInstance();
// Sets the default charset so that setCharset() is not needed elsewhere
$preferences->setCharset('utf-8');
// Without these lines the default caching mechanism is "array" but this uses a lot of memory.
// If possible, use a disk cache to enable attaching large attachments etc.
// You can override the default temporary directory by setting the TMPDIR environment variable.
// The @ operator in front of is_writable calls is to avoid PHP warnings
// when using open_basedir
$tmp = getenv('TMPDIR');
if ($tmp && @is_writable($tmp)) {
$preferences
->setTempDir($tmp)
->setCacheType('disk');
} elseif (function_exists('sys_get_temp_dir') && @is_writable(sys_get_temp_dir())) {
$preferences
->setTempDir(sys_get_temp_dir())
->setCacheType('disk');
}
// this should only be done when Swiftmailer won't use the native QP content encoder
// see mime_deps.php
if (version_compare(phpversion(), '5.4.7', '<')) {
$preferences->setQPDotEscape(false);
}
难道托管服务提供商告诉你,你需要改变你的临时目录中哪个目录? – lowerends
@lowerends no,但新的临时目录的权限是755 – MTVS
你可以调试当前设置的TMPDIR吗?你可以使用'dd($ _ ENV ['TMPDIR'])'。 – lowerends