【问题标题】:PHP Communication with SmtpPHP 与 SMTP 通信
【发布时间】:2015-04-16 07:44:24
【问题描述】:

我有一个邮件应用程序,每天通过 cron 作业发送大约 5000 封电子邮件(大量的帐户文书工作),并且当邮件只发送给一个收件人时工作正常问题出现在我们激活密件抄送时,然后应用程序开始发送直到 980-1050 邮件并开始从 smtp 收到 4.5.3 错误(收件人太多)。如果我暂停作业并再次运行 cron,php 进程会得到一个新的 pid,并开始发送 ok,直到达到相同的限制(980-1050 封邮件);

所以我的问题是:有没有办法重新生成 php 进程 ID?

如果我能够做到这一点,那么应用程序将毫无问题地发送这些邮件。

或者我可能缺少一些后缀配置?

相关部分代码:

/**
* _Send_SmtpData
* Handles the SMTP negotiation for sending the email header and body.
*
* @param String $rcpt_to The 'receipt to' address to send the email to. This is a bare email address only.
* @param String $to The 'to' address to send this to. This can contain a name / email address in the standard format ("Name" <email@address>)
* @param String $subject The subject of the email to send.
* @param String $body The body of the email to send.
* @param String $headers The headers of the email to send.
**/ 

function _Send_SmtpData(&$rcpt_to, &$to, &$subject, &$body, &$headers)
{

    $data = "DATA";

    $this->DebugMemUsage('Trying to put ' . $data);

    if (!$this->_Put_Smtp_Connection($data)) {
        $this->ErrorCode = 12;
        $this->ErrorCodeSMTPEnhanced = false;
        $this->Error = GetLang('UnableToSendEmail_Data');
        $this->_Close_Smtp_Connection();

        $this->DebugMemUsage('Got error ' . $this->Error);

        return array(false, $this->Error);
    }

    $response = $this->_get_response();

    $this->DebugMemUsage('Got response ' . $response);

    $responsecode = substr($response, 0, 3);

    if ($responsecode != '354') {
        $this->ErrorCode = $responsecode;
        $this->ErrorCodeSMTPEnhanced = $this->_GetSMTPEnhancedErrorCode($response);
        $this->Error = $response;
        $this->_Close_Smtp_Connection();

        $this->DebugMemUsage('Got error ' . $this->Error);

        return array(false, $this->Error);
    }

    $msg = "To: " . $to . $this->_smtp_newline . "Subject: " . $subject . $this->_smtp_newline . $headers . $this->_smtp_newline . preg_replace('/^\.(\r|\n)/m', ' .${1}', $body);

    $msg = str_replace("\r\n","\n",$msg);
    $msg = str_replace("\r","\n",$msg);
    $lines = explode("\n",$msg);
    foreach ($lines as $no => $line) {
        // we need to rtrim here so we don't get rid of tabs before the start of the line.
        // the tab is extremely important for boundaries (eg sending multipart + attachment)
        // so it needs to stay.
        $data = rtrim($line);

        $this->DebugMemUsage('Trying to put ' . $data);

        if (!$this->_Put_Smtp_Connection($data)) {
            $this->ErrorCode = 13;
            $this->ErrorCodeSMTPEnhanced = false;
            $this->Error = GetLang('UnableToSendEmail_DataWriting');
            $this->_Close_Smtp_Connection();

            $this->DebugMemUsage('Got error ' . $this->Error);

            return array(false, $this->Error);
        }
    }

    $data = $this->_smtp_newline . ".";

    $this->DebugMemUsage('Trying to put ' . $data);

    if (!$this->_Put_Smtp_Connection($data)) {
        $this->ErrorCode = 14;
        $this->ErrorCodeSMTPEnhanced = false;
        $this->Error = GetLang('UnableToSendEmail_DataFinished');
        $this->_Close_Smtp_Connection();

        $this->DebugMemUsage('Got error ' . $this->Error);

        return array(false, $this->Error);
    }

    $response = $this->_get_response();

    $this->DebugMemUsage('Got response ' . $response);

    $responsecode = substr($response, 0, 3);
    if ($responsecode != '250') {
        $this->ErrorCodeSMTPEnhanced = $this->_GetSMTPEnhancedErrorCode($response);
        $this->ErrorCode = $responsecode;
        $this->Error = $response;
        $this->_Close_Smtp_Connection();

        $this->DebugMemUsage('Got error ' . $this->Error);

        return array(false, $this->Error);
    }

    $this->DebugMemUsage('Mail accepted ');

    /**
     * We got this far, this means we didn't encounter any errors.
     * Cleanup previous error codes and variables since they are no longer relevant
     * with the current process iteration.
     */
    $this->Error = '';
    $this->ErrorCode = false;
    $this->ErrorCodeSMTPEnhanced = false;

    $this->_smtp_email_count++;
    return array(true, false);
}

【问题讨论】:

  • 也许我们可以有一些代码,也许是一个发送循环?
  • 我要回答这个问题...等等
  • 您的问题与应用程序结构有关。
  • 在完成并再次启动之前检测您的脚本是否“崩溃”看起来比每次运行时发送更少的副本更复杂。
  • 脚本不会崩溃,它只是在有密件抄送时和发送了大约1000封电子邮件后可以与stmp协商

标签: php email cron


【解决方案1】:

最后,“bug”出现在另一个函数中,即密件抄送函数;在工作流程的每次调用中,它都不会清理邮件的先前密件抄送副本,而是将它们相加直到达到限制。

【讨论】:

    猜你喜欢
    • 2011-06-09
    • 2015-03-12
    • 2013-01-29
    • 2012-07-11
    • 2012-11-28
    • 2020-08-05
    • 2016-12-19
    • 2016-06-15
    • 1970-01-01
    相关资源
    最近更新 更多