Page 1 of 2

Anonymous Email

Posted: Mon May 23, 2005 9:56 am
by lokesh
Hi,

I want to send anonymous email to anyone and receive private replies in their own inbox.

Any Idea how to do this.

Thanks,
Lokesh.

Posted: Mon May 23, 2005 12:29 pm
by Skara
I have no idea what you just said. You lost me at the private replies bit.
You can send an email so:

Code: Select all

mail($to, $subject, $message, $headers);
//e.g.
mail("anyone@somewhere.net",$sub,$msg,"From: anonymous@nowhere.net\nReply-To: anonymous@nowhere.net");
Hotmail and others don't like sendmail, though. An alternative is phpmailer.

Re: Anonymous Email

Posted: Mon May 23, 2005 1:06 pm
by Roja
lokesh wrote:Hi,

I want to send anonymous email to anyone
Can't. All emails have *some* level of accountability. You can make it so that its limited to "From this server", or "From this service", but can't really get truly anonymous. To do so, simply send it from theserver@example.com or whatever group mail account you like.
lokesh wrote:receive private replies in their own inbox.
Simply set the reply-to field to the user's email address.

Posted: Mon May 23, 2005 1:08 pm
by Burrito
you could set the reply-to header to an email address you create for them, and so if they hit reply, it would then send an email to that address. You could then have php pop to your mail server and grab the emails for those specific addresses and output it on an html page in their own "private" section.

let me know if you need any help with any of that, I recently did a project that did jsut that.

Posted: Tue May 24, 2005 8:25 am
by lokesh
Thanks for your response. Can I get the sample code. I want to implement this feature on my project.

Please let me know.

Thanks,
Lokesh.

Posted: Tue May 24, 2005 10:37 am
by Burrito
for which part do you need the code?

Posted: Tue May 24, 2005 11:29 am
by lokesh
For receiving private replies in their own inbox....

If user reply to anon-001@domain.com, email should go to clients own inbox...

Lokesh.

Posted: Tue May 24, 2005 11:33 am
by infolock
i really hope you aren't planning on using this for spam. i would then be forced to search and destroy you :twisted:

Posted: Tue May 24, 2005 11:44 am
by lokesh
really not I am builing classifieds forum. where people can post their classifieds. Some people wants to show up their email address and some don't. Please help me.

Thanks,
Lokesh.

Posted: Tue May 24, 2005 12:00 pm
by shiznatix

Code: Select all

mail($users_email, $subject, $messsage, "From: anonymous@nowhere.net\nReply-To: anonymous@nowhere.net");
?????

Posted: Tue May 24, 2005 12:05 pm
by lokesh
The code which you have sent is for sending I want for receiving in their own inbox.

Lokesh.

Posted: Tue May 24, 2005 12:13 pm
by Burrito
I have a meeting in 10 mins and as soon as I get out I will send you something you can use to pop to the mail server and retrieve mail for the users...

Posted: Tue May 24, 2005 2:54 pm
by lokesh
Hi Burrito,

Please let me know.

Lokesh.

Posted: Tue May 24, 2005 3:17 pm
by Burrito
Sorry this took so long to get to you...crazy meeting!

