I am using chilkat library to send email, it works perfectly on my local server/pc, but on live server it fails on smtp connect.
I tried both SSL and tls port.. (465/587) but both fails with same kind of error message..
following is the part of code to connect to google smtp server
//init
$smtp = new CkMailMan();
$smtp->put_VerboseLogging(true);
$smtp->put_SmtpHost('smtp.gmail.com');
$smtp->put_SmtpPort(465);
$smtp->put_SmtpSsl(true);
//connect
if(!$smtp->SmtpConnect())
{
file_put_contents('./log/smtp_error_' . $GLOBALS['unixTime'] . '.log', $smtp->lastErrorXml());
unset($smtp);
echo '!failed!';
exit();
}
and here is the log file:
<ChilkatLog>
<SmtpConnect ms="30066">
<DllDate>Jun 25 2022</DllDate>
<ChilkatVersion>9.5.0.91</ChilkatVersion>
<UnlockPrefix>NONE</UnlockPrefix>
<Architecture>Little Endian; 64-bit</Architecture>
<Language>Linux PHP</Language>
<VerboseLogging>1</VerboseLogging>
<ensureSmtpConnection ms="30066">
<smtpParams>
<SmtpHost>smtp.gmail.com</SmtpHost>
<SmtpPort>465</SmtpPort>
<SmtpUsername></SmtpUsername>
<SmtpSsl>1</SmtpSsl>
<StartTLS>0</StartTLS>
</smtpParams>
<smtpConnect ms="30066">
<smtpHostname>smtp.gmail.com</smtpHostname>
<smtpPort>465</smtpPort>
<connectionIsReady>
<info>SMTP host changed.</info>
<info>SMTP port changed.</info>
<info>Need new SMTP connection, something changed!</info>
</connectionIsReady>
<smtpSocketConnect ms="30066">
<socket2Connect ms="30066">
<connect2 ms="30066">
<hostname>smtp.gmail.com</hostname>
<port>465</port>
<ssl>True</ssl>
<connectImplicitSsl ms="30066">
<info>Clearing TLS client certificates.</info>
<connectSocket ms="30066">
<domainOrIpAddress>smtp.gmail.com</domainOrIpAddress>
<port>465</port>
<connectTimeoutMs>30000</connectTimeoutMs>
<connect_ipv6_or_ipv4 ms="30066">
<info>Single-threaded domain to IP address resolution</info>
<info>connecting to IPV4 address...</info>
<ipAddress>172.253.115.108</ipAddress>
<createSocket>
<info>Setting SO_SNDBUF size</info>
<sendBufSize>262144</sendBufSize>
<info>Setting SO_RCVBUF size</info>
<recvBufSize>4194304</recvBufSize>
</createSocket>
<connect ms="30065">
<info>Waiting for the connect to complete...</info>
<connectTimeoutMs>30000</connectTimeoutMs>
<error>timeout waiting for connect to complete;</error>
<timeoutMs>30000</timeoutMs>
<failedWaitToConnect>Socket operation timeout.</failedWaitToConnect>
</connect>
</connect_ipv6_or_ipv4>
</connectSocket>
<error>pmConnect failed.</error>
</connectImplicitSsl>
<connectFailReason>6</connectFailReason>
<ConnectFailReason>Timeout</ConnectFailReason>
<error>A few possible causes for a connection timeout are:</error>
<error>- The remote host is not reachable (perhaps a firewall is blocking the connection on the remote end).</error>
<error>- Your ISP is blocking the outbound connection (this is common for SMTP port 25).</error>
<error>- If your timeout is too short, then maybe the server is just too slow to accept the connection.</error>
</connect2>
</socket2Connect>
<error>Failed to connect to SMTP server..</error>
</smtpSocketConnect>
</smtpConnect>
</ensureSmtpConnection>
<error>Failed.</error>
</SmtpConnect>
</ChilkatLog>
i have consulted with server tech and they said, all the port 465,587,25 all is open.
so, i am so confused why it is not working?
info: it's linux server with plex
Regardless of what your server tech says, you should validate that the ports are open and eliminate at least one of the possibilities.
Here's a simple script that attempts to connect through various ports, and returns a SUCCESS or ERROR message for each.
<?php
$servers = array(
array("ssl://www.google.com", 443),
array("smtp.gmail.com", 465),
array("smtp.gmail.com", 587),
);
foreach ($servers as $server) {
list($server, $port) = $server;
echo "<h1>Attempting connect to <tt>$server:$port</tt></h1>\n";
flush();
$socket = fsockopen($server, $port, $errno, $errstr, 10);
if(!$socket) {
echo "<p>ERROR: $server:$portsmtp - $errstr ($errno)</p>\n";
} else {
echo "<p>SUCCESS: $server:$port - ok</p>\n";
}
flush();
}