Linux за българи: Форуми

Програмиране => Web development => Темата е започната от: Йордан в Apr 11, 2004, 20:01



Титла: PHP
Публикувано от: Йордан в Apr 11, 2004, 20:01
Zdraweite
imam edin wapros s pomo6ta na mail()
4rez nego se izpra6tat maili na potrebiteli samo na sa6tiq sarwar
nqkoi moje li da mi kaje kakwo da polzwam za da moga da pra6tam na drugi sarwari
ili trqbwa da se wazpolzwam ot wazmojnostite na IMAP

a i iskam da popitam nqkoi ima li info za t.n. dinami4no konfigorirane na PHP interpretatora


Титла: PHP
Публикувано от: в Apr 11, 2004, 23:05
ne e verno :) kak 6te se pra6tam samo na sa6tiq server :p pak za dinami4no confane si ima edni funkcii deto gleda6 koe e ON koe OFF i si gi zadava6 dopalnitelno primerno :)


Титла: PHP
Публикувано от: Йордан в Apr 12, 2004, 10:40
ami kato pra6tam kam abv.bg ne pristigat mail'lowete
da de gledam gi s phpinfo()
ama neznam kak da gi smenqm :)


Титла: PHP
Публикувано от: sunhater в Apr 12, 2004, 21:01
Можеш да пращаш през някой SMTP сървър както при email клиентите. Ето ти разработен клас за създаване и пращане през SMTP email:
Примерен код
class smtp_mail {
    var $fp = false;
    var $lastmsg = "";

    var $smtp_server;
    var $from;
    var $to;
    var $subject;
    var $body;
    
    function smtp_mail($smtp_server = "", $from = "", $to = "", $subject = "", $body = "") {
        $this->smtp_server = $smtp_server;
        $this->from = $from;
        $this->to = $to;
        $this->subject = $subject;
        $this->body = $body;
    }

    function add_body($body) {
        return "Content-Type: text/plain; charset=\"Windows-1251\"\nContent-Transfer-Encoding: 7bit\n\n$body\n";
    }

    function get_mail() {
        $mime = "";
        if (!empty($this->from)) $mime .= "From: " . $this->from . "\n";
        if (!empty($this->to)) $mime .= "To: " . $this->to . "\n";
        if (!empty($this->subject)) $mime .= "Subject: " . $this->subject . "\n";
        if (!empty($this->body)) $mime .= $this->add_body($this->body);
        return $mime;
    }

    function read_line() {
        $ret = false;
        $line = fgets($this->fp, 1024);
        if (ereg("^([0-9]+).(.*)$", $line, &$data)) {
            $recv_code = $data[1];
            $recv_msg = $data[2];
            $ret = array($recv_code, $recv_msg);
        }
        return $ret;
    }

    function dialogue($code, $cmd) {
        $ret = true;
        fwrite($this->fp, $cmd . "\r\n");
        $line = $this->read_line($this->fp);
        if ($line == false) {
            $ret = false;
            $this->lastmsg = "";
        } else {
            $this->lastmsg = "$line[0] $line[1]";
            if ($line[0] != $code) $ret = false;
        }
        return $ret;
    }

    function error_message() {
        echo "SMTP protocol failure (" . $this->lastmsg . ").<BR>";
    }

    function crlf_encode($data) {
        $data .= "\n";
        $data = str_replace("\n", "\r\n", str_replace("\r", "", $data));
        $data = str_replace("\n.\r\n", "\n. \r\n", $data);
        return $data;
    }

    function handle_email($from, $to, $data) {
            global $SERVER_NAME;
        $rcpts = explode(",", $to);
        $err = false;
        if (!$this->dialogue(250, "HELO $SERVER_NAME") ||
            !$this->dialogue(250, "MAIL FROM: $from")) $err = true;
        for ($i = 0; !$err && $i < count($rcpts); $i++)
            if (!$this->dialogue(250, "RCPT TO: $rcpts[$i]"))
                $err = true;
        if ($err ||
            !$this->dialogue(354, "DATA") ||
            !fwrite($this->fp, $data) ||
            !$this->dialogue(250, ".") ||
            !$this->dialogue(221, "QUIT")) $ret = true;
        if ($err) $this->error_message();
        return !$err;
    }

    function connect($hostname) {
            $ret = false;
            $this->fp = fsockopen($hostname, 25);
            if ($this->fp) $ret = true;
            return $ret;
    }

    function send_email() {
        if (!$this->connect($this->smtp_server)) return false;
        $line = $this->read_line();
        $ret = false;
        if ($line && $line[0] == "220") {
            $data = $this->crlf_encode($this->get_mail());
            $ret = $this->handle_email($this->from, $this->to, $data);
        } else $this->error_message();
        fclose($this->fp);
        return $ret;
    }
}

За да създадеш и пратиш email:
Примерен код
$mail = new smtp_mail(<SMTP_Server>, <Email_FROM>, <Email_TO>, <Subject>, <Message>);
if (!($mail->send_email())) {
    // Ако има грешка при пращането:
    echo "Error sending mail!";
}


Титла: PHP
Публикувано от: Йордан в Apr 13, 2004, 15:23
mersi mnogo
nadqwam se towa da mi swar6i rabota :)