PHP Classes

SMTP connection works on localhost but not on server

Recommend this page to a friend!

      SMTP E-mail sending class  >  All threads  >  SMTP connection works on localhost...  >  (Un) Subscribe thread alerts  
Subject:SMTP connection works on localhost...
Summary:SMTP connection works on localhost but not on server
Messages:9
Author:Adwait Pande
Date:2014-02-22 15:59:35
Update:2014-02-22 17:59:16
 

  1. SMTP connection works on localhost...   Reply   Report abuse  
Picture of Adwait Pande Adwait Pande - 2014-02-22 15:59:35
<?php
require("smtp.php");
require("sasl/sasl.php");


$from="abc@gmail.com"; $sender_line=__LINE__;
$to="xyz@gmail.com"; $recipient_line=__LINE__;

if(strlen($from)==0)
die("Please set the messages sender address in line ".$sender_line." of the script ".basename(__FILE__)."\n");
if(strlen($to)==0)
die("Please set the messages recipient address in line ".$recipient_line." of the script ".basename(__FILE__)."\n");

$smtp=new smtp_class;

$smtp->host_name="smtp.gmail.com";
$smtp->host_port=465;
$smtp->ssl=1;

$smtp->http_proxy_host_name='';
$smtp->http_proxy_host_port=3128;

$smtp->socks_host_name = '';
$smtp->socks_host_port = 1080;
$smtp->socks_version = '5';

$smtp->start_tls=0;
$smtp->localhost="localhost";
$smtp->direct_delivery=0;
$smtp->timeout=30;
$smtp->data_timeout=0;
$smtp->debug=1;
$smtp->html_debug=1;
$smtp->pop3_auth_host="";
$smtp->user="abc@gmail.com";
$smtp->realm="";
$smtp->password="xxxxxxxxxx";
$smtp->workstation="";

$smtp->authentication_mechanism="";

if($smtp->direct_delivery)
{
if(!function_exists("GetMXRR"))
{
$_NAMESERVERS=array();
include("getmxrr.php");
}
}

if($smtp->SendMessage(
$from,
array(
$to
),
array(
"From: $from",
"To: $to",
"Subject: Testing Manuel Lemos' SMTP class",
"Date: ".strftime("%a, %d %b %Y %H:%M:%S %Z")
),
"Hello $to,\n\nIt is just to let you know that your SMTP class is working just fine.\n\nBye.\n"))
echo "Message sent to $to OK.\n";
else
echo "Could not send the message to $to.\nError: ".$smtp->error."\n";
?>


This code works fine when I send mail from my local computer (XAMPP) but when I upload it to my domain, connection just times out and program haults.

Where am I doing it wrong?

  2. Re: SMTP connection works on localhost...   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2014-02-22 17:59:16 - In reply to message 1 from Adwait Pande
Very likely your hosting company is blocking socket connections to external servers. Just ask them to confirm if that is the case.

  3. Re: SMTP connection works on localhost...   Reply   Report abuse  
Picture of babak ghahremani babak ghahremani - 2016-04-18 03:46:08 - In reply to message 2 from Manuel Lemos
Hello
I have a same problem.
Error: could not connect to the host "send.one.com": Connection timed out
Technical team opened port 465 on the remote server but the timeout problem still exists...
Is it necessary that other ports are open on remote host?Such as 1080 or 3128?
Thanks for your help

  4. Re: SMTP connection works on localhost...   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2016-04-18 04:20:06 - In reply to message 3 from babak ghahremani
No, if they opened the port 465, you just need to change your code to use that port.

Other ports like 1080 or 3128 seem to be for proxies. If you use port 465 you do not need to use proxies.

  5. Re: SMTP connection works on localhost...   Reply   Report abuse  
Picture of babak ghahremani babak ghahremani - 2016-04-18 06:29:00 - In reply to message 4 from Manuel Lemos
Port 465 is open, but debug mode return timeout!
I really do not know what should I do?
I even closed the port 465 on localhost but smtpclass work correctly!!!
I think the problem is not 465 port.Because its open on my remote host.
can you check attach files(4files) if send to you?
these files work correctly on localhost!
my English is not good sir,Sorry!

  6. Re: SMTP connection works on localhost...   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2016-04-18 06:47:14 - In reply to message 5 from babak ghahremani
Maybe the timeout is too short and the remote server is taking too long.

Can you please enabled debugging and show the debug log output?

  7. Re: SMTP connection works on localhost...   Reply   Report abuse  
Picture of babak ghahremani babak ghahremani - 2016-04-18 07:12:31 - In reply to message 6 from Manuel Lemos
sure
Resolving SMTP server domain "send.one.com"...
Connecting to SMTP server "send.one.com" port 465...
Error: could not connect to the host "send.one.com": Connection timed out
$timeout=30;
and i checked it on 3 different remote servers with reasonable speed

  8. Re: SMTP connection works on localhost...   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2016-04-18 18:59:22 - In reply to message 7 from babak ghahremani
It does not seem that the port is really opened. I would double check that with your system administrator.

If you can go on the shell (maybe via ssh) of that server and try this command, you can be sure whether the port is blocked or not:

telnet send.one.com 465

  9. Re: SMTP connection works on localhost...   Reply   Report abuse  
Picture of babak ghahremani babak ghahremani - 2016-04-19 03:25:33 - In reply to message 8 from Manuel Lemos
thank you Mr Lemos