Franc
Franc

Reputation: 67

error with swiftmailer

I'm trying to add a contact form to my website. In localhost it worked fine, now moving on Tiscali server I'm getting this error:

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`

Fatal error: 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`

Parameter I'm using:

 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 

Upvotes: 1

Views: 3073

Answers (2)

MonocroM
MonocroM

Reputation: 1049

The solution of symcbean works fine for me beside one point a had to use putenv() in order to be able to modify the environment variables.

so i wrote sth like:

<?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';
[..]

Upvotes: 0

symcbean
symcbean

Reputation: 48357

This is rare - a reported error sending mail from PHP which is nothing to do with the MTA!

Swiftmailer is trying to create a temporary file. Without digging through the source code, if it's sensibly written it should be using tmpnam() or tmpfile() which (except where explicitly overridden use the "system default temp dir". It determines this by looking at some environment variables - and if these are not present, then a compiled in default.

The directory used is also returned by the sys_get_temp_dir() function

(since swiftmailer goes on to try to send a file which it failed to create implies a rather silly bug in its code).

Really it's the responsibility of whoever set the open_basedir restrictions to ensure that the rest of the PHP settings are configured correctly (session save path, temp dir and others). I'd complain to them to get it fixed properly.

In the meantime try inserting

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

at the top of your script and create the relevant directory, making it writeable by the webserver.

Note that the same error message is described in the comments on the tmpfile() page.

Upvotes: 4

Related Questions