Forum Webscript.Ru

Программирование => PHP => Тема начата: tarya от 15 Марта 2004, 11:08:08

Название: POP3 - fsockopen?
Отправлено: tarya от 15 Марта 2004, 11:08:08
Добрый день дорогие специалисты.

Вопрос вы следующем.

Возможно ли подключиться к ПОП серверу через fsockopen для того чтоб постучавшись на сервер попытаться отправить ему заголовок "письмо для Васи" и прочесть ответ - "Вася есть, давайте письмо", или "Васи то нету у нас".


С благодарностью, Таря.
Название: POP3 - fsockopen?
Отправлено: tarya от 15 Марта 2004, 11:13:22
я тут чтото такое нашел


function socketmail($server, $to, $from, $subject, $message) {
$connect = fsockopen ($server, 25, $errno, $errstr, 30);
fputs($connect, "HELO localhost\\r\\n");
fputs($connect, "MAIL FROM: $from\\n");
fputs($connect, "RCPT TO: $to\\n");
fputs($connect, "DATA\\r\\n");
fputs($connect, "Content-Type: text/plain; charset=iso-8859-1\\n");
fputs($connect, "To: $to\\n");
fputs($connect, "Subject: $subject\\n");
fputs($connect, "\\n\\n");
fputs($connect, stripslashes($message)." \\r\\n");
fputs($connect, ".\\r\\n");
fputs($connect, "RSET\\r\\n");
}
?>


интересно...,  но как например прописать $server  если у меня почта tarya@zapata.org.ua  а сам ПОП3 находтся на mail.iptelecom.net.ua как быть?...
Название: POP3 - fsockopen?
Отправлено: tarya от 15 Марта 2004, 11:25:47


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 $mydomain\\n");
  $res=fgets($connection,256);
  if(substr($res,0,3) != "250") break;

  // Envelope from
  fputs($connection, "MAIL FROM: $from\\n");
  $res=fgets($connection,256);
  if(substr($res,0,3) != "250") break;

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

  // The 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, and finish
  // with a period on its own line.
  fputs($connection, "To: $to\\nFrom: $from\\nSubject: $subject\\n$headers\\n\\n$message\\n.\\n");
  $res=fgets($connection,256);
  if(substr($res,0,3) != "250") break;

  // Say bye bye
  fputs($connection,"QUIT\\n");
  $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: $res\\n";
 if($connection) {
  if($success==0) fputs($connection, "QUIT\\n");
  fclose ($connection);
 }
 return $success?TRUE:FALSE;
}

another_mail("recipient@some.domain","My Subject","X-mailer: PHP Script\\nX-another-header: Whatever","Test email body.\\n\\nNote if you actually put a period on a line\\nby itself, the function will terminate prematurely.\\n\\nYou will get a partial email sent though.\\n");
?>


нашел кажись!
Название: POP3 - fsockopen?
Отправлено: ThE0ReTiC от 15 Марта 2004, 11:30:44
tarya
а какое отношение имеет POP3 протокол к этому потоку сознания?
ты ж с SMTP работаешь а не с POP3 =)
Название: POP3 - fsockopen?
Отправлено: tarya от 15 Марта 2004, 12:02:53
ну уже голова кипит, войдите в положение.