当前位置: 首页>>代码示例>>PHP>>正文


PHP server_parse函数代码示例

本文整理汇总了PHP中server_parse函数的典型用法代码示例。如果您正苦于以下问题:PHP server_parse函数的具体用法?PHP server_parse怎么用?PHP server_parse使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了server_parse函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: smtpmail

 function smtpmail($host, $port, $smtp_login, $smtp_passw, $mail_to, $message, $SEND)
 {
     $SEND .= $message . "\r\n";
     if (!($socket = @fsockopen($host, $port, $errno, $errstr, 10))) {
         return false;
     }
     if (!server_parse($socket, "220", __LINE__)) {
         return false;
     }
     fputs($socket, "HELO " . $smtp_login . "\r\n");
     if (!server_parse($socket, "250", __LINE__)) {
         fclose($socket);
         return false;
     }
     fputs($socket, "AUTH LOGIN\r\n");
     if (!server_parse($socket, "334", __LINE__)) {
         fclose($socket);
         return false;
     }
     fputs($socket, base64_encode($smtp_login) . "\r\n");
     if (!server_parse($socket, "334", __LINE__)) {
         fclose($socket);
         return false;
     }
     fputs($socket, base64_encode($smtp_passw) . "\r\n");
     if (!server_parse($socket, "235", __LINE__)) {
         fclose($socket);
         return false;
     }
     fputs($socket, "MAIL FROM: <" . $smtp_login . ">\r\n");
     if (!server_parse($socket, "250", __LINE__)) {
         fclose($socket);
         return false;
     }
     fputs($socket, "RCPT TO: <" . $mail_to . ">\r\n");
     if (!server_parse($socket, "250", __LINE__)) {
         fclose($socket);
         return false;
     }
     fputs($socket, "DATA\r\n");
     if (!server_parse($socket, "354", __LINE__)) {
         fclose($socket);
         return false;
     }
     fputs($socket, $SEND . "\r\n.\r\n");
     if (!server_parse($socket, "250", __LINE__)) {
         fclose($socket);
         return false;
     }
     fputs($socket, "QUIT\r\n");
     fclose($socket);
     return true;
 }
开发者ID:Aluxian,项目名称:DroidHub,代码行数:53,代码来源:wiqi.php

示例2: smtp_mail

