Beispiel #1
0
 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;
 }
Beispiel #2
0
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();
        }
    }
    fputs($socket, "QUIT\r\n");
    fclose($socket);
    return true;
}
Beispiel #3
0
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;
}
Beispiel #4
0
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;
}
Beispiel #5
0
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}>, ";
    }
    // 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");
        }
    }
    @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");
        }
    }
    // 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");
    // Send the Subject Line...
    fputs($socket, "Subject: {$subject}\r\n");
    // Now the To Header.
    fputs($socket, "{$to_header}\r\n");
    // Now any custom headers....
    fputs($socket, "{$headers}\r\n\r\n");
    // Ok now we are ready for the message...
    fputs($socket, "{$message}\r\n");
    // Ok the all the ingredients are mixed in let's cook this puppy...
    fputs($socket, ".\r\n");
    server_parse($socket, "250");
    // Now tell the server we are done and close the socket...
    fputs($socket, "QUIT\r\n");
    fclose($socket);
    return TRUE;
}
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__);
    // Send the Subject Line...
    fputs($socket, "Subject: {$subject}\r\n");
    // Now the To Header.
    fputs($socket, "To: {$mail_to}\r\n");
    // Now any custom headers....
    fputs($socket, "{$headers}\r\n\r\n");
    // Ok now we are ready for the message...
    fputs($socket, "{$message}\r\n");
    // Ok the all the ingredients are mixed in let's cook this puppy...
    fputs($socket, ".\r\n");
    server_parse($socket, "250", __LINE__);
    // Now tell the server we are done and close the socket...
    fputs($socket, "QUIT\r\n");
    fclose($socket);
    return TRUE;
}
Beispiel #7
0
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;
}
Beispiel #8
0
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;
}
Beispiel #9
0
/**
 * 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;
        // 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['maillist_mail_from']) ? $webmaster_email : $modSettings['maillist_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 . $line_break);
        if (strlen($mail_to) > 0) {
            fputs($socket, 'To: <' . $mail_to . '>' . $line_break);
        }
        fputs($socket, $headers . $line_break . $line_break);
        fputs($socket, $message . $line_break);
        // Send a ., or in other words "end of data".
        if (!server_parse('.', $socket, '250')) {
            return false;
        }
        // track the number of emails sent
        if (!empty($modSettings['trackStats'])) {
            trackStats(array('email' => '+'));
        }
        // Keep our post via email log
        if (!empty($unq_head)) {
            $sent[] = array($unq_head, time(), $mail_to);
        }
        // Almost done, almost done... don't stop me just yet!
        @set_time_limit(300);
        if (function_exists('apache_reset_timeout')) {
            @apache_reset_timeout();
        }
    }
    // say our goodbyes
    fputs($socket, 'QUIT' . $line_break);
    fclose($socket);
    // Log each email
    if (!empty($sent)) {
        require_once SUBSDIR . '/Maillist.subs.php';
        log_email($sent);
    }
    return true;
}
Beispiel #10
0
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;
}
Beispiel #11
0
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']) {
            echo '<p>Не могу отправить тело письма. Письмо не было отправлено!</p>';
        }
        fclose($socket);
        return false;
    }
    fputs($socket, "QUIT\r\n");
    fclose($socket);
    return TRUE;
}
Beispiel #12
0
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';
}
Beispiel #13
0
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;
}
Beispiel #14
0
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;
}
Beispiel #15
0
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}>";
    }
    // 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");
        }
    }
    @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");
        }
    }
    // 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");
    // Send the Subject Line...
    fputs($socket, "Subject: {$subject}\r\n");
    // Now the To Header.
    fputs($socket, "{$to_header}\r\n");
    // Now any custom headers....
    fputs($socket, "{$headers}\r\n\r\n");
    // Ok now we are ready for the message...
    fputs($socket, "{$message}\r\n");
    // Ok the all the ingredients are mixed in let's cook this puppy...
    fputs($socket, ".\r\n");
    server_parse($socket, "250");
    // Now tell the server we are done and close the socket...
    fputs($socket, "QUIT\r\n");
    fclose($socket);
    return TRUE;
}
Beispiel #16
0
function smtpmail($config, $to, $subject, $body, $headers = null)
{
    // Fix any bare linefeeds in the message to make it RFC821 Compliant.
    $body = preg_replace("#(?<!\r)\n#si", "\r\n", $body);
    $cc = $bcc = array();
    if (isset($headers)) {
        $headers = rtrim($headers);
        // Make sure there are no bare linefeeds in the headers
        $headers = preg_replace('#(?<!\\r)\\n#si', "\r\n", $headers);
        if (preg_match('#^cc:\\s*(.*?)\\s*$#mi', $headers, $match)) {
            $cc = split(', *', $match[1]);
        }
        if (preg_match('#^bcc:\\s*(.*?)\\s*$#mi', $headers, $match)) {
            $bcc = split(', *', $match[1]);
            $headers = preg_replace('#^bcc:.*$#mi', '', $headers);
        }
    }
    if (trim($subject) == '') {
        return GalleryCoreApi::error(ERROR_PLATFORM_FAILURE, __FILE__, __LINE__, "No email Subject specified");
    }
    if (trim($body) == '') {
        return GalleryCoreApi::error(ERROR_PLATFORM_FAILURE, __FILE__, __LINE__, "Email message was blank");
    }
    // Connect
    list($config['smtp.host'], $port) = array_merge(explode(':', $config['smtp.host']), array(25));
    if (!($socket = fsockopen($config['smtp.host'], $port, $errno, $errstr, 20))) {
        return GalleryCoreApi::error(ERROR_PLATFORM_FAILURE, __FILE__, __LINE__, "Could not connect to smtp host : {$errno} : {$errstr}");
    }
    // Wait for reply
    $ret = server_parse($socket, "220");
    if ($ret) {
        return $ret->wrap(__FILE__, __LINE__);
    }
    // Do we want to use AUTH?, send RFC2554 EHLO, else send RFC821 HELO
    if (!empty($config['smtp.username']) && !empty($config['smtp.password'])) {
        fputs($socket, "EHLO " . $config['smtp.host'] . "\r\n");
        $ret = server_parse($socket, "250");
        if ($ret) {
            return $ret->wrap(__FILE__, __LINE__);
        }
        fputs($socket, "AUTH LOGIN\r\n");
        $ret = server_parse($socket, "334");
        if ($ret) {
            return $ret->wrap(__FILE__, __LINE__);
        }
        fputs($socket, base64_encode($config['smtp.username']) . "\r\n");
        $ret = server_parse($socket, "334");
        if ($ret) {
            return $ret->wrap(__FILE__, __LINE__);
        }
        fputs($socket, $config['smtp.password'] . "\r\n");
        // Already encoded
        $ret = server_parse($socket, "235");
        if ($ret) {
            return $ret->wrap(__FILE__, __LINE__);
        }
    } else {
        fputs($socket, "HELO " . $config['smtp.host'] . "\r\n");
        $ret = server_parse($socket, "250");
        if ($ret) {
            return $ret->wrap(__FILE__, __LINE__);
        }
    }
    // From this point onward most server response codes should be 250
    // Specify who the mail is from....
    fputs($socket, "MAIL FROM: <" . $config['smtp.from'] . ">\r\n");
    $ret = server_parse($socket, "250");
    if ($ret) {
        return $ret->wrap(__FILE__, __LINE__);
    }
    // Add an additional bit of error checking to the To field.
    $to = trim($to) == '' ? 'Undisclosed-recipients:;' : trim($to);
    if (preg_match('#[^ ]+\\@[^ ]+#', $to)) {
        fputs($socket, "RCPT TO: <{$to}>\r\n");
        $ret = server_parse($socket, "250");
        if ($ret) {
            return $ret->wrap(__FILE__, __LINE__);
        }
    }
    // Ok now do the CC and BCC fields...
    foreach (array_merge($cc, $bcc) as $address) {
        $address = trim($address);
        if (preg_match('#[^ ]+\\@[^ ]+#', $address)) {
            fputs($socket, "RCPT TO: <{$address}>\r\n");
            $ret = server_parse($socket, "250");
            if ($ret) {
                return $ret->wrap(__FILE__, __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.
    $ret = server_parse($socket, "354");
    if ($ret) {
        return $ret->wrap(__FILE__, __LINE__);
    }
    // Send the Subject Line...
    fputs($socket, "Subject: {$subject}\r\n");
    // Now the To Header.
    fputs($socket, "To: {$to}\r\n");
    // Now any custom headers....
    if (isset($headers)) {
        fputs($socket, "{$headers}\r\n");
    }
    // Ok now we are ready for the message...
    fputs($socket, "\r\n{$body}\r\n");
    // Ok the all the ingredients are mixed in let's cook this puppy...
    fputs($socket, ".\r\n");
    $ret = server_parse($socket, "250");
    if ($ret) {
        return $ret->wrap(__FILE__, __LINE__);
    }
    // Now tell the server we are done and close the socket...
    fputs($socket, "QUIT\r\n");
    fclose($socket);
    return null;
}
Beispiel #17
0
function smtpmail($mail_to, $subject, $message, $headers = "")
{
    $message = preg_replace("/(?<!\r)\n/si", "\r\n", $message);
    $mailbox = EMAIL_SMTPAUTH_MAILBOX ? EMAIL_SMTPAUTH_MAILBOX : EMAIL_FROM;
    $mail_to_array = explode(",", $mail_to);
    if (!defined('EMAIL_SMTPAUTH_MAIL_SERVER_PORT')) {
        define('EMAIL_SMTPAUTH_MAIL_SERVER_PORT', '25');
    }
    if (!($socket = @fsockopen(EMAIL_SMTPAUTH_MAIL_SERVER, EMAIL_SMTPAUTH_MAIL_SERVER_PORT, $errno, $errstr, 20))) {
        $messageStack->add("ERROR: Could not connect to SMTP host : {$errno} : {$errstr}", 'error');
        return false;
    }
    server_parse($socket, "220");
    fputs($socket, "EHLO " . EMAIL_SMTPAUTH_MAIL_SERVER . "\r\n");
    server_parse($socket, "250");
    fputs($socket, "AUTH LOGIN\r\n");
    server_parse($socket, "334");
    fputs($socket, base64_encode($mailbox) . "\r\n");
    server_parse($socket, "334");
    fputs($socket, base64_encode(EMAIL_SMTPAUTH_PASSWORD) . "\r\n");
    server_parse($socket, "235");
    fputs($socket, "MAIL FROM: <" . EMAIL_FROM . ">\r\n");
    server_parse($socket, "250");
    $to_header = "To: ";
    @reset($mail_to_array);
    while (list(, $mail_to_address) = each($mail_to_array)) {
        $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}>";
    }
    fputs($socket, "DATA\r\n");
    server_parse($socket, "354");
    fputs($socket, "Subject: {$subject}\r\n");
    fputs($socket, "{$to_header}\r\n");
    fputs($socket, "{$headers}\r\n\r\n");
    fputs($socket, "{$message}\r\n");
    fputs($socket, ".\r\n");
    server_parse($socket, "250");
    fputs($socket, "QUIT\r\n");
    fclose($socket);
    return true;
}
Beispiel #18
0
function smtp_mail($to, $subject, $message, $headers = '')
{
    global $mailcfg;
    $recipients = explode(',', $to);
    if (!($socket = fsockopen($mailcfg['server'], $mailcfg['port'], $errno, $errstr, 15))) {
        error('Could not connect to smtp host "' . $mailcfg['server'] . '" (' . $errno . ') (' . $errstr . ')', __FILE__, __LINE__);
    }
    server_parse($socket, '220');
    if ($mailcfg['username'] != '' && $mailcfg['password'] != '') {
        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($mailcfg['username']) . "\r\n");
        server_parse($socket, '334');
        fwrite($socket, base64_encode($mailcfg['password']) . "\r\n");
        server_parse($socket, '235');
    } else {
        fwrite($socket, 'HELO ' . $mailcfg['port'] . "\r\n");
        server_parse($socket, '250');
    }
    fwrite($socket, 'MAIL FROM: <' . $mailcfg['username'] . '>' . "\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;
}