here are a couple of functions you can use to pop to a mail server and retreive mail *Note requires PEAR (don't know who originally authored them so can't give credit...sorry. I do know that I've completely butchered them to make sure they worked for me 8O ):

you're going to need to include two files from PEAR:

Code: Select all

// you need to set the constants...obviously
<?php
require_once('../includes/pop3.php');
require_once('Mail/mimeDecode.php'); //PEAR Mail_Mime Module
require_once('Mail/RFC822.php'); // PEAR Mail Module


error_reporting(E_ERROR);
  set_error_handler(&quote;emailErrorHandler&quote;);

tt_db_connect();

mysql_query(&quote;LOCK TABLE ttpop3last WRITE&quote;);
$getlastsql = &quote;SELECT lastretrieved FROM ttpop3last&quote;;
$getlasthandle = mysql_query($getlastsql)
  or trigger_error(&quote;Couldn't get last email time.&quote;, E_USER_ERROR);
$getlast = mysql_fetch_row($getlasthandle);
if (!$getlast || strtotime($getlastї0]) + POP3_WAIT <= time())
{
  $updatelastsql = $getlast ? &quote;UPDATE ttpop3last SET lastretrieved=NOW()&quote; : &quote;INSERT INTO ttpop3last (lastretrieved) VALUES (NOW())&quote;;
  mysql_query($updatelastsql);
  
  mysql_query(&quote;UNLOCK TABLES&quote;);
  
  $handle = pop3_connect(POP3_SERVER, POP3_PORT, POP3_USER, POP3_PASS, POP3_APOP)
    or trigger_error(&quote;Couldn't connect to pop3 server. Details: {$errstr}&quote;, E_USER_ERROR);
  
  $stats = pop3_stat($handle)
    or trigger_error(&quote;Couldn't execute stat command. Details: {$errstr}&quote;, E_USER_ERROR);
  
  if ($statsї'count'] > 0)
  {
    if ($messages = pop3_uidl($handle))
      $uidlist = TRUE;  //we have a unique id for each message now
    else
    {
      $uidlist = FALSE; //we do not have a unique id for each message yet
      $messages = pop3_list($handle)
        or trigger_error(&quote;Couldn't retrieve message list. Details: {$errstr}&quote;, E_USER_ERROR);
    }
    
    foreach($messages as $msgid => $extrainfo)
    {
      if (!$uidlist)
      {
        //don't want to retrieve extra messages unless we need to
        $message = pop3_retr($handle, $msgid);
        $messageuid = md5(implode('', $message));
      }
      else
      {
        $messageuid = trim($extrainfo);
      }
      
      $isuniquehandle = mysql_query(&quote;SELECT COUNT(id) FROM mailtable WHERE mailid='{$messageuid}'&quote;)
        or trigger_error(&quote;Couldn't select unique IDs.&quote;, E_USER_ERROR);
      $isunique = mysql_fetch_row($isuniquehandle);
      if ($isuniqueї0] == 0)
      {
        if ($uidlist)
        {
          if (($message = pop3_retr($handle, $msgid)) === FALSE) //retrieve message now since it wasn't done above
          {
            //we don't want to break the loop, there may just be something wrong with this message
            continue;
          }
        }
        $params = array();
        $paramsї'include_bodies'] = true;
        $paramsї'decode_bodies'] = true;
        $paramsї'decode_headers'] = true;
        $paramsї'input'] = implode('', $message);
        
        $structure = Mail_mimeDecode::decode($params);
        $subject = isset($structure->headersї'subject']) ? $structure->headersї'subject'] : '';
        $from = $structure->headersї'from'];
        $from = Mail_RFC822::parseAddressList($from, POP3_DEFHOST, FALSE, TRUE);
        $from = $fromї0]->mailbox . '@' . $fromї0]->host; //don't care about extra info
        $datesent = strtotime($structure->headersї'date']);
        $messageid = $structure->headersї'message-id'];
        
        $emailinfo = getEmail($structure);
        
        if (!isset($emailinfoї'text']))
        {
          $emailinfoї'text'] = isset($emailinfoї'html']) ? trim(unhtmlentities(strip_tags($emailinfoї'html']))) : &quote;No email content&quote;;
        }
        if (!isset($emailinfoї'html']))
        {
          $emailinfoї'html'] = isset($emailinfoї'text']) ? nl2br(htmlentities($emailinfoї'text'])) : &quote;No email content&quote;;
        }
        
       //lokesh....run your insert queries here
  
       
      if (POP3_DELETE)
        pop3_delete($handle, $msgid);
      mysql_free_result($isuniquehandle);
    } // end foreach message
  } // end if statsї'count'] > 0
  
  pop3_quit($handle);
} //end if last time is this time

mysql_query(&quote;UNLOCK TABLES&quote;);

header(&quote;Expires: Mon, 26 Jul 1997 05:00:00 GMT&quote;); 

// always modified 
header(&quote;Last-Modified: &quote; . gmdate(&quote;D, d M Y H:i:s&quote;) . &quote; GMT&quote;); 

// HTTP/1.1 
header(&quote;Cache-Control: no-store, no-cache, must-revalidate&quote;); 
header(&quote;Cache-Control: post-check=0, pre-check=0&quote;, false); 

