<?
function another_mail($to,$subject,$headers,$message)
{
// Could get this from the php ini?
$from="me@here.com";
list($me,$mydomain) = split("@",$from);
// Now look up the mail exchangers for the recipient
list($user,$domain) = split("@",$to,2);
if(getmxrr($domain,$mx,$weight) == 0) return FALSE;
// Try them in order of lowest weight first
array_multisort($mx,$weight);
$success=0;
foreach($mx as $host) {
// Open an SMTP connection
$connection = fsockopen ($host, 25, &$errno, &$errstr, 1);
if (!$connection)
continue;
$res=fgets($connection,256);
if(substr($res,0,3) != "220") break;
// Introduce ourselves
fputs($connection, "HELO $mydomainn");
$res=fgets($connection,256);
if(substr($res,0,3) != "250") break;
// Envelope from
fputs($connection, "MAIL FROM: $fromn");
$res=fgets($connection,256);
if(substr($res,0,3) != "250") break;
// Envelope to
fputs($connection, "RCPT TO: $ton");
$res=fgets($connection,256);
if(substr($res,0,3) != "250") break;
// The message
fputs($connection, "DATAn");
$res=fgets($connection,256);
if(substr($res,0,3) != "354") break;
// Send To:, From:, Subject:, other headers, blank line, message, and finish
// with a period on its own line.
fputs($connection, "To: $tonFrom: $fromnSubject: $subjectn$headersnn$messagen.n");
$res=fgets($connection,256);
if(substr($res,0,3) != "250") break;
// Say bye bye
fputs($connection,"QUITn");
$res=fgets($connection,256);
if(substr($res,0,3) != "221") break;
// It worked! So break out of the loop which tries all the mail exchangers.
$success=1;
break;
}
// Debug for if we fall over - uncomment as desired
// print $success?"Mail sent":"Failure: $resn";
if($connection) {
if($success==0) fputs($connection, "QUITn");
close ($connection);
}
return $success?TRUE:FALSE;
}
another_mail("recipient@some.domain","My Subject","X-mailer: PHP ScriptnX-another-header: Whatever","Test email body.nnNote if you actually put a period on a linenby itself, the function will terminate prematurely.nnYou will get a partial email sent though.n");
?>
function another_mail($to,$subject,$headers,$message)
{
// Could get this from the php ini?
$from="me@here.com";
list($me,$mydomain) = split("@",$from);
// Now look up the mail exchangers for the recipient
list($user,$domain) = split("@",$to,2);
if(getmxrr($domain,$mx,$weight) == 0) return FALSE;
// Try them in order of lowest weight first
array_multisort($mx,$weight);
$success=0;
foreach($mx as $host) {
// Open an SMTP connection
$connection = fsockopen ($host, 25, &$errno, &$errstr, 1);
if (!$connection)
continue;
$res=fgets($connection,256);
if(substr($res,0,3) != "220") break;
// Introduce ourselves
fputs($connection, "HELO $mydomainn");
$res=fgets($connection,256);
if(substr($res,0,3) != "250") break;
// Envelope from
fputs($connection, "MAIL FROM: $fromn");
$res=fgets($connection,256);
if(substr($res,0,3) != "250") break;
// Envelope to
fputs($connection, "RCPT TO: $ton");
$res=fgets($connection,256);
if(substr($res,0,3) != "250") break;
// The message
fputs($connection, "DATAn");
$res=fgets($connection,256);
if(substr($res,0,3) != "354") break;
// Send To:, From:, Subject:, other headers, blank line, message, and finish
// with a period on its own line.
fputs($connection, "To: $tonFrom: $fromnSubject: $subjectn$headersnn$messagen.n");
$res=fgets($connection,256);
if(substr($res,0,3) != "250") break;
// Say bye bye
fputs($connection,"QUITn");
$res=fgets($connection,256);
if(substr($res,0,3) != "221") break;
// It worked! So break out of the loop which tries all the mail exchangers.
$success=1;
break;
}
// Debug for if we fall over - uncomment as desired
// print $success?"Mail sent":"Failure: $resn";
if($connection) {
if($success==0) fputs($connection, "QUITn");
close ($connection);
}
return $success?TRUE:FALSE;
}
another_mail("recipient@some.domain","My Subject","X-mailer: PHP ScriptnX-another-header: Whatever","Test email body.nnNote if you actually put a period on a linenby itself, the function will terminate prematurely.nnYou will get a partial email sent though.n");
?>