| px | top | add code | search | signup | login | help |
<?php
/********************
Direct Mail function 1.0
By Hamish Milne
bool mail_direct ( string $to , string $subject , string $message , string $from [, bool $talk [, string $headers ]] )
Unlike the PHP mail() function, mail_direct() does not require any extra binaries or an available SMTP server.
It uses the server local to the POP3 or IMAP account by using getmxrr() with it's domain.
This means that the email is delivered faster and more securely, directly into the inbox.
If you are on a Windows platform, you will need to include my WinDNS getmxrr() function which is on PX.
Parameters
These are the same as the php mail() function with a few differences:
$from Required for the SMTP protocol. The sender's adress
$talk If set to FALSE, will return a boolean value. If set to TRUE, returns the server's replies. Default is FALSE.
$headers The headers to send before the message. Default shows To, From and Subject.
Requires
Windows/BSD: WinDNS getmxrr() to work
PHP4
fsockopen()
********************/
//include('windns\getmxrr.php');
function mail_direct($to,$subject,$message,$from,$talk=0,$headers=''){
if(!$headers){
$headers="To: <$to>\r\nFrom: <$from>\r\nSubject: $subject\r\nMIME-Version: 1.0\r\n";
}
$mx=array();
$ed=explode('@',$to);
if(!$ed[1]){
return FALSE;
}
if(!@getmxrr($ed[1],$mx)){
return FALSE;
}
$sock=@fsockopen($mx[0],25);
if(!$sock){
return FALSE;
}
fputs($sock,"HELO ".$_SERVER['REMOTE_ADDR']."\r\n");
$t.=fgets($sock,256);
fputs($sock,"MAIL FROM: <$from>\r\n");
$t.=fgets($sock,256);
fputs($sock,"RCPT TO: <$to>\r\n");
$t.=fgets($sock,256);
fputs($sock,"DATA\r\n");
$t.=fgets($sock,256);
fputs($sock,"$headers\r\n$message\r\n.\r\n");
$r=fgets($sock,256);
$t.=$r;
fputs($sock,"QUIT\r\n");
$t.=fgets($sock,256);
fclose($sock);
return($talk?$t:($r{0}=='2'?TRUE:FALSE));
}
?>
Comments or questions?
PX is running PHP 5.2.11
Thanks to Miranda Productions for hosting and bandwidth.
Use of any code from PX is at your own risk.