// HTTP/1.0 
header(&quote;Pragma: no-cache&quote;); 

// tell it that this is a gif
header(&quote;Content-Type: image/gif&quote;);

readFile(&quote;../images/spacer.gif&quote;);

function emailErrorHandler($errno, $errstr, $errfile, $errline) 
{
  global $handle;
  pop3_quit($handle);
  
  mysql_query(&quote;UNLOCK TABLES&quote;);
  
  header(&quote;Expires: Mon, 26 Jul 1997 05:00:00 GMT&quote;); 
  
  // always modified 
  header(&quote;Last-Modified: &quote; . gmdate(&quote;D, d M Y H:i:s&quote;) . &quote; GMT&quote;); 
  
  // HTTP/1.1 
  header(&quote;Cache-Control: no-store, no-cache, must-revalidate&quote;); 
  header(&quote;Cache-Control: post-check=0, pre-check=0&quote;, false); 
  
  // HTTP/1.0 
  header(&quote;Pragma: no-cache&quote;); 
  
  // tell it that this is a gif
  header(&quote;Content-Type: image/gif&quote;);
  
  readFile(&quote;../images/spacer.gif&quote;);
  exit();
}


?>

Code: Select all

<?php
//pop3 stuff

$errno = '';
$errstr = '';

define('GETLENGTH', 512);
define('TIMEOUT', 200);

function pop3_connect($popserver, $popport, $username = '', $pass = '', $apop = FALSE, $echocmd = FALSE, $echortrn = FALSE)
{
  global $errno, $errstr;
  if (empty($username) || empty($pass))
  {
    $errno = -2;
    $errstr = &quote;Username and/or password not provided&quote;;
    return FALSE;
  }
  if ($echocmd) echo &quote;CONNECTING TO {$popserver}:{$popport}\n&quote;;
  $handle = fsockopen($popserver, $popport, $errno, $errstr);
  if (!$handle)
  {
    if ($echocmd) echo &quote;CONNECTION FAILED\n&quote;;
    return $handle;
  }
  stream_set_blocking($handle, TRUE);
  $response = fgets($handle, GETLENGTH);
  $response = pop3_killcrlf($response);
  if ($echortrn) echo &quote;REPLY: {$response}\n&quote;;
  if (!pop3_isGoodReply($response))
  {
    if ($echocmd || $echortrn) echo &quote;UNRECOGNIZED REPLY\n&quote;;
    pop3_quit($handle, $echocmd, $echortrn);
    $errno = -2;
    $errstr = &quote;Server returned this unrecognized response: {$response}&quote;;
    return FALSE;
  }
  $confString = preg_replace(&quote;/^\+OK\s+<(.+)>/&quote;, &quote;\\1&quote;, $response); //for apop
  
  $command = &quote;NOOP\r\n&quote;;
  fwrite($handle, $command, strlen($command));
  if ($echocmd) echo &quote;CMD: {$command}\n&quote;;
  $response = fgets($handle, GETLENGTH);
  $response = pop3_killcrlf($response);
  if ($echortrn) echo &quote;REPLY: {$response}\n&quote;;
  if (pop3_isGoodReply($response))
  {
    if ($echocmd || $echortrn) echo &quote;SERVER IS NOT RFC 1939 COMPLIANT\n&quote;;
    pop3_quit($handle, $echocmd, $echortrn);
    $errno = -2;
    $errstr = &quote;POP3 Server did not comply with RFC 1939 for NOOP before authentication: {$response}&quote;;
    return FALSE;
  }
  
  if (!$apop)
  {
    $command = &quote;USER {$username}\r\n&quote;;
    fwrite($handle, $command, strlen($command));
    if ($echocmd) echo &quote;CMD: {$command}\n&quote;;
    $response = fgets($handle, GETLENGTH);
    $response = pop3_killcrlf($response);
    if ($echortrn) echo &quote;REPLY: {$response}\n&quote;;
    if (!pop3_isGoodReply($response))
    {
      if ($echocmd || $echortrn) echo &quote;USERNAME DID NOT WORK\n&quote;;
      pop3_quit($handle, $echocmd, $echortrn);
      $errno = -2;
      $errstr = &quote;Username did not return OK: {$response}\n&quote;;
      return FALSE;
    }
    
    $command = &quote;PASS {$pass}\r\n&quote;;
    fwrite($handle, $command, strlen($command));
    if ($echocmd) echo &quote;CMD: {$command}\n&quote;;
    $response = fgets($handle, GETLENGTH);
    $response = pop3_killcrlf($response);
    if ($echortrn) echo &quote;REPLY: {$response}\n&quote;;
    if (!pop3_isGoodReply($response))
    {
      if ($echocmd || $echortrn) echo &quote;Password not authenticated\n&quote;;
      pop3_quit($handle, $echocmd, $echortrn);
      $errno = -2;
      $errstr = &quote;Username or password not authenticated: {$response}\n&quote;;
      return FALSE;
    }
  }
  else //apop
  {
    $confString .= $pass;
    $confString = md5($confString);
    $command = &quote;APOP {$username} {$confString}\r\n&quote;;
    fwrite($handle, $command, strlen($command));
    if ($echocmd) echo &quote;CMD: {$command}\n&quote;;
    $response = fgets($handle, GETLENGTH);
    $response = pop3_killcrlf($response);
    if ($echortrn) echo &quote;REPLY: {$response}\n&quote;;
    if (!pop3_isGoodReply($response))
    {
      if ($echocmd || $echortrn) echo &quote;APOP LOGIN FAILED\n&quote;;
      pop3_quit($handle, $echocmd, $echortrn);
      $errno = -2;
      $errstr = &quote;Apop login not authenticated: {$response}\n&quote;;
      return FALSE;
    }
  }
  
  //now do noop again just to be sure we're authenticated and the server works
  $command = &quote;NOOP\r\n&quote;;
  fwrite($handle, $command, strlen($command));
  if ($echocmd) echo &quote;CMD: {$command}\n&quote;;
  $response = fgets($handle, GETLENGTH);
  $response = pop3_killcrlf($response);
  if ($echortrn) echo &quote;REPLY: {$response}\n&quote;;
  if (!pop3_isGoodReply($response))
  {
    if ($echocmd || $echortrn) echo &quote;SERVER IS NOT RFC 1939 COMPLIANT\n&quote;;
    pop3_quit($handle, $echocmd, $echortrn);
    $errno = -2;
    $errstr = &quote;POP3 Server did not comply with RFC 1939 for NOOP after authentication: {$response}&quote;;
    return FALSE;
  }
  
  set_time_limit(TIMEOUT);
  
  return $handle;
}

