Hi, i was trying this class on loacalhost and it works but if i put the class on a domain, it doesn't anymore. I'm pretty sure that my error is calling $email_message->localhost= with the wrong parameter. This is the message i got:
Errore: could not connect to the host "smtp.gmail.com": Connection timed out

I've been trying with localhost (silly), $_SERVER['SERVER_ADDR'] (same error message), $_SERVER['HTTP_HOST'] (still the same error). All is still working on localhost with: $email_message->localhost="localhost"

If someone knows the answer to this problem, please POST it! Thanks to all

The localhost parameter is irrelevant in your case because it is only used to after you connect to the SMTP server but it seems you are not even able to connect.

It is very likely that your network has the outgoing SMTP port blocked. For Gmail you need to use port 465 or 587. Just try one or the other. Also make sure that the timeout variable is set to a large enough value.

If nothing works and it always results in a connection timeout error, ask your system administrator if is there any firewall, anti-virus, proxy blocking connections to both ports 465 and 587.