我已經在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