php->mail

Sem dobrej mám zdroják na odesílání mailů pomocí smtp libovolného serveru....
kdyby někdo měl zájem ať napíše sem nebo mě na mail...
Pošli mi zdrojový kód!!!
myslim, ze zajemcu bude dost. mozna by jsi mohl to dat do txt souboru na svuj web prostor a hodit sem nekam link... pak to snad najdou lidi i pomoci fce hledat ;~)

m.sa.
<?php

/*
* save as "smtp_mail.inc"
*/

class smtp_mail {
var $fp = false;
var $lastmsg = "";

/*
* read_line() reads a line from the socket
* and returns the numeric code and the rest of the line
*/

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;
}

/*
* dialogue() sends a command $cmd to the remote server
* and checks whether the numeric return code is the one
* we expect ($code).
*/

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;
}

/*
* error_message() prints out an error message,
* including the last message received from the SMTP server.
*/

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

/*
* crlf_encode() fixes line endings
* RFC 788 specifies CRLF (hex 0x13 0x10) as line endings
*/

function crlf_encode($data)
{
# make sure that the data ends with a newline character
$data .= "\n";
# remove all CRs and replace single LFs with CRLFs
$data = str_replace("\n", "\r\n", str_replace("\r", "", $data));
# in the SMTP protocol a line consisting of a single "." has
# a special meaning. We therefore escape it by appending one space.
$data = str_replace("\n.\r\n", "\n. \r\n", $data);

return $data;
}

/*
* handle_e-mail() talks to the SMTP server
*/

function handle_e-mail($from, $to, $data)
{
# split recipient list
$rcpts = explode(",", $to);

$err = false;
if(!$this->dialogue(250, "HELO phpclient") ||
!$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")) {
$err = true;
}

if($err) {
$this->error_message();
}

return !$err;
}

/*
* connect() connects to an SMTP server on the well-known port 25
*/

function connect($hostname)
{
$ret = false;

$this->fp = fsockopen($hostname, 25);

if($this->fp) {
$ret = true;
}

return $ret;
}

/*
* send_e-mail() connects to an SMTP server, encodes the message
* optionally, and sends $data. The envelope sender address
* is $from. A comma-separated list of recipients is expected in $to.
*/

function send_e-mail($hostname, $from, $to, $data, $crlf_encode = 0)
{
if(!$this->connect($hostname)) {
echo "cannot open socket<br>\n";
return false;
}

$line = $this->read_line();
$ret = false;

if($line && $line[0] == "220") {
if($crlf_encode) {
$data = $this->crlf_encode($data);
}

$ret = $this->handle_e-mail($from, $to, $data);
} else {
$this->error_message();
}

fclose($this->fp);

return $ret;
}
}
?>
<?

// store as "mime_mail.inc"

class mime_mail
{
var $parts;
var $to;
var $from;
var $headers;
var $subject;
var $body;

/*
* void mime_mail()
* class constructor
*/

function mime_mail() {
$this->parts = array();
$this->to = "";
$this->from = "";
$this->subject = "";
$this->body = "";
$this->headers = "";
}

/*
* void add_attachment(string message, [string name], [string ctype])
* Add an attachment to the mail object
*/

function add_attachment($message, $name = "", $ctype = "application/octet-stream") {
$this->parts[] = array (
"ctype" => $ctype,
"message" => $message,
"encode" => $encode,
"name" => $name
);
}

/*
* void build_message(array part=
* Build message parts of an multipart mail
*/

function build_message($part) {
$message = $part[ "message"];
$message = chunk_split(base64_encode($message));
$encoding = "base64";
return "Content-Type: ".$part[ "ctype"].
($part[ "name"]? "; name = \"".$part[ "name"].
"\"" : "").

"\nContent-Transfer-Encoding: $encoding\n\n$message\n";
}

/*
* void build_multipart()
* Build a multipart mail
*/

function build_multipart() {
$boundary = "b".md5(uniqid(time()));
$multipart =
"Content-Type: multipart/mixed; boundary = $boundary\n\nThis is a MIME encoded message.\n\n--$boundary";

for($i = sizeof($this->parts)-1; $i >= 0; $i--)
{
$multipart .= "\n".$this->build_message($this->parts[$i]).
"--$boundary";
}
return $multipart.= "--\n";
}

/*
* string get_mail()
* returns the constructed mail
*/

function get_mail($complete = true) {
$mime = "";
if (!empty($this->from))
$mime .= "From: ".$this->from. "\n";
if (!empty($this->headers))
$mime .= $this->headers. "\n";

if ($complete) {
if (!empty($this->to)) {
$mime .= "To: $this->to\n";
}
if (!empty($this->subject)) {
$mime .= "Subject: $this->subject\n";
}
}

if (!empty($this->body))
$this->add_attachment($this->body, "", "text/plain");
$mime .= "MIME-Version: 1.0\n".$this->build_multipart();

return $mime;
}

/*
* void send()
* Send the mail (last class-function to be called)
*/

function send() {
$mime = $this->get_mail(false);
mail($this->to, $this->subject, "", $mime);
}
}; // end of class

