英文:
GMAIL SMTP Connect Fails On Server But Works On Local
问题
I am using the Chilkat library to send email. It works perfectly on my local server/PC, but on the live server, it fails to connect to SMTP.
I've tried both SSL and TLS ports (465/587), but both fail with the same error message.
Here is the relevant part of the 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>
<!-- ... (log details) ... -->
<error>Failed.</error>
</SmtpConnect>
</ChilkatLog>
I've consulted with server tech, and they confirmed that all ports (465, 587, 25) are open. However, it's not working on the Linux server with Plex.
英文:
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
答案1
得分: 1
无论你的服务器技术如何说,你都应该验证端口是否开放,并至少排除一个可能性。
以下是一个简单的脚本,尝试通过各种端口连接,并为每个端口返回成功或错误消息。
<?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>尝试连接到 <tt>$server:$port</tt></h1>\n";
flush();
$socket = fsockopen($server, $port, $errno, $errstr, 10);
if(!$socket) {
echo "<p>错误:$server:$port - $errstr ($errno)</p>\n";
} else {
echo "<p>成功:$server:$port - 正常</p>\n";
}
flush();
}
?>
英文:
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();
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论