On Tue, Feb 23, 2010 at 02:16:24AM +0200, Andre Polykanine wrote: > Hello everyone, > I've just subscribed to the list, and I already have a question. > what I need to do is to send mail using sockets. Actually, the > built-in Mail() function is great and I wouldn't have to search for > something else if I didn't need more than one message to be sent at a > time. Say, I have ten or a hundred of users who want to receive a > notification about new blog entries. If I use the mail() function in > the loop, it will be performed too slow since it constantly opens and > closes the door, I mean, the SMTP connection. > So I need an alternative. > And here's what I'm doing: > > <? > function socketmail($to, $subject, $message) { > $from="Oire.org Administration <elensule@xxxxxxxx>"; > $connect = fsockopen ("smtp.yandex.ru", 25, $errno, $errstr, 30); > if ($connect) { > $out="HELO localhost\r\n"; > $out.="MAIL FROM: $from\n"; > $out.="RCPT TO: $to\n"; > $out.="DATA\r\n"; > $out.="Content-Type: text/plain; charset=utf-8\n"; > $out.="To: $to\n"; > $out.="Subject: $subject\n"; > $out.="\n\n"; > $out.=$message." \r\n"; > $out.=".\r\n"; > $out.="RSET\r\n"; > fwrite ($connect, $out); > fclose ($connect); > } else { > die ("Error: ".$errstr." ($errno)"); > } > } > > socketmail ("arthaelon@xxxxxxxxx", "this is a socket mail test", > "Testing mail sending"); > ?> > > And what I get is absolutely nothing. No errors, no warnings, no > message in the mailbox. > So three questions: > 1. What's wrong with my script? > 2. How to look where the error exactly is? Can't get server logs for > some reason (will talk to tech support probably). > 3. How to do the same thing but with an ability to send multiple > messages without closing the connection after each message? First, if you're using the mail() function to talk to a *local* SMTP server, you shouldn't have a long lag at all. The local SMTP server should queue the messages and deal with the remote connections on its own time, withough blocking.. Second, you're doing this socket operation as though it's a static one-sided conversation. I'm not an expert, but SMTP conversations don't normally work this way. You issue the HELO, wait for the response, issue other commands, wait for the response, etc. The way you're doing it, if your SMTP conversation runs into any snags (like the RCPT TO is not recognized), you won't know it. Your function will simply ride over the error, because it's not listening to the SMTP server. Again, I'm not an expert, so maybe there's something I've overlooked. Paul -- Paul M. Foster -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php