Re: [PHP] Sending e-mail via socket
On 02/23/2010 01:16 AM, 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. Have you figured it out yet? I have written a SMTP function a couple of years ago which will talk to any SMTP server directly via socket. The only limitation I have noticed is that it does not support encrypted logins but that can be added, I just never bothered to do it. So let me know if you still require it and I'll dig it out. -- John Ihr führt Krieg? Ihr fürchtet euch vor einem Nachbarn? So nehmt doch die Grenzsteine weg - so habt ihr keinen Nachbarn mehr. Aber ihr wollt den Krieg und deshalb erst setztet ihr die Grenzsteine. [Friedrich Nietzsche] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re[2]: [PHP] Sending e-mail via socket
Hello Rene, Can't do that since the message is personalized: I need to put in the user name ("Hello $username") and some other data, so the BCC is not a solution, unfortunately... -- With best regards from Ukraine, Andre Skype: Francophile; Wlm&MSN: arthaelon @ yandex.ru; Jabber: arthaelon @ jabber.org Yahoo! messenger: andre.polykanine; ICQ: 191749952 Twitter: m_elensule - Original message - From: Rene Veerman To: Andre Polykanine Date: Tuesday, February 23, 2010, 2:58:41 AM Subject: [PHP] Sending e-mail via socket have you tried mail() with a large bcc header? On Tue, Feb 23, 2010 at 1:16 AM, 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 "; > $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 ("arthae...@yandex.ru", "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? > > Thanks! > > -- > With best regards from Ukraine, > Andre > Http://oire.org/ - The Fantasy blogs of Oire > Skype: Francophile; Wlm&MSN: arthaelon @ yandex.ru; Jabber: arthaelon @ > jabber.org > Yahoo! messenger: andre.polykanine; ICQ: 191749952 > Twitter: http://twitter.com/m_elensule > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Sending e-mail via socket
Paul M Foster wrote: > 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. Even if the mailserver does pipelining, he'll still need to do the EHLO separately and wait for the response to see if it does. After that you can fire off everything in one go. /Per -- Per Jessen, Zürich (7.8°C) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Sending e-mail via socket
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. Use sendmail to drop the emails straight into your MTA queue. /Per -- Per Jessen, Zürich (6.9°C) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Sending e-mail via socket
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 "; > $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 ("arthae...@yandex.ru", "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
Re: [PHP] Sending e-mail via socket
have you tried mail() with a large bcc header? On Tue, Feb 23, 2010 at 1:16 AM, 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 "; > $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 ("arthae...@yandex.ru", "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? > > Thanks! > > -- > With best regards from Ukraine, > Andre > Http://oire.org/ - The Fantasy blogs of Oire > Skype: Francophile; Wlm&MSN: arthaelon @ yandex.ru; Jabber: arthaelon @ > jabber.org > Yahoo! messenger: andre.polykanine; ICQ: 191749952 > Twitter: http://twitter.com/m_elensule > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Sending e-mail via socket
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: "; $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 ("arthae...@yandex.ru", "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? Thanks! -- With best regards from Ukraine, Andre Http://oire.org/ - The Fantasy blogs of Oire Skype: Francophile; Wlm&MSN: arthaelon @ yandex.ru; Jabber: arthaelon @ jabber.org Yahoo! messenger: andre.polykanine; ICQ: 191749952 Twitter: http://twitter.com/m_elensule -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php