Question

I am trying to use PHPMailer to send emails from my website.

Trying it locally on my PC, everything goes fine.

 SERVER -> CLIENT: 220 mail.xxx.it Microsoft ESMTP MAIL Service, Version: 6.0.3790.4675 ready at Sun, 26 Jan 2014 17:48:16 +0100 
CLIENT -> SERVER: EHLO localhost
SERVER -> CLIENT: 250-mail.xxx.it Hello [151.16.96.254]250-TURN250-SIZE250-ETRN250-PIPELINING250-DSN250-ENHANCEDSTATUSCODES250-8bitmime250-BINARYMIME250-CHUNKING250-VRFY250-X-EXPS GSSAPI NTLM LOGIN250-X-EXPS=LOGIN250-AUTH GSSAPI NTLM LOGIN250-AUTH=LOGIN250-X-LINK2STATE250-XEXCH50250 OK
CLIENT -> SERVER: MAIL FROM:<cantina@xxx.it>
SERVER -> CLIENT: 250 2.1.0 cantina@xxx.it....Sender OK
CLIENT -> SERVER: RCPT TO:<cantina@xxx.it>
SERVER -> CLIENT: 250 2.1.5 cantina@xxx.it 
CLIENT -> SERVER: DATA
SERVER -> CLIENT: 354 Start mail input; end with <CRLF>.<CRLF>
CLIENT -> SERVER: Date: Sun, 26 Jan 2014 16:48:16 +0000
CLIENT -> SERVER: Return-Path: <cantina@xxx.it>
CLIENT -> SERVER: To: Cantina <cantina@xxx.it>
CLIENT -> SERVER: From: Cantina<cantina@xxx.it>
CLIENT -> SERVER: Reply-To: Cantina <cantina@xxx.it>
CLIENT -> SERVER: Subject: PHPMailer Mail SMTP test
CLIENT -> SERVER: Message-ID: <7ce374d41e4d33734ece535a61122792@localhost>
CLIENT -> SERVER: X-Priority: 3
CLIENT -> SERVER: X-Mailer: PHPMailer 5.2.7 (https://github.com/PHPMailer/PHPMailer/)
CLIENT -> SERVER: MIME-Version: 1.0
CLIENT -> SERVER: Content-Type: multipart/alternative;
CLIENT -> SERVER: boundary="b1_7ce374d41e4d33734ece535a61122792"
...    
SERVER -> CLIENT: 250 2.6.0 <7ce374d41e4d33734ece535a61122792@localhost> Queued mail for delivery
CLIENT -> SERVER: QUIT
SERVER -> CLIENT: 221 2.0.0 mail.xxx.it Service closing transmission channel
Message sent!

While when I move my PHP file to the webserver on the hosting provider.

SMTP ERROR: Failed to connect to server: Connection timed out (110)
SMTP connect() failed.
Mailer Error: SMTP connect() failed.

The SMTP is responsing on standard 25 non authenticated.

Any hint on how to go further on the understanding on why it happens. I would start by pinging the machine, I don't know if it could be done via PHP.

Thank you

Was it helpful?

Solution

Yes you can ping with php, here's an example:

function ping($host, $port, $timeout) { 
  $tB = microtime(true); 
  $fP = fSockOpen($host, $port, $errno, $errstr, $timeout); 
  if (!$fP) { return "down"; } 
  $tA = microtime(true); 
  return round((($tA - $tB) * 1000), 0)." ms"; 
}

//Echoing it will display the ping if the host is up, if not it'll say "down".
echo ping("xxx.it", 25, 10);

I'm sure this isn't enough to solve your problem but it will, at least, help you to determine if you can connect to the remote serve before continuing with the rest of the script.
You should also consider that the remote server maybe be blocking connections for your host.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top