0

I saw in some advertising websites, that when you want to send an email to the ad owner, it does not show the real email, but rather the email address under that website's domain(which definitely looks like auto-generated, rather than chosen by the user), say smth like n8MngCo5cHg@example.com.

So, AFA I understand, when an email is being sent to that address, it is being redirected to the ad owner's real email. I am trying to to do the same thing by php.

QSN1 By php script, how to create that email address for the user, when he registers ?

QSN2 Is there a way (again by code) to set up a forwarder, so emails sent to n8MngCo5cHg@example.com automatically will be redirected to user's real email user_email@gmail.com, or I should fetch emails by IMAP from time to time and send to to the user ? I am using apache2.x/Debian 7, if it matters.

These two questions I found, are for cpanel, but I am not using it or any other UI.

Create an email account with PhP - With some things I need to work around

Create emails accounts using PHP

Thanks

Community
  • 1
  • 1
dav
  • 8,931
  • 15
  • 76
  • 140
  • 1- Generate some random strings 2- Save both the real and generated user email in some table in database 3- When it is required to send the email fetch the real email using generated email from database – Qarib Haider Jul 14 '14 at 06:03
  • @SyedQarib, I understand the logic that u described, the questions is how to create the email address by php and is it possible to forward the email to the user's real email. – dav Jul 14 '14 at 06:05

1 Answers1

0

Here is one way that you can create an random 'alias' email address:

$aliasaddress=md5(uniqid(mt_rand(),1)) . "@example.com";

Then, as SyedQarib suggests, you would store the alias address and the actual address in a database, so that your program can get the actual address given an alias address.

Finally, you would need to setup your mail server with wildcarding such that it accepts messages to *@example.com, and forward each incoming message to your PHP script, so that for each incoming message to an alias address, your script would parse the incoming message, capture the alias address that it's addressed to, query the database to find the corresponding actual address, then forward the message to the actual address. For information on how to setup a mail server to forward incoming messages to a script, see http://harrybailey.com/2009/02/send-or-pipe-an-email-to-a-php-script/ or How to setup a mail server?

Community
  • 1
  • 1
mti2935
  • 11,465
  • 3
  • 29
  • 33