2012-04-05 110 views
1

我正在嘗試向我的網站添加一個聯繫表單。在本地主機它工作得很好,現在正在Tiscali公司的服務器上,我得到這個錯誤:swiftmailer錯誤

Warning: is_writable() [function.is-writable]: open_basedir restriction in effect.  
File(/tmp) is not within the allowed path(s): 
(/var/www/virtual/mydomain.it/:/usr/share/php/:/var/www/ispcp/gui/tools/filemanager/) in /var/www/virtual/mydomain.it/htdocs/prova-intro/Swift-4.1.6/lib/preferences.php on line 15` 

致命錯誤:Uncaught exception Swift_TransportException' with message

'Expected response code 220 but got code "554",

with message "554 santino.mail.tiscali.it ESMTP server not available from your IP "' in /var/www/virtual/mydomain.it/htdocs/prova-intro/Swift-4.1.6/lib/classes/Swift/Transport/AbstractSmtpTransport.php:422 Stack trace: #0 /var/www/virtual/mydomain.it/htdocs/prova-intro/Swift-4.1.6/lib/classes/Swift/Transport/AbstractSmtpTransport.php(315):` 
Swift_Transport_AbstractSmtpTransport->_assertResponseCode('554 santino.mai...', Array) 

#1 /var/www/virtual/mydomain.it/htdocs/prova-intro/Swift-4.1.6/lib/classes/Swift/Transport/AbstractSmtpTransport.php(123): Swift_Transport_AbstractSmtpTransport->_readGreeting() 
#2 /var/www/virtual/mydomain.it/htdocs/prova-intro/Swift-4.1.6/lib/classes/Swift/Mailer.php(79): Swift_Transport_AbstractSmtpTransport->start() 

#3 /var/www/virtual/mydomain.it/htdocs/prova-intro/mail_SwiftMailer.php(129): Swift_Mailer->send(Object(Swift_Message) in /var/www/virtual/mydomain.it/htdocs/prova-intro/Swift-4.1.6/lib/classes/Swift/Transport/AbstractSmtpTransport.php on line 422` 

參數我使用:

define('HOST_SMTP', 'smtp.mydomain.it'); 
define('PORT_SMTP', 465); 
define('SECUTITY_SMTP', ssl); 
define('EMAIL_SMTP', '[email protected]'); 
define('PASSWORD_SMTP', 'xxxxxxx'); 
define('EMAIL_DESTINATARIO', $_POST['destinatario']); 
define('MAX_DIM_FILE', 1048576); // 1mb 
+0

對於您的錯誤信息,它看起來S形W​​eb服務器的機器是無法通信的SMTP服務器。我不認爲它是swiftmailer的錯,但是與你的Web服務器的機器或者SMTP服務器的配置有關。 – F21 2012-04-05 10:09:50

回答

4

This很少見 - 從PHP發送郵件的錯誤與MTA無關!

Swiftmailer正試圖創建一個臨時文件。如果沒有深入瞭解源代碼,如果明智地寫了它,應該使用tmpnam()或tmpfile()(除非顯式覆蓋使用「系統默認臨時目錄」),它通過查看一些環境變量來確定 - 如果這些不存在,那麼在默認的編譯。

使用也由sys_get_temp_dir()函數返回的目錄

(因爲swiftmailer接着嘗試發送其未能創造意味着在一個相當愚蠢的錯誤文件它的代碼)

真的,這是誰設置open_basedir限制,以確保其餘的PHP設置配置c (會話保存路徑,臨時目錄等)。我會抱怨他們正確地修復它。

在此期間嘗試在你的腳本的頂部插入

$_ENV['TMPDIR']='/var/www/virtual/mydomain.it/tmp'; 
$_ENV['TMP']=$_ENV['TMPDIR']; 

,並創建相關目錄,使其可寫,則由服務器。

請注意,同樣的錯誤消息是在tmpfile()頁面上的described in the comments

+0

我無法解決問題。獲取相同的錯誤。我將要求我的提供商解決這些限制。感謝您的幫助 – Franc 2012-04-05 15:42:23

0

symcbean的解決方案對我來說很好,除了一點之外必須使用putenv()才能修改環境變量。

所以我寫了某事,如:

<?php 
// web/app_dev.php 
// in prod the warning should not raise an exception, 
// but this depends on the error handling 

use [..] 

$tmpDir = __DIR__.'/../app/cache'; 

putenv('TMP='.$tmpDir); 
putenv('TMPDIR='.$tmpDir); 
putenv('TEMP='.$tmpDir); 

$loader = require_once __DIR__.'/../app/bootstrap.php.cache'; 
[..]