与Smtp的PHP通信

时间:2014-03-07 13:08:02

标签: php email cron

我有一个邮件应用程序,通过cron作业每天发送大约5000封电子邮件(很多帐户文书工作),当邮件发送给一个收件人时正常工作问题出现在我们激活BCC副本时,应用程序开始发送直到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);
}

1 个答案:

答案 0 :(得分:0)

最后&#34; bug&#34;在另一个功能,密件抄送功能;在每次调用工作流程时,都没有清理以前的bcc邮件副本,而是将它们相加,直到达到限制为止。