function pop3_stat($handle, $echocmd = FALSE, $echortrn = FALSE)
{
  global $errno, $errstr;
  $command = &quote;STAT\r\n&quote;;
  fwrite($handle, $command, strlen($command));
  if ($echocmd) echo &quote;CMD: {$command}\n&quote;;
  $response = fgets($handle, GETLENGTH);
  $response = pop3_killcrlf($response);
  if ($echortrn) echo &quote;REPLY: {$response}\n&quote;;
  if (!pop3_isGoodReply($response))
  {
    if ($echocmd || $echortrn) echo &quote;Stat failed\n&quote;;
    $errno = -3;
    $errstr = &quote;Stat command failed: {$response}&quote;;
    return FALSE;
  }
  set_time_limit(TIMEOUT);
  
  $temp = explode(&quote; &quote;, $response);
  return array(&quote;count&quote; => intval($tempї1]), &quote;length&quote; => intval($tempї2]));
}

function pop3_list($handle, $msgNum = '', $echocmd = FALSE, $echortrn = FALSE)
{
  global $errno, $errstr;
  if (empty($msgNum))
  {
    $command = &quote;LIST\r\n&quote;;
    fwrite($handle, $command, strlen($command));
    if ($echocmd) echo &quote;CMD: {$command}\n&quote;;
    $response = fgets($handle, GETLENGTH);
    $response = pop3_killcrlf($response);
    if ($echortrn) echo &quote;REPLY: {$response}\n&quote;;
    if (!pop3_isGoodReply($response))
    {
      if ($echocmd || $echortrn) echo &quote;List failed\n&quote;;
      $errno = -3;
      $errstr = &quote;List command failed: {$response}&quote;;
      return FALSE;
    }
    
    $messages = array();
    while (preg_match(&quote;/^(\d+) (\d+)(.*)$/&quote;, fgets($handle, GETLENGTH), $lineInfo))
    {
      if ($echortrn) echo &quote;REPLY: {$lineInfoї0]}\n&quote;;
      $messagesїintval($lineInfoї1])] = intval($lineInfoї2]);
    }
    set_time_limit(TIMEOUT);
    
    return $messages;
  }
  else
  {
    $command = &quote;LIST {$msgNum}\r\n&quote;;
    fwrite($handle, $command, strlen($command));
    if ($echocmd) echo &quote;CMD: {$command}\n&quote;;
    $response = fgets($handle, GETLENGTH);
    $response = pop3_killcrlf($response);
    if ($echortrn) echo &quote;REPLY: {$response}\n&quote;;
    if (!pop3_isGoodReply($response))
    {
      if ($echocmd || $echortrn) echo &quote;List failed\n&quote;;
      $errno = -3;
      $errstr = &quote;List command failed: {$response}&quote;;
      return FALSE;
    }
    set_time_limit(TIMEOUT);
    
    $temp = explode(&quote; &quote;, $response);
    return array(&quote;msgid&quote; => $tempї1], &quote;size&quote; => $tempї2]);
  }
}

