note 65528 deleted from function.getmxrr by bjori
| From: | bjori@php.net | Date: | Tue, 02 May 2006 20:58:44 +0000 |
| Subject: | note 65528 deleted from function.getmxrr by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-110395@lists.php.net to get a copy of this message | ||
Note Submitter: liviumacoviciuc2000 at yahoo dot com
Reason: bad code
----
It seems that everybody complains about the fact that Windows does not have a getmxrr() function. I
am not sure that this is really the case(Microsoft has an old habit of not publicly documenting some
of Windows's functions).
So, try this :
$con=fsockopen('smtp.' .$hostname);
It works on all versions of Windows, including 9x, but sometimes it fails - I don't know why
,but I think that the quality of the results depends on the quality of the DNS server that your ISP
provides you.
Since a getmxrr function is usually needed for writing a mailing function, and nobody is providing
such a function, I am giving you a basic one here :
function mymail($to,$from,$exp,$subj,$mesaj)
{
//*****************************************
//Mail function created by Liviu Macoviciuc , liviumacoviciuc2000@yahoo.com
//Use this function however you like ,but please keep the comment
//*****************************************
$mes=explode("\r\n",$mesaj);
$to=trim($to);
$temp=explode("@",$to);
//Linux version
//$a=getmxrr($temp[1],$host);
//if($a){$server=$host[0];}
//else{$server=$temp[1];}
//$con=fsockopen($server,25,$erno,$erstr);
$con=fsockopen('smtp.'.$temp[1],25,$erno,$erstr);
if(!$con){file_put_contents("raport.txt","$erno $erstr
$to\r\n",FILE_APPEND);
}
else{$read=fgets($con);
echo($read);
//$loc=$_SERVER['SERVER_NAME'];
fputs($con,"EHLO as.ro\r\n");
do{$read=fgets($con);
echo($read);
if(strpos($read,"-")===FALSE){break;};
}while(!feof($con));
fputs($con,"MAIL FROM:<".$from.">\r\n");
$read=fgets($con);
echo($read);
fputs($con,"RCPT TO:<".$to.">\r\n");
$read=fgets($con);
echo($read);
fputs($con,"DATA\r\n");
$read=fgets($con);
echo($read);
fputs($con,"MIME-Version:1.0\r\n");
fputs($con,"Date:".date("r")."\r\n");
fputs($con,"Subject:".$subj."\r\n");
fputs($con,"From:".$exp."\r\n");
fputs($con,"Reply-to:".$from."\r\n");
fputs($con,"To:".$to."\r\n");
fputs($con,"Content-Type:text/html\r\n");
fputs($con,"\r\n");
for($i=0;$i<count($mes);$i++){
fputs($con,"$mes[$i]\r\n");
}
fputs($con,"\r\n.\r\n");
$read=fgets($con);
echo($read);
fputs($con,"QUIT\r\n");
$read=fgets($con);
echo($read);
fclose($con);
}
}
Example of usage :
mymail('anunt@as.ro', 'liviumacoviciuc2000@yahoo.com', "Liviu
Macoviciuc", 'C.V. - curriculum vitae', "<html>..</html>");