?>
<?php

include "mime_mail.inc";
include "smtp_mail.inc";

# our relaying SMTP server
$smtp_server = "smtpserver";
# the sender address
$from = "odkoho";
# the recipient(s)
$to = "komu";
# the subject of the e-mail
$subject = "predmet";
# ... and its body
$body = "tetst";

# create mime_mail instance

$mail = new mime_mail;

$mail->from = $from;
$mail->to = $to;
$mail->subject = $subject;
$mail->body = $body;

# get the constructed e-mail data

$data = $mail->get_mail();

# create smtp_mail instance

$smtp = new smtp_mail;

# send e-mail

$smtp->send_e-mail($smtp_server, $from, $to, $data);

?>

Užívejte si:-))) Ale pozor zatím to moc nefunguje jsou tam asi dvě chyby které jsem nestačil opravit:-(((
proboha!!!!! precti si jeste jednou co jsem napsal: "mozna by jsi mohl to dat do txt souboru na svuj web prostor a hodit sem nekam link"... mira ted ma urcite radost :~)
jinak nemyslel jsem na sebe (fce mail mam moznost si uzivat dosytosti), ale na zoufalce, co tu kazdej treti den resi jestli funguje fce mail()...

m.sa.
Tak ať má radost...;~)
Sakra už jsem se naučil ty tvoje smaili:-)))
Proč říkáš že jsi dobrej ?
Až to naprogramuješ sám, tak budeš dobrej...
tohle je nějaký source opsaný z knížky nebo z NETu....

Na posílání mailů nepotřebuju žádnou spec. fci !
Stačí Mail() ....
chtěl bych vidět někoho, kdo posílá > 20 mailů za den

u navstevovanejsich stranej nejaky rozesilani novinek, after-registracni maily, zapomenuty hesla, atd., v maillistu mas vic, jak dvacet lidi a ses v pytli...
Ale presne tohle jsem hledal, tak dik :)
no lukasik je dobrej proto, ze to dokazal vyhrabat a dat k dispozici ;)(i kdyz pekne debilnim zpusobem). ja jsem se zmohl maximalne na teorii a ani nikdo jinej sem nedal nejakej vysledek s pokusy ;) takze pomohl tem lidem, kteri tady stale rvou po odesilani emailu, ale jsou "too stupid" si to naprogramovat sami a "too lazy" si to najit uz hotove...

jasne, ze na posilani mailu staci mail(), ale pokud nemas spravne nastavene php.ini, nebo se proste nemuze php dostat na smtp server, je toto uzitecna vec. jinak 20mailu za den se ti zda prilis??? jsem zvedavej, kolik emailu bude rozesilat tvuj budouci portal ;)
pokud ti na stranky prijde par lidi, tak to staci. ale jsou i pripady, kdy chces delat registraci uzivatelu (napr. eshop, freesluzba, portaly :) a potom potrebujes odeslat minimalne jeden email (ale vetsinou dva) s potvrzenou registraci - nechces snad nutit uzivatele vsechny logovaci udaje si tupe opisovat :~)

jen snad jeste naokraj - nedavejte administratorum duvod zakazovat fci fsockopen() - pls!!!

m.sa.
No tak nějak a někdo říkal že jsem to psal?
Je to vytáhlí z knihy programujeme php profesionálně fakt bych mohl doporučit mnohemn lepší než od koska...
Pokud jde o tu knihu, tak bych si dovolil nesouhlasit :). Koskova kniha mi prijde podstatne uzitecnejsi (strucna a jasna) ... dobra i pro zacatecnika.
souhlasim... kniha od koska je mnohem lepsi (skoda ze jen pro php3:( v php profesionalne je dost nepresnosti a podle me kdyz to prezenu, je to jen ukazka zdrojaku jak to delaj jini - coz se da dnes najit vsude na netu. kosek to ale pise mnohem srozumitelneji hlavne pro zacatecniky a uplne lajky co si neumi predstavit funkci weboveho serveru, http protokolu a dalsiho s tim souvidejiciho...

m.sa.
co se tyce rychlosti odhaduju, ze bude nepostrehnutelny rozdil. je to proste rozepsana cinnost funkce mail() a chova se to temer uplne stejne - predava data na port25 SMTP serveru ;~)

m.sa.
Já jsem se něco podobný pokoušel udělat sám ale nějak to......................
Ano pro začátečníka se mi taky zdá lepší od koska ale kdo už zná minimálně základy tak je tahle vhodnější...