function pop3_retr($handle, $msgid, $echocmd = FALSE, $echortrn = FALSE)
{
  global $errno, $errstr;
  $command = &quote;RETR {$msgid}\r\n&quote;;
  fwrite($handle, $command, strlen($command));
  if ($echocmd) echo &quote;CMD: {$command}\n&quote;;
  $response = fgets($handle, GETLENGTH);
  $response = pop3_killcrlf($response);
  if ($echortrn) echo &quote;REPLY: {$response}\n&quote;;
  if (!pop3_isGoodReply($response))
  {
    if ($echocmd || $echortrn) echo &quote;Retr failed\n&quote;;
    $errno = -3;
    $errstr = &quote;Retr command failed: {$response}&quote;;
    return FALSE;
  }
  
  $msg = array();
  $line = fgets($handle, GETLENGTH);
  while (!preg_match(&quote;/^\.\r\n/&quote;, $line))
  {
    $msgї] = preg_replace(&quote;/^\.\./&quote;, &quote;.&quote;, $line);
    $line = fgets($handle, GETLENGTH);
    if (empty($line)) break;
  }
  set_time_limit(TIMEOUT);
  
  return $msg;
}

function pop3_delete($handle, $msgid, $echocmd = FALSE, $echortrn = FALSE)
{
  global $errno, $errstr;
  $command = &quote;DELE {$msgid}\r\n&quote;;
  fwrite($handle, $command, strlen($command));
  if ($echocmd) echo &quote;CMD: {$command}\n&quote;;
  $response = fgets($handle, GETLENGTH);
  $response = pop3_killcrlf($response);
  if ($echortrn) echo &quote;REPLY: {$response}\n&quote;;
  if (!pop3_isGoodReply($response))
  {
    if ($echocmd || $echortrn) echo &quote;Dele failed\n&quote;;
    $errno = -3;
    $errstr = &quote;Dele command failed: {$response}&quote;;
    return FALSE;
  }
  set_time_limit(TIMEOUT);
  
  return TRUE;
}

function pop3_reset($handle, $echocmd = FALSE, $echortrn = FALSE)
{
  global $errno, $errstr;
  $command = &quote;RSET\r\n&quote;;
  fwrite($handle, $command, strlen($command));
  if ($echocmd) echo &quote;CMD: {$command}\n&quote;;
  $response = fgets($handle, GETLENGTH);
  $response = pop3_killcrlf($response);
  if ($echortrn) echo &quote;REPLY: {$response}\n&quote;;
  if (!pop3_isGoodReply($response))
  {
    if ($echocmd || $echortrn) echo &quote;Rset failed\n&quote;;
    $errno = -3;
    $errstr = &quote;Rset command failed: {$response}&quote;;
    return FALSE;
  }
  set_time_limit(TIMEOUT);
  
  return TRUE;
}

