php - Problems receiving email -


function socketmail($to,$subject,$message,$headers,$debug=0)

{global $mailfrom; $from=$mailfrom;  list($me,$mydomain) = split("@",$from);  // mail exchangers recipient  list($user,$domain) = split("@",$from,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 $host)  {     // open smtp connection     //echo "$host to: $to<hr>";     //print "smtp: $host\n";      $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 $mydomain\n");     $res=fgets($connection,256);     if(substr($res,0,3) != "250") break;      // envelope     fputs($connection, "mail from: $from\n");     $res=fgets($connection,256);     if(substr($res,0,3) != "250") break;      // envelope     fputs($connection, "rcpt to: $to\n");     $res=fgets($connection,256);     //print "response: $res\n";     if(substr($res,0,3) != "250") break;      // message     fputs($connection, "data\n");     $res=fgets($connection,256);     if(substr($res,0,3) != "354") break;      // send to:, from:, subject:, other headers, blank line, message, , finish     // period on own line.     fputs($connection, "to: $to\r\nfrom: $from\r\nsubject: $subject\r\n$headers\r\n\r\n$message\r\n.\r\n");     $res=fgets($connection,256);     if(substr($res,0,3) != "250") break;      // bye bye     fputs($connection,"quit\n");     $res=fgets($connection,256);     if(substr($res,0,3) != "221") break;      // worked! break out of loop tries mail exchangers.     $success=1;     break; }   // debug if fall on - uncomment desired if($debug)  {     print $success?"mail sent":"failure: $res\n";     die(0); } if($connection)  {     if($success==0)          fputs($connection, "quit\n");     fclose ($connection); } return $success?true:false; 

there code. problem here :

fputs($connection, "rcpt to: $to\n"); $res=fgets($connection,256); //print "response: $res\n"; if(substr($res,0,3) != "250") break; 

if change break continue, works, want warning if email not sent. if test error message is: failure: 553 sorry, domain isn't in list of allowed rcpthosts (#5.7.1).

can me? thanks!

a 553 error happens when mail server restricted being open relay (which thing or forward email on internet). typically, when use mail(), you're using local server's mta (if linux, sendmail). remote server can't used send email in way. either or need contact remote server , either whitelist server script running on (preferred) or allow domains you're trying send in relay (which allow relay domains)

out of curiosity, why aren't using mail()? simpler opening raw socket.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -

php - Accessing static methods using newly created $obj or using class Name -