diff --git a/htdocs/lib/CMailFile.class.php b/htdocs/lib/CMailFile.class.php
index 66ec234aaa93df97fd7c87d9482fc04803448bd8..5897bda5ad5028cc6f0f8f302e54f7ce08649981 100644
--- a/htdocs/lib/CMailFile.class.php
+++ b/htdocs/lib/CMailFile.class.php
@@ -254,13 +254,15 @@ class CMailFile
      */
     function send_to_file()
     {
-        $fp = fopen("/tmp/dolibarr_mail","w");
-        fputs($fp, $this->headers);
-        fputs($fp, $this->message);
-        fclose($fp);
+    	if (@is_writeable("/tmp"))	// Avoid fatal error on fopen with open_basedir
+    	{
+        	$fp = fopen("/tmp/dolibarr_mail","w");
+        	fputs($fp, $this->headers);
+        	fputs($fp, $this->message);
+        	fclose($fp);
+    	}
     }
 
-
     /**
             \brief		Creation des headers smtp
     */