function pop3_quit($handle, $echocmd = FALSE, $echortrn = FALSE)
{
  global $errno, $errstr;
  $command = &quote;QUIT\r\n&quote;;
  @fwrite($handle, $command, strlen($command));
  if ($echocmd) echo &quote;CMD: {$command}\n&quote;;
  $response = @fgets($handle, GETLENGTH);
  $response = pop3_killcrlf($response);
  if ($echortrn) echo &quote;REPLY: {$response}\n&quote;;
  @fclose($handle);
  return TRUE;
}

//optional functions - may not be implemented by server
function pop3_top($handle, $msgid, $numlines = '0', $echocmd = FALSE, $echortrn = FALSE)
{
  global $errno, $errstr;
  $command = &quote;TOP {$msgid} {$numlines}\r\n&quote;;
  fwrite($handle, $command, strlen($command));
  if ($echocmd) echo &quote;CMD: {$command}\n&quote;;
  $response = fgets($handle, GETLENGTH);
  $response = pop3_killcrlf($response);
  if ($echortrn) echo &quote;REPLY: {$response}\n&quote;;
  if (!pop3_isGoodReply($response))
  {
    if ($echocmd || $echortrn) echo &quote;Top failed\n&quote;;
    $errno = -3;
    $errstr = &quote;Top command failed: {$response}&quote;;
    return FALSE;
  }
  
  $msg = array();
  $line = fgets($handle, GETLENGTH);
  while (!preg_match(&quote;/^\.\r\n/&quote;, $line))
  {
    $msgї] = preg_replace(&quote;/^\.\./&quote;, &quote;.&quote;, $line);
    $line = fgets($handle, GETLENGTH);
    if (empty($line)) break;
  }
  set_time_limit(TIMEOUT);
  
  return $msg;
}

function pop3_uidl($handle, $msgid = '', $echocmd = FALSE, $echortrn = FALSE)
{
  global $errno, $errstr;
  if (empty($msgid))
  {
    $command = &quote;UIDL\r\n&quote;;
    fwrite($handle, $command, strlen($command));
    if ($echocmd) echo &quote;CMD: {$command}\n&quote;;
    $response = fgets($handle, GETLENGTH);
    $response = pop3_killcrlf($response);
    if ($echortrn) echo &quote;REPLY: {$response}\n&quote;;
    if (!pop3_isGoodReply($response))
    {
      if ($echocmd || $echortrn) echo &quote;Uidl failed\n&quote;;
      $errno = -3;
      $errstr = &quote;Uidl command failed: {$response}&quote;;
      return FALSE;
    }
    
    $messages = array();
    while (preg_match(&quote;/^(\d+) (.*)$/&quote;, fgets($handle, GETLENGTH), $lineInfo))
    {
      if ($echortrn) echo &quote;REPLY: {$lineInfoї0]}\n&quote;;
      $messagesїintval($lineInfoї1])] = $lineInfoї2];
    }
    set_time_limit(TIMEOUT);
    
    return $messages;
  }
  else
  {
    $command = &quote;UIDL {$msgid}\r\n&quote;;
    fwrite($handle, $command, strlen($command));
    if ($echocmd) echo &quote;CMD: {$command}\n&quote;;
    $response = fgets($handle, GETLENGTH);
    $response = pop3_killcrlf($response);
    if ($echortrn) echo &quote;REPLY: {$response}\n&quote;;
    if (!pop3_isGoodReply($response))
    {
      if ($echocmd || $echortrn) echo &quote;Uidl failed\n&quote;;
      $errno = -3;
      $errstr = &quote;Uidl command failed: {$response}&quote;;
      return FALSE;
    }
    set_time_limit(TIMEOUT);
    
    $temp = explode(&quote; &quote;, $response);
    return array(&quote;msgid&quote; => $tempї1], &quote;uid&quote; => $tempї2]);
  }
}

//helper functions
function pop3_isGoodReply($response = '')
{
  if (empty($response)) return false;
  if (preg_match(&quote;/^\+OK/&quote;, $response)) return true;
  return false;
}

function pop3_killcrlf($what)
{
  return preg_replace(&quote;/\r|\n/&quote;, '', $what);
}

Posted: Tue May 24, 2005 3:45 pm
by lokesh
Thank you so much I will let you know the status. Where will I find PEAR modules?

Lokesh