问题使用fsockopen()在两个VPS

时间:2016-03-02 11:59:20

标签: php centos vps fsockopen

我有两个虚拟专用服务器(VPS):Windows Server 2008 R2上的一个SMTP服务器,另一个是我在CentOS上的网站。问题是,当我尝试发送电子邮件时,并非所有电子邮件都被发送:可能是八个中的两个,有时是三个。但是,当我在我的本地机器上托管我的网站并使用fsockopen()时,它的工作完美。

以下是一个示例:

第1页:

<?php

include('SMTPconfig.php');
include('SMTPClass.php');

for ($i = 0; $i < 8; $i++) {
    $SMTPMail = new SMTPClient ($serv, $port, $user, $pass, $from, $to, $header, $subject, $body);
    $SMTPChat = $SMTPMail->SendMail();
}

SMTPconfig.php:

<?php

$SmtpServer = "XXX.XXX.XXX.XXX";
$SmtpPort = "port";
$SmtpUser = "admin";
$SmtpPass = "****";

SMTPClass.php

<?php

class SMTPClient
{
    function SMTPClient($SmtpServer, $SmtpPort, $SmtpUser, $SmtpPass, $from, $to, $a, $subject, $body)
    {
        $this->SmtpServer = $SmtpServer;
        $this->SmtpUser = base64_encode($SmtpUser);
        $this->SmtpPass = base64_encode($SmtpPass);
        $this->from = $from;
        $this->to = $to;
        $this->a = $a;
        $this->subject = $subject;
        $this->body = $body;
        if ($SmtpPort == "") {
            $this->PortSMTP = 25;
        } else {
            $this->PortSMTP = $SmtpPort;
        }
    }

    function SendMail()
    {
        if ($SMTPIN = fsockopen($this->SmtpServer, $this->PortSMTP, $errno, $errstr, 30)) {
            fputs($SMTPIN, "EHLO " . $_SERVER['HTTP_HOST'] . "\r\n");
            $talk["hello"] = fgets($SMTPIN, 1024);
            fputs($SMTPIN, "auth login\r\n");
            $talk["res"] = fgets($SMTPIN, 1024);
            fputs($SMTPIN, $this->SmtpUser . "\r\n");
            $talk["user"] = fgets($SMTPIN, 1024);
            fputs($SMTPIN, $this->SmtpPass . "\r\n");
            $talk["pass"] = fgets($SMTPIN, 256);
            fputs($SMTPIN, "MAIL FROM: <" . $this->from . ">\r\n");
            $talk["From"] = fgets($SMTPIN, 1024);
            fputs($SMTPIN, "RCPT TO: <" . $this->to . ">\r\n");
            $talk["To"] = fgets($SMTPIN, 1024);
            fputs($SMTPIN, "DATA\r\n");
            $talk["data"] = fgets($SMTPIN, 1024);
            fputs($SMTPIN, $this->a . "\r\n" . $this->body . "\r\n.\r\n");
            $talk["send"] = fgets($SMTPIN, 256);
            //CLOSE CONNECTION AND EXIT ...
            fputs($SMTPIN, "QUIT\r\n");
            fclose($SMTPIN);
            //
        } else echo $errstr;
        return $talk;
    }
}

请帮忙!我花了两天时间试图找到问题,但我找不到任何东西。谢谢!

0 个答案:

没有答案