2014-07-25 48 views
0

我已经在cpanelshared 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); 
} 
+0

难道托管服务提供商告诉你,你需要改变你的临时目录中哪个目录? – lowerends

+0

@lowerends no,但新的临时目录的权限是755 – MTVS

+0

你可以调试当前设置的TMPDIR吗?你可以使用'dd($ _ ENV ['TMPDIR'])'。 – lowerends

回答

1

您需要检查目录是否可以通过尝试写入目录的进程写入。您可以验证其用户和组是由您的过程执行:

<?php 
    echo getmyuid().':'.getmygid(); 
?> 

这会给你像user:group。然后,你需要chown目录写入用:

chown -R user:group writable_directory/ 
相关问题