Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams require_once "lib/Swift.php"; require_once "lib/Swift/Connection/SMTP.php"; $smtp =& new Swift_Connection_SMTP("mail.somedomain.net", 587); $smtp->setUsername("username"); $smtp->setpassword("password"); $swift =& new Swift($smtp); //Create the sender from the details we've been given $sender =& new Swift_Address($email, $name); $message =& new Swift_Message("message title"); $message->attach(new Swift_Message_Part("Hello")); //Try sending the email $sent = $swift->send($message, "$myEmail", $sender); //Disconnect from SMTP, we're done $swift->disconnect(); if($sent) print 'sent'; print 'not sent'; catch (Exception $e) echo"$e";

The issue is that it is working fine on my local server (which my xampp server) but not working when the file is uploaded on the real server.

It throwing this error:

'The SMTP connection failed to start [mail.somedomain.net:587]: fsockopen returned Error Number 110 and Error String 'Connection timed out''

Please what should I do to correct this error. Thanks for reading

Thanks, my hostname is correct as everything works fine while the script is still on my computer (local apache server). Any suggestion please? – Selom Apr 7, 2010 at 21:48 Thanks for answering, the domain is valid and it works when the script file is still on my local apache server. I also tried to ping the server domain using ping mail.somedomain.com, il works perfectly. Please i need some ideas. thanks for reading and answering. – Selom Apr 7, 2010 at 21:02

is that '587' the port number to connect to? Any reason you're trying that instead of the normal port 25? Port 587 (submission) is normally used for local users to send mail. Once you're running this script on your remote web server, it's no longer "local", and is most likely firewalled off (or the mail server's not listening to that port on external interfaces).

Try switching to port 25 and see if that helps any.

update:

Connection refused is better than "connection timed out". It means at least that the initial data packet got somewhere and was actively refused. Timed out means things just got dropped silently somewhere en-route.

max_execution_time would only come into play if the php script itself went over the max time. If that was the case, you wouldn't be getting a swiftmailer error, because the script would have simply terminated.

Is your webserver running sendmail? Change the connection host to 'localhost' and see if that helps. If you just want to send an email, then that should work. The only reason you might want to connect to a remote SMTP server is for the From: headers to be correctly set and not be possibly flagged as SPAM on the receving end.

thanks for answering, I tried the port 25 and I have this message: 'The SMTP connection failed to start [mail.somedomain.net:25]:fsockopen returned Error Number 111 and Error String 'Connection refused'' I think the problem might be from the server configuration as the same script works fine on my local apache server when I use the same smtp server domain detail. I runned the phpinfo and the only thing i could notice was that the max_execution_time is set to 30 on the server but set to 60 on my local apache server. Any idea please – Selom Apr 7, 2010 at 23:26

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.