Create email address account php - php

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

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?

Related

Bounce invalid dynamic email address from PHP through postfix pipe

I have a web application in PHP that allows users to create documents and send them as PDF attached to an email.
Originally, it was sent with a reply-to pointing to the user's email address, but I am implementing an internal email address system. The goal is to keep all the replies to the original email related to a specific document in the application.
All internal addresses start with PREFIX followed by delimiter "-". Postfix processes all email sent to PREFIX#mydomain.com through a pipe to a PHP script that tries to match the address to a specific user and document (eg: PREFIX-U1A-DJX8#mydomain.com refers to document JX8 of user 1A)
Everything works well but I am wondering how to handle invalid emails:
When no document is found related to the address, it is most probably spam.
However it's possible someone manually wrote the address and was mistaken, in that case the sender should be notified.
Should I simply send a generic mail from the PHP script to the sender stating the address is invalid?
Or is there a way to send a bounce either through the script or to tell postfix to handle it?

MediaWiki: multiple recipients when user changes email

I'm running a wiki based on mediawiki 1.21.11. Because I can't prevent users to change their e-mail address, I want to get informed (e.g. by mail) about this change.
My question: is there any possibility to send e. g. a copy of the notification mail or another notification including the old or new e-mail address to a specified recipient when users change their e-mail address?
You can prevent users from changing their email address with an auth plugin, although it seems like a horrible thing to do. You can use some hook to send you notifications - PrefsEmailAudit or UserSetEmail if you don't require confirmations, ConfirmEmailComplete if you do.

Email to trigger PHP Script... Possible?

I'm in need of setting up an auto-response from an email account that I control, based on trigger words within the body of the email. But also, it needs to add/delete rows from a database table based on trigger words sent to this email account (that belongs to my site) and it needs to create a topic, in some cases, within a forum, if sent to a different email address (but on the same server). I know PHP to be able to do this, but not really sure how to trigger a PHP script to be executed when an email gets sent to a specific email address account that I control. Or if there is another solution to accomplish this, please let me know.
This is basically an inquiry on how to accomplish something like this, based on an email sent to a specific email address on my server with words like: "Join", "Leave", "Set Mail", "Set Digest", etc. etc.
There will be another email address account set aside that will need to send those subscribers in the database, the same exact email (Mass Send). This is for a CDB-L ListServ. Kind of old school I suppose, but we want to transfer this ability to our server, since these old school methods still work today and is very much active.
Curious on security issues, what type of server software I'll need and just a basic approach on how to set something like this up.
You can alias your email address directly to a php script if you run your own mail server (on linux this would just be in the /etc/alias file or equivalent where the target was your php script instead of an email address) eg http://www.topwebhosts.org/bbs/board.php?bo_table=server_mgmt&wr_id=73
If not, then your only real choice is to set up a php process that checks an email address for mail every x minutes.
I have used both these methods over the years to great success
You can walk through emails with PHP's IMAP functions and undertake action (based on conditions/content). More info.

Update an email id using PHP

Is there a way in PHP to update an email id in a mail server if we have the access details of the mail server. The requirement is as follows.
I am developing a community website which need a provision to upload photos to their photo gallery by sending an email. We planned to create email id for each user so that they could send emails with photo attachments to that id. A cron job will search for emails inside those id's and if it finds a mail with attachment, uploads the file to the server and subject of the email will be considered as the photo caption.
But it has a security loophole such that anyone who knows the email id can send an email and add photo to others account. We are planning to have a security code in their id which can be modified by user if required.
eg. name.XXXX#domain.com where XXXX is a four digit secret code. THe user can change that code whenever required. i.e. the email id can be name.1234#domain.com or name.3452#domain.com according to the user's wish to maintain privacy. So is there a way to edit the email id using PHP functions.
Creating email accounts and/or aliases would certainly be possible with PHP, but it would depend so much on your server setup.
Another route to consider would be to not have any real email boxes, but to instead have all email delivered to a catch-all account and have your cron script search through that one mailbox and compare all recipient addresses against a database, then you don't have to worry about actually creating real email users on the server.
Additionally, in terms of improving security, you could have each user authenticate which sender email addresses are allowed to send emails with photo attachments. It's still not bullet-proof, because sender addresses can be spoofed, but it's an extra step in the right direction.

How do I set up an inbound mail controller so users can post to unique email address?

Tumblr (the short form blogging platform) has a feature where you are given a unique email address (for example, f3sf16a#tumblr.com) that you can email text or images and it automatically formats it into a post for you (as long as the sending email address matches your account email address).
I'd let to set up something similar, but solely as a method to submit images. Ideally, when a user signs up to my site, I'd create a unique address for them and store it in my db (MySQL). If a user emails a photo to that address using the email address they signed up with, i'd route it to a PHP function that breaks it down and handles the upload of content to their account.
How would I go about setting something like this up? Would it be something at the DNS level, or Apache level? Would I need to create a "safe list" of all the "real" email accounts on my domain to pass it through first? Also, I'm using Google Apps for email on this domain, will I need to create some sort of filter on that end?
Any ideas/suggestions would be awesome!
There's another quick and dirty way to make this work...
Setup a "catch-all" address for your domain. In other words, setup your domain so that e-mail sent to any address at the domain automatically gets forward to one catch-all address (i.e. global#mydomain.com).
Then, on the PHP side... Setup a script that periodically checks the e-mail in the global#mydomain.com box. Be sure to check the "To:" field so that you can identify which specific user the message was intended for.
Hope this helps!
It would be at the MTA level. Most MTAs have a facility whereby an email can be piped to an external program; this program would then parse the email and store the image.

Categories