Hi everyone,

Iam mahendran and i working as a php programmer for the last 8months. I have a doubt to create mail ids in server dynamically using PHP.

I wants to write a program for generating alias email ids in server dynamically when user register into the site by giving his original id such as(yahoo,gmail,etc..). The created alias ids are given to other users whose see that user profile. The users can use this ailas id for send mails. if they send the mail they can goes to the original id of alias id of that user ....
this is my task.

user given originalid---makes--------> alias id---------------stored in server.

sending Mail----to------->alias id-----------search for---------->original id---------------->user inbox

Anyone have idea how to implement this by scripting please let me know. It is very useful for me.
Thanks to all

Sounds like you need something to generate a unique random user ID and associate it with the account you wish to use. Perl has just the right data type for that (oh shucks, this is PHP)... Uh Well you can still do it a couple different ways:

2-dimension array. Dimension 1 is the User ID and dimension 2 has the account info
multiple arrays: The index is the same for related info.

Hi everyone,

Iam mahendran and i working as a php programmer for the last 8months. I have a doubt to create mail ids in server dynamically using PHP.

I wants to write a program for generating alias email ids in server dynamically when user register into the site by giving his original id such as(yahoo,gmail,etc..). The created alias ids are given to other users whose see that user profile. The users can use this ailas id for send mails. if they send the mail they can goes to the original id of alias id of that user ....
this is my task.

user given originalid---makes--------> alias id---------------stored in server.

sending Mail----to------->alias id-----------search for---------->original id---------------->user inbox

Anyone have idea how to implement this by scripting please let me know. It is very useful for me.
Thanks to all

Hello Mahendran,

I believe you want to create a system to where an email sent to user@yourdomain.com is forwarded to user@yahoo.com ?

You'll first need to save the users id, email id (on your domain) and real email in your database. That way you can reference te users real email in the database from their id, or a random email id generated for your domain.
To create a radom number is simple, see the rand() function: http://www.php.net/rand or mt_rand() which is faster.
Most random number generation uses something like:

$seed = mt_rand();
$random_number = sha1(time().$seed); // less subject to brute force

This is better since someone utilizing brute force or a dictionary type attack to get the emails has to "guess" two things: time() and mt_rand() which are enclosed in a non-reversable hash: sha1().

The real questions for implementing what you want are:

1) do you want to set up an email for each user on your site?
2) Do you want to set up a forwarder for each users email on your site?

If you want to set up an email for all users on your site, then you can easily set up a forwarder, that will forward the users email to say username@yahoo.com
Setting up emails and forwarders can be done dynamically when a user registers, its platform dependant though.

An easier way to have everything handles by php is to just route all your incoming mail to your domain to a php script, then have the php script forward email for you to the appropriate email address.

To have all your incoming mail sent to a php script, you need to set up a catch-all email address, and set up a forwarder that will send (pipe) all this mail to the php script.

A good reference is here: http://evolt.org/incoming_mail_and_php
Or you can query "email piping to php".

When your php script receives the email, it can check for the "to" header which should be something like user@yoursite.com and check with your database as to the email to forward to, eg: user@yahoo.com
To forward the email just mail it.. see mail() function in php.net manual.

----

However, a much easier thing to do is to just set up a form on the users profile page that sends email to the user.
That way you can also limit that page to say members only of your site.

If you create an email id for each user on your domain, and it forwards to the users real email, it still is sending email to the user and still subject to spam, even though the sender does not know the users real email address..

Hai Ether,

Thanku for your great reply. I really understood the concepts. Also now i have been working with these concepts in my project. I already send a personal message to you. Once again I thanku.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.