function smtp_mail($mail_to_array, $subject, $message, $headers)
{
    global $modSettings, $webmaster_email, $txt;
    $modSettings['smtp_host'] = trim($modSettings['smtp_host']);
    // Try POP3 before SMTP?
    // !!! There's no interface for this yet.
    if ($modSettings['mail_type'] == 2 && $modSettings['smtp_username'] != '' && $modSettings['smtp_password'] != '') {
        $socket = fsockopen($modSettings['smtp_host'], 110, $errno, $errstr, 2);
        if (!$socket && (substr($modSettings['smtp_host'], 0, 5) == 'smtp.' || substr($modSettings['smtp_host'], 0, 11) == 'ssl://smtp.')) {
            $socket = fsockopen(strtr($modSettings['smtp_host'], array('smtp.' => 'pop.')), 110, $errno, $errstr, 2);
        }
        if ($socket) {
            fgets($socket, 256);
            fputs($socket, 'USER ' . $modSettings['smtp_username'] . "\r\n");
            fgets($socket, 256);
            fputs($socket, 'PASS ' . base64_decode($modSettings['smtp_password']) . "\r\n");
            fgets($socket, 256);
            fputs($socket, 'QUIT' . "\r\n");
            fclose($socket);
        }
    }
    // Try to connect to the SMTP server... if it doesn't exist, only wait three seconds.
    if (!($socket = fsockopen($modSettings['smtp_host'], empty($modSettings['smtp_port']) ? 25 : $modSettings['smtp_port'], $errno, $errstr, 3))) {
        // Maybe we can still save this?  The port might be wrong.
        if (substr($modSettings['smtp_host'], 0, 4) == 'ssl:' && (empty($modSettings['smtp_port']) || $modSettings['smtp_port'] == 25)) {
            if ($socket = fsockopen($modSettings['smtp_host'], 465, $errno, $errstr, 3)) {
                log_error($txt['smtp_port_ssl']);
            }
        }
        // Unable to connect!  Don't show any error message, but just log one and try to continue anyway.
        if (!$socket) {
            log_error($txt['smtp_no_connect'] . ': ' . $errno . ' : ' . $errstr);
            return false;
        }
    }
    // Wait for a response of 220, without "-" continuer.
    if (!server_parse(null, $socket, '220')) {
        return false;
    }
    if ($modSettings['mail_type'] == 1 && $modSettings['smtp_username'] != '' && $modSettings['smtp_password'] != '') {
        // !!! These should send the CURRENT server's name, not the mail server's!
        // EHLO could be understood to mean encrypted hello...
        if (server_parse('EHLO ' . $modSettings['smtp_host'], $socket, null) == '250') {
            if (!server_parse('AUTH LOGIN', $socket, '334')) {
                return false;
            }
            // Send the username and password, encoded.
            if (!server_parse(base64_encode($modSettings['smtp_username']), $socket, '334')) {
                return false;
            }
            // The password is already encoded ;)
            if (!server_parse($modSettings['smtp_password'], $socket, '235')) {
                return false;
            }
        } elseif (!server_parse('HELO ' . $modSettings['smtp_host'], $socket, '250')) {
            return false;
        }
    } else {
        // Just say "helo".
        if (!server_parse('HELO ' . $modSettings['smtp_host'], $socket, '250')) {
            return false;
        }
    }
    // Fix the message for any lines beginning with a period! (the first is ignored, you see.)
    $message = strtr($message, array("\r\n." => "\r\n.."));
    // !! Theoretically, we should be able to just loop the RCPT TO.
    $mail_to_array = array_values($mail_to_array);
    foreach ($mail_to_array as $i => $mail_to) {
        // Reset the connection to send another email.
        if ($i != 0) {
            if (!server_parse('RSET', $socket, '250')) {
                return false;
            }
        }
        // From, to, and then start the data...
        if (!server_parse('MAIL FROM: <' . (empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from']) . '>', $socket, '250')) {
            return false;
        }
        if (!server_parse('RCPT TO: <' . $mail_to . '>', $socket, '250')) {
            return false;
        }
        if (!server_parse('DATA', $socket, '354')) {
            return false;
        }
        fputs($socket, 'Subject: ' . $subject . "\r\n");
        if (strlen($mail_to) > 0) {
            fputs($socket, 'To: <' . $mail_to . ">\r\n");
        }
        fputs($socket, $headers . "\r\n\r\n");
        fputs($socket, $message . "\r\n");
        // Send a ., or in other words "end of data".
        if (!server_parse('.', $socket, '250')) {
            return false;
        }
        // Almost done, almost done... don't stop me just yet!
        @set_time_limit(300);
        if (function_exists('apache_reset_timeout')) {
            apache_reset_timeout();
        }
    }
//.........这里部分代码省略.........
开发者ID:VBGAMER45,项目名称:SMFMods,代码行数:101,代码来源:Subs-Post.php

示例3: smtp_mail

function smtp_mail($to, $subject, $message, $headers = '')
{
    global $pun_config;
    $recipients = explode(',', $to);
    // Sanitize the message
    $message = str_replace("\r\n.", "\r\n..", $message);
    $message = substr($message, 0, 1) == '.' ? '.' . $message : $message;
    // Are we using port 25 or a custom port?
    if (strpos($pun_config['o_smtp_host'], ':') !== false) {
        list($smtp_host, $smtp_port) = explode(':', $pun_config['o_smtp_host']);
    } else {
        $smtp_host = $pun_config['o_smtp_host'];
        $smtp_port = 25;
    }
    if ($pun_config['o_smtp_ssl'] == '1') {
        $smtp_host = 'ssl://' . $smtp_host;
    }
    if (!($socket = fsockopen($smtp_host, $smtp_port, $errno, $errstr, 15))) {
        error('Could not connect to smtp host "' . $pun_config['o_smtp_host'] . '" (' . $errno . ') (' . $errstr . ')', __FILE__, __LINE__);
    }
    server_parse($socket, '220');
    if ($pun_config['o_smtp_user'] != '' && $pun_config['o_smtp_pass'] != '') {
        fwrite($socket, 'EHLO ' . $smtp_host . "\r\n");
        server_parse($socket, '250');
        fwrite($socket, 'AUTH LOGIN' . "\r\n");
        server_parse($socket, '334');
        fwrite($socket, base64_encode($pun_config['o_smtp_user']) . "\r\n");
        server_parse($socket, '334');
        fwrite($socket, base64_encode($pun_config['o_smtp_pass']) . "\r\n");
        server_parse($socket, '235');
    } else {
        fwrite($socket, 'HELO ' . $smtp_host . "\r\n");
        server_parse($socket, '250');
    }
    fwrite($socket, 'MAIL FROM: <' . $pun_config['o_webmaster_email'] . '>' . "\r\n");
    server_parse($socket, '250');
    foreach ($recipients as $email) {
        fwrite($socket, 'RCPT TO: <' . $email . '>' . "\r\n");
        server_parse($socket, '250');
    }
    fwrite($socket, 'DATA' . "\r\n");
    server_parse($socket, '354');
    fwrite($socket, 'Subject: ' . $subject . "\r\n" . 'To: <' . implode('>, <', $recipients) . '>' . "\r\n" . $headers . "\r\n\r\n" . $message . "\r\n");
    fwrite($socket, '.' . "\r\n");
    server_parse($socket, '250');
    fwrite($socket, 'QUIT' . "\r\n");
    fclose($socket);
    return true;
}
开发者ID:rakete,项目名称:affenbande-fluxbb,代码行数:49,代码来源:email.php

示例4: smtp_mail

function smtp_mail($to, $subject, $message, $headers = '')
{
    global $pun_config;
    $recipients = explode(',', $to);
    // Are we using port 25 or a custom port?
    if (strpos($pun_config['o_smtp_host'], ':') !== false) {
        list($smtp_host, $smtp_port) = explode(':', $pun_config['o_smtp_host']);
    } else {
        $smtp_host = $pun_config['o_smtp_host'];
        $smtp_port = 25;
    }
    if (!($socket = fsockopen($smtp_host, $smtp_port, $errno, $errstr, 15))) {
        error('Could not connect to smtp host "' . $pun_config['o_smtp_host'] . '" (' . $errno . ') (' . $errstr . ')', __FILE__, __LINE__);
    }
    server_parse($socket, 220);
    if ($pun_config['o_smtp_user'] && $pun_config['o_smtp_pass']) {
        fwrite($socket, 'EHLO ' . $smtp_host . "\r\n");
        server_parse($socket, 250);
        fwrite($socket, 'AUTH LOGIN' . "\r\n");
        server_parse($socket, 334);
        fwrite($socket, base64_encode($pun_config['o_smtp_user']) . "\r\n");
        server_parse($socket, 334);
        fwrite($socket, base64_encode($pun_config['o_smtp_pass']) . "\r\n");
        server_parse($socket, 235);
    } else {
        fwrite($socket, 'HELO ' . $smtp_host . "\r\n");
        server_parse($socket, 250);
    }
    fwrite($socket, 'MAIL FROM: <' . $pun_config['o_webmaster_email'] . '>' . "\r\n");
    server_parse($socket, 250);
    $to_header = 'To: ';
    @reset($recipients);
    while (list(, $email) = @each($recipients)) {
        fwrite($socket, 'RCPT TO: <' . $email . '>' . "\r\n");
        server_parse($socket, 250);
        $to_header .= '<' . $email . '>, ';
    }
    fwrite($socket, 'DATA' . "\r\n");
    server_parse($socket, 354);
    fwrite($socket, 'Subject: ' . $subject . "\r\n" . $to_header . "\r\n" . $headers . "\r\n\r\n" . $message . "\r\n");
    fwrite($socket, '.' . "\r\n");
    server_parse($socket, 250);
    fwrite($socket, 'QUIT' . "\r\n");
    fclose($socket);
    return true;
}
开发者ID:tipsun91,项目名称:punbb-mod,代码行数:46,代码来源:email.php

示例5: smtpmail

function smtpmail($mail_to, $subject, $message, $headers = '', $smtp_host, $smtp_username, $smtp_password, $admin_email)
{
    //global $smtp_host, $smtp_username, $smtp_password, $admin_email;
    //echo $to_mail.$subject.$message.$headers.$smtp_host.$smtp_username.$smtp_password;
    //
    // Fix any bare linefeeds in the message to make it RFC821 Compliant.
    //
    $message = preg_replace("/(?<!\r)\n/si", "\r\n", $message);
    /*echo "SMTP_HOST".$smtp_host;
      echo "<br>\nSMTP_USER".$smtp_user;
      echo "<br>\nSMTP_PW".$smtp_password;
      echo "<br>\nADMIN".$admin_email; */
    if ($headers != "") {
        if (is_array($headers)) {
            if (sizeof($headers) > 1) {
                $headers = join("\r\n", $headers);
            } else {
                $headers = $headers[0];
            }
        }
        $headers = chop($headers);
        //
        // Make sure there are no bare linefeeds in the headers
        //
        $headers = preg_replace("/(?<!\r)\n/si", "\r\n", $headers);
        //
        // Ok this is rather confusing all things considered,
        // but we have to grab bcc and cc headers and treat them differently
        // Something we really didn't take into consideration originally
        //
        $header_array = explode("\r\n", $headers);
        @reset($header_array);
        $headers = "";
        $cc = '';
        $bcc = '';
        while (list(, $header) = each($header_array)) {
            if (preg_match("/^cc:/si", $header)) {
                $cc = preg_replace("/^cc:(.*)/si", "\\1", $header);
            } else {
                if (preg_match("/^bcc:/si", $header)) {
                    $bcc = preg_replace("/^bcc:(.*)/si", "\\1", $header);
                    $header = "";
                }
            }
            $headers .= $header . "\r\n";
        }
        $headers = chop($headers);
        $cc = explode(",", $cc);
        $bcc = explode(",", $bcc);
    }
    if (trim($mail_to) == "") {
        exit;
    }
    if (trim($subject) == "") {
        die("No email Subject specified");
    }
    $mail_to_array = explode(",", $mail_to);
    //
    // Ok we have error checked as much as we can to this point let's get on
    // it already.
    //
    if (!($socket = fsockopen($smtp_host, 25, $errno, $errstr, 20))) {
        die("Could not connect to smtp host : {$errno} : {$errstr}");
    }
    server_parse($socket, "220");
    if (!empty($smtp_username) && !empty($smtp_password)) {
        // Send the RFC2554 specified EHLO.
        // This improved as provided by SirSir to accomodate
        // both SMTP AND ESMTP capable servers
        fputs($socket, "EHLO " . $smtp_host . "\r\n");
        server_parse($socket, "250");
        fputs($socket, "AUTH LOGIN\r\n");
        server_parse($socket, "334");
        fputs($socket, base64_encode($smtp_username) . "\r\n");
        server_parse($socket, "334");
        fputs($socket, base64_encode($smtp_password) . "\r\n");
        server_parse($socket, "235");
    } else {
        // Send the RFC821 specified HELO.
        fputs($socket, "HELO " . $smtp_host . "\r\n");
        server_parse($socket, "250");
    }
    // From this point onward most server response codes should be 250
    // Specify who the mail is from....
    fputs($socket, "MAIL FROM: <" . $admin_email . ">\r\n");
    server_parse($socket, "250");
    // Specify each user to send to and build to header.
    $to_header = "To: ";
    @reset($mail_to_array);
    while (list(, $mail_to_address) = each($mail_to_array)) {
        //
        // Add an additional bit of error checking to the To field.
        //
        $mail_to_address = trim($mail_to_address);
        if (preg_match('/[^ ]+\\@[^ ]+/', $mail_to_address)) {
            fputs($socket, "RCPT TO: <{$mail_to_address}>\r\n");
            server_parse($socket, "250");
        }
        $to_header .= "<{$mail_to_address}>, ";
    }
//.........这里部分代码省略.........
开发者ID:DKNY1201,项目名称:TPS,代码行数:101,代码来源:smtp.php

示例6: smtpmail

function smtpmail($mail_to, $subject, $message, $headers = '')
{
    global $board_config;
    // Fix any bare linefeeds in the message to make it RFC821 Compliant.
    $message = preg_replace("#(?<!\r)\n#si", "\r\n", $message);
    if ($headers != '') {
        if (is_array($headers)) {
            if (sizeof($headers) > 1) {
                $headers = join("\n", $headers);
            } else {
                $headers = $headers[0];
            }
        }
        $headers = chop($headers);
        // Make sure there are no bare linefeeds in the headers
        $headers = preg_replace('#(?<!\\r)\\n#si', "\r\n", $headers);
        // Ok this is rather confusing all things considered,
        // but we have to grab bcc and cc headers and treat them differently
        // Something we really didn't take into consideration originally
        $header_array = explode("\r\n", $headers);
        @reset($header_array);
        $headers = '';
        while (list(, $header) = each($header_array)) {
            if (preg_match('#^cc:#si', $header)) {
                $cc = preg_replace('#^cc:(.*)#si', '\\1', $header);
            } else {
                if (preg_match('#^bcc:#si', $header)) {
                    $bcc = preg_replace('#^bcc:(.*)#si', '\\1', $header);
                    $header = '';
                }
            }
            $headers .= $header != '' ? $header . "\r\n" : '';
        }
        $headers = chop($headers);
        $cc = explode(', ', $cc);
        $bcc = explode(', ', $bcc);
    }
    if (trim($subject) == '') {
        message_die(GENERAL_ERROR, "No email Subject specified", "", __LINE__, __FILE__);
    }
    if (trim($message) == '') {
        message_die(GENERAL_ERROR, "Email message was blank", "", __LINE__, __FILE__);
    }
    // Ok we have error checked as much as we can to this point let's get on
    // it already.
    if (!($socket = fsockopen($board_config['smtp_host'], 25, $errno, $errstr, 20))) {
        message_die(GENERAL_ERROR, "Could not connect to smtp host : {$errno} : {$errstr}", "", __LINE__, __FILE__);
    }
    // Wait for reply
    server_parse($socket, "220", __LINE__);
    // Do we want to use AUTH?, send RFC2554 EHLO, else send RFC821 HELO
    // This improved as provided by SirSir to accomodate
    if (!empty($board_config['smtp_username']) && !empty($board_config['smtp_password'])) {
        fputs($socket, "EHLO " . $board_config['smtp_host'] . "\r\n");
        server_parse($socket, "250", __LINE__);
        fputs($socket, "AUTH LOGIN\r\n");
        server_parse($socket, "334", __LINE__);
        fputs($socket, base64_encode($board_config['smtp_username']) . "\r\n");
        server_parse($socket, "334", __LINE__);
        fputs($socket, base64_encode($board_config['smtp_password']) . "\r\n");
        server_parse($socket, "235", __LINE__);
    } else {
        fputs($socket, "HELO " . $board_config['smtp_host'] . "\r\n");
        server_parse($socket, "250", __LINE__);
    }
    // From this point onward most server response codes should be 250
    // Specify who the mail is from....
    fputs($socket, "MAIL FROM: <" . $board_config['board_email'] . ">\r\n");
    server_parse($socket, "250", __LINE__);
    // Specify each user to send to and build to header.
    $to_header = '';
    // Add an additional bit of error checking to the To field.
    $mail_to = trim($mail_to) == '' ? 'Undisclosed-recipients:;' : trim($mail_to);
    if (preg_match('#[^ ]+\\@[^ ]+#', $mail_to)) {
        fputs($socket, "RCPT TO: <{$mail_to}>\r\n");
        server_parse($socket, "250", __LINE__);
    }
    // Ok now do the CC and BCC fields...
    @reset($bcc);
    while (list(, $bcc_address) = each($bcc)) {
        // Add an additional bit of error checking to bcc header...
        $bcc_address = trim($bcc_address);
        if (preg_match('#[^ ]+\\@[^ ]+#', $bcc_address)) {
            fputs($socket, "RCPT TO: <{$bcc_address}>\r\n");
            server_parse($socket, "250", __LINE__);
        }
    }
    @reset($cc);
    while (list(, $cc_address) = each($cc)) {
        // Add an additional bit of error checking to cc header
        $cc_address = trim($cc_address);
        if (preg_match('#[^ ]+\\@[^ ]+#', $cc_address)) {
            fputs($socket, "RCPT TO: <{$cc_address}>\r\n");
            server_parse($socket, "250", __LINE__);
        }
    }
    // Ok now we tell the server we are ready to start sending data
    fputs($socket, "DATA\r\n");
    // This is the last response code we look for until the end of the message.
    server_parse($socket, "354", __LINE__);
//.........这里部分代码省略.........
开发者ID:BackupTheBerlios,项目名称:smileinstaller,代码行数:101,代码来源:smtp.php

示例7: smtp_mail

function smtp_mail($to, $subject, $message, $headers = '')
{
    global $luna_config;
    static $local_host;
    $recipients = explode(',', $to);
    // Sanitize the message
    $message = str_replace("\r\n.", "\r\n..", $message);
    $message = substr($message, 0, 1) == '.' ? '.' . $message : $message;
    // Are we using port 25 or a custom port?
    if (strpos($luna_config['o_smtp_host'], ':') !== false) {
        list($smtp_host, $smtp_port) = explode(':', $luna_config['o_smtp_host']);
    } else {
        $smtp_host = $luna_config['o_smtp_host'];
        $smtp_port = 25;
    }
    if ($luna_config['o_smtp_ssl'] == '1') {
        $smtp_host = 'ssl://' . $smtp_host;
    }
    if (!($socket = fsockopen($smtp_host, $smtp_port, $errno, $errstr, 15))) {
        error('Could not connect to smtp host "' . $luna_config['o_smtp_host'] . '" (' . $errno . ') (' . $errstr . ')', __FILE__, __LINE__);
    }
    server_parse($socket, '220');
    if (!isset($local_host)) {
        // Here we try to determine the *real* hostname (reverse DNS entry preferably)
        $local_host = php_uname('n');
        // Able to resolve name to IP
        if (($local_addr = @gethostbyname($local_host)) !== $local_host) {
            // Able to resolve IP back to name
            if (($local_name = @gethostbyaddr($local_addr)) !== $local_addr) {
                $local_host = $local_name;
            }
        }
    }
    if ($luna_config['o_smtp_user'] != '' && $luna_config['o_smtp_pass'] != '') {
        fwrite($socket, 'EHLO ' . $local_host . "\r\n");
        server_parse($socket, '250');
        fwrite($socket, 'AUTH LOGIN' . "\r\n");
        server_parse($socket, '334');
        fwrite($socket, base64_encode($luna_config['o_smtp_user']) . "\r\n");
        server_parse($socket, '334');
        fwrite($socket, base64_encode($luna_config['o_smtp_pass']) . "\r\n");
        server_parse($socket, '235');
    } else {
        fwrite($socket, 'HELO ' . $local_host . "\r\n");
        server_parse($socket, '250');
    }
    fwrite($socket, 'MAIL FROM: <' . $luna_config['o_webmaster_email'] . '>' . "\r\n");
    server_parse($socket, '250');
    foreach ($recipients as $email) {
        fwrite($socket, 'RCPT TO: <' . $email . '>' . "\r\n");
        server_parse($socket, '250');
    }
    fwrite($socket, 'DATA' . "\r\n");
    server_parse($socket, '354');
    fwrite($socket, 'Subject: ' . $subject . "\r\n" . 'To: <' . implode('>, <', $recipients) . '>' . "\r\n" . $headers . "\r\n\r\n" . $message . "\r\n");
    fwrite($socket, '.' . "\r\n");
    server_parse($socket, '250');
    fwrite($socket, 'QUIT' . "\r\n");
    fclose($socket);
    return true;
}
开发者ID:BogusCurry,项目名称:Luna,代码行数:61,代码来源:email.php

示例8: smtpmail

function smtpmail($mail_to, $subject, $message, $headers)
{
    global $config;
    $SEND = "Date: " . date("D, d M Y H:i:s") . " UT\r\n";
    $SEND .= 'Subject: =?' . $config['smtp_charset'] . '?B?' . base64_encode($subject) . "=?=\r\n";
    if ($headers) {
        $SEND .= $headers . "\r\n\r\n";
    } else {
        $SEND .= "Reply-To: " . $config['smtp_username'] . "\r\n";
        $SEND .= "MIME-Version: 1.0\r\n";
        $SEND .= "Content-Type: text/plain; charset=\"" . $config['smtp_charset'] . "\"\r\n";
        $SEND .= "Content-Transfer-Encoding: 8bit\r\n";
        $SEND .= "From: \"" . $config['smtp_from'] . "\" <" . $config['smtp_username'] . ">\r\n";
        $SEND .= "To: {$mail_to} <{$mail_to}>\r\n";
        $SEND .= "X-Priority: 3\r\n\r\n";
    }
    $SEND .= $message . "\r\n";
    if (!($socket = fsockopen($config['smtp_host'], $config['smtp_port'], $errno, $errstr, 30))) {
        if ($config['smtp_debug']) {
            echo $errno . "&lt;br&gt;" . $errstr;
        }
        return false;
    }
    if (!server_parse($socket, "220", __LINE__)) {
        return false;
    }
    fputs($socket, "HELO " . $config['smtp_host'] . "\r\n");
    if (!server_parse($socket, "250", __LINE__)) {
        if ($config['smtp_debug']) {
            echo '<p>Не могу отправить HELO!</p>';
        }
        fclose($socket);
        return false;
    }
    fputs($socket, "AUTH LOGIN\r\n");
    if (!server_parse($socket, "334", __LINE__)) {
        if ($config['smtp_debug']) {
            echo '<p>Не могу найти ответ на запрос авторизаци.</p>';
        }
        fclose($socket);
        return false;
    }
    fputs($socket, base64_encode($config['smtp_username']) . "\r\n");
    if (!server_parse($socket, "334", __LINE__)) {
        if ($config['smtp_debug']) {
            echo '<p>Логин авторизации не был принят сервером!</p>';
        }
        fclose($socket);
        return false;
    }
    fputs($socket, base64_encode($config['smtp_password']) . "\r\n");
    if (!server_parse($socket, "235", __LINE__)) {
        if ($config['smtp_debug']) {
            echo '<p>Пароль не был принят сервером как верный! Ошибка авторизации!</p>';
        }
        fclose($socket);
        return false;
    }
    fputs($socket, "MAIL FROM: <" . $config['smtp_username'] . ">\r\n");
    if (!server_parse($socket, "250", __LINE__)) {
        if ($config['smtp_debug']) {
            echo '<p>Не могу отправить комманду MAIL FROM: </p>';
        }
        fclose($socket);
        return false;
    }
    fputs($socket, "RCPT TO: <" . $mail_to . ">\r\n");
    if (!server_parse($socket, "250", __LINE__)) {
        if ($config['smtp_debug']) {
            echo '<p>Не могу отправить комманду RCPT TO: </p>';
        }
        fclose($socket);
        return false;
    }
    fputs($socket, "DATA\r\n");
    if (!server_parse($socket, "354", __LINE__)) {
        if ($config['smtp_debug']) {
            echo '<p>Не могу отправить комманду DATA</p>';
        }
        fclose($socket);
        return false;
    }
    fputs($socket, $SEND . "\r\n.\r\n");
    if (!server_parse($socket, "250", __LINE__)) {
        if ($config['smtp_debug']) {
            echo '<p>Не смог отправить тело письма. Письмо не было отправленно!</p>';
        }
        fclose($socket);
        return false;
    }
    fputs($socket, "QUIT\r\n");
    fclose($socket);
    return TRUE;
}
开发者ID:nekleenov,项目名称:sampucp,代码行数:94,代码来源:mail.class.php

示例9: smtp_mail

/**
 * Sends mail, like mail() but over SMTP.
 *
 * - It expects no slashes or entities.
 *
 * @package Mail
 * @internal
 * @param string[] $mail_to_array - array of strings (email addresses)
 * @param string $subject email subject
 * @param string $message email message
 * @param string $headers
 * @param int $priority
 * @param string|null $message_id
 * @return boolean whether it sent or not.
 */
function smtp_mail($mail_to_array, $subject, $message, $headers, $priority, $message_id = null)
{
    global $modSettings, $webmaster_email, $txt, $scripturl;
    $modSettings['smtp_host'] = trim($modSettings['smtp_host']);
    // Try POP3 before SMTP?
    // @todo There's no interface for this yet.
    if ($modSettings['mail_type'] == 2 && $modSettings['smtp_username'] != '' && $modSettings['smtp_password'] != '') {
        $socket = fsockopen($modSettings['smtp_host'], 110, $errno, $errstr, 2);
        if (!$socket && (substr($modSettings['smtp_host'], 0, 5) == 'smtp.' || substr($modSettings['smtp_host'], 0, 11) == 'ssl://smtp.')) {
            $socket = fsockopen(strtr($modSettings['smtp_host'], array('smtp.' => 'pop.')), 110, $errno, $errstr, 2);
        }
        if ($socket) {
            fgets($socket, 256);
            fputs($socket, 'USER ' . $modSettings['smtp_username'] . "\r\n");
            fgets($socket, 256);
            fputs($socket, 'PASS ' . base64_decode($modSettings['smtp_password']) . "\r\n");
            fgets($socket, 256);
            fputs($socket, 'QUIT' . "\r\n");
            fclose($socket);
        }
    }
    // Try to connect to the SMTP server... if it doesn't exist, only wait three seconds.
    if (!($socket = fsockopen($modSettings['smtp_host'], empty($modSettings['smtp_port']) ? 25 : $modSettings['smtp_port'], $errno, $errstr, 3))) {
        // Maybe we can still save this?  The port might be wrong.
        if (substr($modSettings['smtp_host'], 0, 4) == 'ssl:' && (empty($modSettings['smtp_port']) || $modSettings['smtp_port'] == 25)) {
            if ($socket = fsockopen($modSettings['smtp_host'], 465, $errno, $errstr, 3)) {
                log_error($txt['smtp_port_ssl']);
            }
        }
        // Unable to connect!  Don't show any error message, but just log one and try to continue anyway.
        if (!$socket) {
            log_error($txt['smtp_no_connect'] . ': ' . $errno . ' : ' . $errstr);
            return false;
        }
    }
    // Wait for a response of 220, without "-" continue.
    if (!server_parse(null, $socket, '220')) {
        return false;
    }
    if ($modSettings['mail_type'] == 1 && $modSettings['smtp_username'] != '' && $modSettings['smtp_password'] != '') {
        // @todo These should send the CURRENT server's name, not the mail server's!
        // EHLO could be understood to mean encrypted hello...
        if (server_parse('EHLO ' . $modSettings['smtp_host'], $socket, null) == '250') {
            if (!server_parse('AUTH LOGIN', $socket, '334')) {
                return false;
            }
            // Send the username and password, encoded.
            if (!server_parse(base64_encode($modSettings['smtp_username']), $socket, '334')) {
                return false;
            }
            // The password is already encoded ;)
            if (!server_parse($modSettings['smtp_password'], $socket, '235')) {
                return false;
            }
        } elseif (!server_parse('HELO ' . $modSettings['smtp_host'], $socket, '250')) {
            return false;
        }
    } else {
        // Just say "helo".
        if (!server_parse('HELO ' . $modSettings['smtp_host'], $socket, '250')) {
            return false;
        }
    }
    // Fix the message for any lines beginning with a period! (the first is ignored, you see.)
    $message = strtr($message, array("\r\n" . '.' => "\r\n" . '..'));
    $sent = array();
    $need_break = substr($headers, -1) === "\n" || substr($headers, -1) === "\r" ? false : true;
    $real_headers = $headers;
    $line_break = "\r\n";
    // !! Theoretically, we should be able to just loop the RCPT TO.
    $mail_to_array = array_values($mail_to_array);
    foreach ($mail_to_array as $i => $mail_to) {
        // the keys are must unique for every mail you see
        $unq_id = '';
        $unq_head = '';
        // Using the post by email functions, and not a digest (priority 4)
        // then generate "reply to mail" keys and place them in the message
        if (!empty($modSettings['maillist_enabled']) && $message_id !== null && $priority != 4) {
            $unq_head = md5($scripturl . microtime() . rand()) . '-' . $message_id;
            $encoded_unq_head = base64_encode($line_break . $line_break . '[' . $unq_head . ']' . $line_break);
            $unq_id = ($need_break ? $line_break : '') . 'Message-ID: <' . $unq_head . strstr(empty($modSettings['maillist_mail_from']) ? $webmaster_email : $modSettings['maillist_mail_from'], '@') . '>';
            $message = mail_insert_key($message, $unq_head, $encoded_unq_head, $line_break);
        }
        // Fix up the headers for this email!
        $headers = $real_headers . $unq_id;
//.........这里部分代码省略.........
开发者ID:scripple,项目名称:Elkarte,代码行数:101,代码来源:Mail.subs.php

示例10: smtp_send

function smtp_send($mail_to_array, $from_name, $subject, $message)
{
    global $smtp_allow, $smtp_server, $smtp_port, $smtp_email, $smtp_username, $smtp_password;
    # If they didn't want smtp being used, just die
    if ($smtp_allow != 1) {
        return true;
    }
    # Try connecting to the SMTP server
    if (!($socket = fsockopen($smtp_server, $smtp_port, $errno, $errstr, 5))) {
        # Unable to connect!
        print "Unable to connect to the SMTP server to email alerts: {$errno} : {$errstr}<BR>";
        return false;
    }
    // Construct the mail headers...
    $headers = 'From: "' . addcslashes($from_name, '<>[]()\'\\"') . '" <' . $smtp_email . ">\r\n";
    $headers .= 'Date: ' . gmdate('D, d M Y H:i:s') . ' +0000' . "\r\n";
    // Wait for a response of 220, without "-" continuer.
    if (!server_parse(null, $socket, '220')) {
        return false;
    }
    if ($smtp_username != '' && $smtp_password != '') {
        // EHLO could be understood to mean encrypted hello...
        if (!server_parse('EHLO ' . $smtp_server, $socket, '250')) {
            return false;
        }
        if (!server_parse('AUTH LOGIN', $socket, '334')) {
            return false;
        }
        // Send the username ans password, encoded.
        if (!server_parse(base64_encode($smtp_username), $socket, '334')) {
            return false;
        }
        if (!server_parse(base64_encode($smtp_password), $socket, '235')) {
            return false;
        }
    } else {
        // Just say "helo".
        if (!server_parse('HELO ' . $smtp_server, $socket, '250')) {
            return false;
        }
    }
    foreach ($mail_to_array as $mail_to) {
        // From, to, and then start the data...
        if (!server_parse('MAIL FROM: <' . $smtp_email . '>', $socket, '250')) {
            return false;
        }
        if (!server_parse('RCPT TO: <' . $mail_to . '>', $socket, '250')) {
            return false;
        }
        if (!server_parse('DATA', $socket, '354')) {
            return false;
        }
        fputs($socket, 'Subject: ' . $subject . "\r\n");
        if (strlen($mail_to) > 0) {
            fputs($socket, 'To: <' . $mail_to . ">\r\n");
        }
        fputs($socket, $headers . "\r\n\r\n");
        fputs($socket, $message . "\r\n");
        // Send a ., or in other words "end of data".
        if (!server_parse('.', $socket, '250')) {
            return false;
        }
        // Reset the connection to send another email.
        if (!server_parse('RSET', $socket, '250')) {
            return false;
        }
    }
    fputs($socket, "QUIT\r\n");
    fclose($socket);
    return true;
}
开发者ID:shifter,项目名称:ospap,代码行数:71,代码来源:shared.php

示例11: smtpmail

function smtpmail($mail_to, $subject, $message, $headers = '')
{
    //Настройки почты
    $config['smtp_username'] = 'manager@gp-studio.ru';
    //Смените на имя своего почтового ящика из ISPManager.
    $config['smtp_password'] = 'DVvvm5734';
    //Измените пароль.
    $config['smtp_from'] = 'GP-STUDIO';
    //Ваше имя - или имя Вашего сайта. Будет показывать при прочтении в поле "От кого".
    //Обычно эти настройки менять не стоит
    $config['smtp_host'] = 'localhost';
    //Сервер для отправки почты (для наших клиентов менять не требуется).
    $config['smtp_port'] = '25';
    // Порт работы. Не меняйте, если не уверены.
    $config['smtp_debug'] = false;
    //Если Вы хотите видеть сообщения ошибок, укажите true вместо false.
    $config['smtp_charset'] = 'UTF-8';
    //Кодировка сообщений.
    $SEND = "Date: " . date("D, d M Y H:i:s") . " UT\r\n";
    $SEND .= 'Subject: =?' . $config['smtp_charset'] . '?B?' . base64_encode($subject) . "=?=\r\n";
    if ($headers) {
        $SEND .= $headers . "\r\n\r\n";
    } else {
        $SEND .= "Reply-To: " . $config['smtp_username'] . "\r\n";
        $SEND .= "MIME-Version: 1.0\r\n";
        $SEND .= "Content-Type: text/plain; charset=\"" . $config['smtp_charset'] . "\"\r\n";
        $SEND .= "Content-Transfer-Encoding: 8bit\r\n";
        $SEND .= "From: \"" . $config['smtp_from'] . "\" <" . $config['smtp_username'] . ">\r\n";
        $SEND .= "To: {$mail_to} <{$mail_to}>\r\n";
        $SEND .= "X-Priority: 3\r\n\r\n";
    }
    $SEND .= $message . "\r\n";
    if (!($socket = fsockopen($config['smtp_host'], $config['smtp_port'], $errno, $errstr, 30))) {
        if ($config['smtp_debug']) {
            echo $errno . "<br>" . $errstr;
        }
        return false;
    }
    if (!server_parse($socket, "220", __LINE__)) {
        return false;
    }
    fputs($socket, "EHLO " . $config['smtp_host'] . "\r\n");
    if (!server_parse($socket, "250", __LINE__)) {
        if ($config['smtp_debug']) {
            echo '<p>Не могу отправить EHLO!</p>';
        }
        fclose($socket);
        return false;
    }
    fputs($socket, "AUTH LOGIN\r\n");
    if (!server_parse($socket, "334", __LINE__)) {
        if ($config['smtp_debug']) {
            echo '<p>Не могу найти ответ на запрос авторизации!</p>';
        }
        fclose($socket);
        return false;
    }
    fputs($socket, base64_encode($config['smtp_username']) . "\r\n");
    if (!server_parse($socket, "334", __LINE__)) {
        if ($config['smtp_debug']) {
            echo '<p>Логин авторизации не был принят сервером!</p>';
        }
        fclose($socket);
        return false;
    }
    fputs($socket, base64_encode($config['smtp_password']) . "\r\n");
    if (!server_parse($socket, "235", __LINE__)) {
        if ($config['smtp_debug']) {
            echo '<p>Пароль не был принят сервером как верный! Ошибка авторизации!</p>';
        }
        fclose($socket);
        return false;
    }
    fputs($socket, "MAIL FROM: <" . $config['smtp_username'] . ">\r\n");
    if (!server_parse($socket, "250", __LINE__)) {
        if ($config['smtp_debug']) {
            echo '<p>Не могу отправить команду MAIL FROM:</p>';
        }
        fclose($socket);
        return false;
    }
    fputs($socket, "RCPT TO: <" . $mail_to . ">\r\n");
    if (!server_parse($socket, "250", __LINE__)) {
        if ($config['smtp_debug']) {
            echo '<p>Не могу отправить команду RCPT TO:</p>';
        }
        fclose($socket);
        return false;
    }
    fputs($socket, "DATA\r\n");
    if (!server_parse($socket, "354", __LINE__)) {
        if ($config['smtp_debug']) {
            echo '<p>Не могу отправить команду DATA!</p>';
        }
        fclose($socket);
        return false;
    }
    fputs($socket, $SEND . "\r\n.\r\n");
    if (!server_parse($socket, "250", __LINE__)) {
        if ($config['smtp_debug']) {
//.........这里部分代码省略.........
开发者ID:MrVladevoit,项目名称:shofacademy,代码行数:101,代码来源:smtp-func.php

示例12: smtp_send

function smtp_send($mail_to_array, $from_name, $subject, $message)
{
    # If they didn't want smtp being used, just die
    if (SMTP_ALLOW != 1) {
        return 'smtp_disabled';
    }
    # Try connecting to the SMTP server
    if (!($socket = fsockopen(SMTP_SERVER, SMTP_PORT, $errno, $errstr, 5))) {
        # Unable to connect!
        return 'smtp_connect_failed';
    }
    // Construct the mail headers...
    $headers = 'From: "' . addcslashes($from_name, '<>[]()\'\\"') . '" <' . SMTP_ADMIN_EMAIL . ">\r\n";
    $headers .= 'Date: ' . gmdate('D, d M Y H:i:s') . ' +0000' . "\r\n";
    // Wait for a response of 220, without "-" continuer.
    if (!server_parse(null, $socket, '220')) {
        return 'smtp_invalid_response';
    }
    if (SMTP_USERNAME != '' && SMTP_PASSWORD != '') {
        // EHLO could be understood to mean encrypted hello...
        if (!server_parse('EHLO ' . SMTP_SERVER, $socket, '250')) {
            return 'smtp_invalid_response';
        }
        if (!server_parse('AUTH LOGIN', $socket, '334')) {
            return 'smtp_invalid_response';
        }
        // Send the username ans password, encoded.
        if (!server_parse(base64_encode(SMTP_USERNAME), $socket, '334')) {
            return 'smtp_invalid_response';
        }
        if (!server_parse(base64_encode(SMTP_PASSWORD), $socket, '235')) {
            return 'smtp_invalid_response';
        }
    } else {
        // Just say "helo".
        if (!server_parse('HELO ' . SMTP_SERVER, $socket, '250')) {
            return 'smtp_invalid_response';
        }
    }
    foreach ($mail_to_array as $mail_to) {
        // From, to, and then start the data...
        if (!server_parse('MAIL FROM: <' . SMTP_ADMIN_EMAIL . '>', $socket, '250')) {
            return 'smtp_error';
        }
        if (!server_parse('RCPT TO: <' . $mail_to . '>', $socket, '250')) {
            return 'smtp_error';
        }
        if (!server_parse('DATA', $socket, '354')) {
            return 'smtp_error';
        }
        fputs($socket, 'Subject: ' . $subject . "\r\n");
        if (strlen($mail_to) > 0) {
            fputs($socket, 'To: <' . $mail_to . ">\r\n");
        }
        fputs($socket, $headers . "\r\n\r\n");
        fputs($socket, $message . "\r\n");
        // Send a ., or in other words "end of data".
        if (!server_parse('.', $socket, '250')) {
            return 'smtp_error';
        }
        // Reset the connection to send another email.
        if (!server_parse('RSET', $socket, '250')) {
            return 'smtp_error';
        }
    }
    fputs($socket, "QUIT\r\n");
    fclose($socket);
    return 'smtp_success';
}
开发者ID:shifter,项目名称:ospap2,代码行数:69,代码来源:functions.php

示例13: smtpmail

function smtpmail($mail_to, $subject, $message, $headers = '')
{
    global $allgAr;
    $smtp_host = $allgAr['mail_smtp_host'];
    $smtp_username = $allgAr['mail_smtp_login'];
    require_once 'include/includes/class/AzDGCrypt.class.inc.php';
    $cr64 = new AzDGCrypt(DBDATE . DBUSER . DBPREF);
    $smtp_password = $cr64->decrypt($allgAr['mail_smtp_password']);
    $absender = $allgAr['mail_smtp_email'];
    $message = preg_replace("#(?<!\r)\n#si", "\r\n", $message);
    if ($headers != '') {
        if (is_array($headers)) {
            if (sizeof($headers) > 1) {
                $headers = join("\n", $headers);
            } else {
                $headers = $headers[0];
            }
        }
        $headers = chop($headers);
        $headers = preg_replace('#(?<!\\r)\\n#si', "\r\n", $headers);
        $header_array = explode("\r\n", $headers);
        @reset($header_array);
        $headers = '';
        while (list(, $header) = each($header_array)) {
            if (preg_match('#^cc:#si', $header)) {
                $cc = preg_replace('#^cc:(.*)#si', '\\1', $header);
            } else {
                if (preg_match('#^bcc:#si', $header)) {
                    $bcc = preg_replace('#^bcc:(.*)#si', '\\1', $header);
                    $header = '';
                }
            }
            $headers .= $header != '' ? $header . "\r\n" : '';
        }
        $headers = chop($headers);
        $cc = explode(', ', $cc);
        $bcc = explode(', ', $bcc);
    }
    if (trim($subject) == '') {
        echo 'No email Subject specified<br />';
    }
    if (trim($message) == '') {
        echo 'Email message was blank<br />';
    }
    if (!($socket = @fsockopen($smtp_host, 25, $errno, $errstr, 20))) {
        echo "Could not connect to smtp host : {$errno} : {$errstr}<br />";
    }
    server_parse($socket, "220", __LINE__);
    if (!empty($smtp_username) && !empty($smtp_password)) {
        fputs($socket, "HELO " . $smtp_host . "\r\n");
        server_parse($socket, "250", __LINE__);
        fputs($socket, "AUTH LOGIN\r\n");
        server_parse($socket, "334", __LINE__);
        fputs($socket, base64_encode($smtp_username) . "\r\n");
        server_parse($socket, "334", __LINE__);
        fputs($socket, base64_encode($smtp_password) . "\r\n");
        server_parse($socket, "235", __LINE__);
    } else {
        fputs($socket, "HELO " . $smtp_host . "\r\n");
        server_parse($socket, "250", __LINE__);
    }
    fputs($socket, "MAIL FROM: <" . $absender . ">\r\n");
    server_parse($socket, "250", __LINE__);
    $to_header = '';
    $mail_to = trim($mail_to) == '' ? 'Undisclosed-recipients:;' : trim($mail_to);
    if (preg_match('#[^ ]+\\@[^ ]+#', $mail_to)) {
        fputs($socket, "RCPT TO: <{$mail_to}>\r\n");
        server_parse($socket, "250", __LINE__);
    }
    @reset($bcc);
    if (isset($bcc)) {
        while (list(, $bcc_address) = each($bcc)) {
            $bcc_address = trim($bcc_address);
            if (preg_match('#[^ ]+\\@[^ ]+#', $bcc_address)) {
                fputs($socket, "RCPT TO: <{$bcc_address}>\r\n");
                server_parse($socket, "250", __LINE__);
            }
        }
    }
    @reset($cc);
    if (isset($cc)) {
        while (list(, $cc_address) = each($cc)) {
            $cc_address = trim($cc_address);
            if (preg_match('#[^ ]+\\@[^ ]+#', $cc_address)) {
                fputs($socket, "RCPT TO: <{$cc_address}>\r\n");
                server_parse($socket, "250", __LINE__);
            }
        }
    }
    fputs($socket, "DATA\r\n");
    server_parse($socket, "354", __LINE__);
    fputs($socket, "Subject: {$subject}\r\n");
    fputs($socket, "To: {$mail_to}\r\n");
    fputs($socket, "{$headers}\r\n\r\n");
    fputs($socket, "{$message}\r\n");
    fputs($socket, ".\r\n");
    server_parse($socket, "250", __LINE__);
    fputs($socket, "QUIT\r\n");
    fclose($socket);
    return true;
//.........这里部分代码省略.........
开发者ID:kveldscholten,项目名称:Ilch-1.1,代码行数:101,代码来源:smtp.php

示例14: smtpmail

function smtpmail($mail_to, $subject, $message, $headers = '')
{
    global $config;
    $SEND = "Date: " . date("D, d M Y H:i:s") . " UT\r\n";
    $SEND .= "Subject: {$subject}\r\n";
    if ($headers) {
        $SEND .= $headers . "\r\n\r\n";
    } else {
        $SEND .= "Reply-To: " . $config['smtp_username'] . "\r\n";
        $SEND .= "MIME-Version: 1.0\r\n";
        $SEND .= "Content-Type: text/plain; charset=\"" . $config['smtp_charset'] . "\"\r\n";
        $SEND .= "Content-Transfer-Encoding: 8bit\r\n";
        $SEND .= "From: \"" . $config['smtp_from'] . "\" <" . $config['smtp_username'] . ">\r\n";
        $SEND .= "To: {$mail_to} <{$mail_to}>\r\n";
        $SEND .= "X-Priority: 3\r\n\r\n";
    }
    $SEND .= $message . "\r\n";
    if (!($socket = fsockopen($config['smtp_host'], $config['smtp_port'], $errno, $errstr, 30))) {
        if ($config['smtp_debug']) {
            echo $errno . "&lt;br&gt;" . $errstr;
        }
        return false;
    }
    if (!server_parse($socket, "220", __LINE__)) {
        return false;
    }
    fputs($socket, "HELO " . $config['smtp_host'] . "\r\n");
    if (!server_parse($socket, "250", __LINE__)) {
        if ($config['smtp_debug']) {
            echo '<p>Íå ìîãó îòïðàâèòü HELO!</p>';
        }
        fclose($socket);
        return false;
    }
    fputs($socket, "AUTH LOGIN\r\n");
    if (!server_parse($socket, "334", __LINE__)) {
        if ($config['smtp_debug']) {
            echo '<p>Íå ìîãó íàéòè îòâåò íà çàïðîñ àâòîðèçàöè.</p>';
        }
        fclose($socket);
        return false;
    }
    fputs($socket, base64_encode($config['smtp_username']) . "\r\n");
    if (!server_parse($socket, "334", __LINE__)) {
        if ($config['smtp_debug']) {
            echo '<p>Ëîãèí àâòîðèçàöèè íå áûë ïðèíÿò ñåðâåðîì!</p>';
        }
        fclose($socket);
        return false;
    }
    fputs($socket, base64_encode($config['smtp_password']) . "\r\n");
    if (!server_parse($socket, "235", __LINE__)) {
        if ($config['smtp_debug']) {
            echo '<p>Ïàðîëü íå áûë ïðèíÿò ñåðâåðîì êàê âåðíûé! Îøèáêà àâòîðèçàöèè!</p>';
        }
        fclose($socket);
        return false;
    }
    fputs($socket, "MAIL FROM: <" . $config['smtp_username'] . ">\r\n");
    if (!server_parse($socket, "250", __LINE__)) {
        if ($config['smtp_debug']) {
            echo '<p>Íå ìîãó îòïðàâèòü êîììàíäó MAIL FROM: </p>';
        }
        fclose($socket);
        return false;
    }
    fputs($socket, "RCPT TO: <" . $mail_to . ">\r\n");
    if (!server_parse($socket, "250", __LINE__)) {
        if ($config['smtp_debug']) {
            echo '<p>Íå ìîãó îòïðàâèòü êîììàíäó RCPT TO: </p>';
        }
        fclose($socket);
        return false;
    }
    fputs($socket, "DATA\r\n");
    if (!server_parse($socket, "354", __LINE__)) {
        if ($config['smtp_debug']) {
            echo '<p>Íå ìîãó îòïðàâèòü êîììàíäó DATA</p>';
        }
        fclose($socket);
        return false;
    }
    fputs($socket, $SEND . "\r\n.\r\n");
    if (!server_parse($socket, "250", __LINE__)) {
        if ($config['smtp_debug']) {
            echo '<p>Íå ñìîã îòïðàâèòü òåëî ïèñüìà. Ïèñüìî íå áûëî îòïðàâëåííî!</p>';
        }
        fclose($socket);
        return false;
    }
    fputs($socket, "QUIT\r\n");
    fclose($socket);
    return TRUE;
}
开发者ID:HomelessCoder,项目名称:sacp,代码行数:94,代码来源:smtp-func.php

示例15: smtpmail

function smtpmail($mail_to, $subject, $message, $headers = "")
{
    // For now I'm using an array based $smtp_vars to hold the smtp server
    // info, but it should probably change to $board_config...
    // then the relevant info would be $board_config['smtp_host'] and
    // $board_config['smtp_port'].
    global $board_config;
    //
    // Fix any bare linefeeds in the message to make it RFC821 Compliant.
    //
    $message = preg_replace("/(?<!\r)\n/si", "\r\n", $message);
    if ($headers != "") {
        if (is_array($headers)) {
            if (sizeof($headers) > 1) {
                $headers = join("\r\n", $headers);
            } else {
                $headers = $headers[0];
            }
        }
        $headers = chop($headers);
        //
        // Make sure there are no bare linefeeds in the headers
        //
        $headers = preg_replace("/(?<!\r)\n/si", "\r\n", $headers);
        //
        // Ok this is rather confusing all things considered,
        // but we have to grab bcc and cc headers and treat them differently
        // Something we really didn't take into consideration originally
        //
        $header_array = explode("\r\n", $headers);
        @reset($header_array);
        $headers = "";
        while (list(, $header) = each($header_array)) {
            if (preg_match("/^cc:/si", $header)) {
                $cc = preg_replace("/^cc:(.*)/si", "\\1", $header);
            } else {
                if (preg_match("/^bcc:/si", $header)) {
                    $bcc = preg_replace("/^bcc:(.*)/si", "\\1", $header);
                    $header = "";
                }
            }
            $headers .= $header . "\r\n";
        }
        $headers = chop($headers);
        $cc = explode(",", $cc);
        $bcc = explode(",", $bcc);
    }
    if (trim($mail_to) == "") {
        message_die(GENERAL_ERROR, "No email address specified", "", __LINE__, __FILE__);
    }
    if (trim($subject) == "") {
        message_die(GENERAL_ERROR, "No email Subject specified", "", __LINE__, __FILE__);
    }
    if (trim($message) == "") {
        message_die(GENERAL_ERROR, "Email message was blank", "", __LINE__, __FILE__);
    }
    $mail_to_array = explode(",", $mail_to);
    //
    // Ok we have error checked as much as we can to this point let's get on
    // it already.
    //
    if (!($socket = fsockopen($board_config['smtp_host'], 25, $errno, $errstr, 20))) {
        message_die(GENERAL_ERROR, "Could not connect to smtp host : {$errno} : {$errstr}", "", __LINE__, __FILE__);
    }
    server_parse($socket, "220");
    if (!empty($board_config['smtp_username']) && !empty($board_config['smtp_password'])) {
        // Send the RFC2554 specified EHLO.
        // This improved as provided by SirSir to accomodate
        // both SMTP AND ESMTP capable servers
        fputs($socket, "EHLO " . $board_config['smtp_host'] . "\r\n");
        server_parse($socket, "250");
        fputs($socket, "AUTH LOGIN\r\n");
        server_parse($socket, "334");
        fputs($socket, base64_encode($board_config['smtp_username']) . "\r\n");
        server_parse($socket, "334");
        fputs($socket, base64_encode($board_config['smtp_password']) . "\r\n");
        server_parse($socket, "235");
    } else {
        // Send the RFC821 specified HELO.
        fputs($socket, "HELO " . $board_config['smtp_host'] . "\r\n");
        server_parse($socket, "250");
    }
    // From this point onward most server response codes should be 250
    // Specify who the mail is from....
    fputs($socket, "MAIL FROM: <" . $board_config['board_email'] . ">\r\n");
    server_parse($socket, "250");
    // Specify each user to send to and build to header.
    $to_header = "To: ";
    @reset($mail_to_array);
    while (list(, $mail_to_address) = each($mail_to_array)) {
        //
        // Add an additional bit of error checking to the To field.
        //
        $mail_to_address = trim($mail_to_address);
        if (preg_match('/[^ ]+\\@[^ ]+/', $mail_to_address)) {
            fputs($socket, "RCPT TO: <{$mail_to_address}>\r\n");
            server_parse($socket, "250");
        }
        $to_header .= ($mail_to_address != '' ? ', ' : '') . "<{$mail_to_address}>";
    }
//.........这里部分代码省略.........
开发者ID:BackupTheBerlios,项目名称:limb-svn,代码行数:101,代码来源:smtp.php


注:本文中的server_parse函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。