$domain = "nerdalert.biz";
$SMTP = fsockopen($domain, 25);
$InputBuffer[] = fgets($SMTP, 1024);
fputs($SMTP, "HELO " . $domain);
$InputBuffer[] = fgets($SMTP, 1024);
fputs($SMTP, "MAIL From: $FromEmail");
$InputBuffer[] = fgets($SMTP, 1024);
fputs($SMTP, "RCPT To: $ToEmail");
$InputBuffer[] = fgets($SMTP, 1024);
fputs($SMTP, "DATA");
$InputBuffer[] = fgets($SMTP, 1024);
fputs($SMTP, "$Header");
fputs($SMTP, "From: $FromName <$FromEmail>");
fputs($SMTP, "To: $ToName <$ToEmail>");
fputs($SMTP, "Subject: $Subject");
fputs($SMTP, "$Body.");
fputs($SMTP, "QUIT");
$InputBuffer[] = fgets($SMTP, 1024);
fclose($SMTP);
print_r($InputBuffer);
but it cooks for few minutes and doesnt return anything. However when
I run this:
$domain = "nerdalert.biz";
$SMTP = fsockopen($domain, 25);
$InputBuffer[] = fgets($SMTP, 1024);
print_r($InputBuffer);
I got this:
: Array ( [0] => 220 nerdalert-1 ESMTP )
It seems like the function freezes up on the first "fputs". Why is
that? Is there any other way I can get this done?
Thank you
Michael G.
Because its waiting for a CR/LF pair to mark the end of line, that's why.
Look up RFC 821and get the SMTP protocol implemented PROPERLY.
http://www.faqs.org/rfcs/rfc821.html
The fputs() isn't sending the correct line end character. You need to
use fwrite() and terminate with "\r\n", i.e.
fwrite($SMTP, "HELO $domain\r\n");
Be sure you end your data with a single line containing only a period ('.').
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstu...@attglobal.net
==================
> Hi, I want to write a function that connects to any given SMTP server
> and runs some commands. I tried this:
>
> $domain = "nerdalert.biz";
> $SMTP = fsockopen($domain, 25);
>
> $InputBuffer[] = fgets($SMTP, 1024);
>
> fputs($SMTP, "HELO " . $domain);
Concatenation is superflous with double-quoted strings and variables.
> $InputBuffer[] = fgets($SMTP, 1024);
> fputs($SMTP, "MAIL From: $FromEmail");
See?
> $InputBuffer[] = fgets($SMTP, 1024);
> fputs($SMTP, "RCPT To: $ToEmail");
> $InputBuffer[] = fgets($SMTP, 1024);
> fputs($SMTP, "DATA");
> $InputBuffer[] = fgets($SMTP, 1024);
> fputs($SMTP, "$Header");
> fputs($SMTP, "From: $FromName <$FromEmail>");
> fputs($SMTP, "To: $ToName <$ToEmail>");
> fputs($SMTP, "Subject: $Subject");
> fputs($SMTP, "$Body.");
> fputs($SMTP, "QUIT");
> $InputBuffer[] = fgets($SMTP, 1024);
> fclose($SMTP);
> print_r($InputBuffer);
>
> but it cooks for few minutes and doesnt return anything. However when
> I run this:
>
> $domain = "nerdalert.biz";
> $SMTP = fsockopen($domain, 25);
> $InputBuffer[] = fgets($SMTP, 1024);
> print_r($InputBuffer);
>
> I got this:
>
> : Array ( [0] => 220 nerdalert-1 ESMTP )
>
> It seems like the function freezes up on the first "fputs". Why is
> that?
You are not observing protocol.
First of all, if you send HELO (and there is no intrinsic protocol
requirement to do that, although many MTAs demand it on VRFY, MAIL FROM or
later), you need to use the host name of the *client* MTA as parameter (to
authenticate *yourself*), and the client's IP address should have a PTR DNS
resource record that matches your HELO parameter. IOW, you are not to say
"HELO Alice" to Alice in SMTP (she knows her name already, that's how you
found her), but "HELO(, I'm) Bob" (so that Alice knows whom she is talking
to; AIUI `Received' header fields of e-mails are added using that
information).
Second, you are not sending the trailing CRLF delimiter.
Third, you need to *wait* for the server response before you send a new
command, and you need to *branch* for possible response status codes.
Capturing the output and going on like nothing happened is simply not enough
to make this work.
The syntax of the MAIL FROM, RCPT TO, and DATA commands in your
implementation is also incorrect (as for DATA, unless $Body already ends
with CRLF). Read RFC 2821/5321.
> Is there any other way I can get this done?
There are certainly better tools to do this. I have written an e-mail
address checker that uses Tcl/expect to talk SMTP over telnet. Dealing with
grey- and blacklisting is the hard part. For example, you can pretty much
forget nowadays to do SMTP from a dynamic IP address; most of those address
ranges are blacklisted by Firewalls or MTAs to prevent spamming (or chances
are you are talking to a honey pot/net ;-)) And many MTAs use greylisting
to fight spammers, so you won't be able to send your message in the first
pass.
But since you do want to send an e-mail, why are you trying to reinvent the
wheel? Is this homework?
PointedEars
--
var bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16