PHP to create email forwarding

Hello good people

I am trying to write a script that will create an email forwarding on the server.

The server is a UNIX based system but before I go into specifics I thought I would ask the question.

Scenario is this.

User wants an email address at john_smith@domain.com

They fill in a form requesting an email and the system searches to see if john_smith@domain.com exists and is available. If it is the script will create a forward for john_smith@domain.com to users_actual@googlemail_or_whatever.com

I can log into the providers panel and create an email forward manually but the question is, can PHP do this?

In hope

Keith

Hi Guys

The email domain will be hosted on the same server, yes.

What needs to be created is just the forwarding part of the email.

The reason is that my client has a prestigious domain and wants to make forwarding addresses and eventually a full email package. so in a nutshell he wants to have people come along and register as a user then once in the user can opt to have a forwarding address made.

The script which checks if a particular email address is taken, I can write but the question is can PHP create an email forwarding address. ie can it integrate with the host server and create a forwarding address.

If he’s using cPanel then yes he can.
Cpanel::email::addforward

If his server is using something else to manage his emails, then investigation into that other system needs to be attended to.

Im not sure what is being used. its hosted through media temple who seem to have their own panel but it may just be a rebrand. Thanks for the pointers. Your a diamond.

Regards

keith

Yes it can.

Verify a User’s Email Address Using PHP

That only checks if the domain exists, not the email.

There are plenty of examples out there.

Here is one that uses PHP to control telnet, and determines whether the email address (not just the domain) is valid or not.

How to check if an email address exists without sending an email?

It can’t determine 100%. It can tell you if it does exist, but not if it doesn’t.

Why exactly do you want to do this? You can either trust the user or require a confirmation email (which doesn’t mean much with mailinator etc). If it’s something critical like making sure certain emails get sent to certain addresses then you should use the mail server, not php.

Does it help to know that the email being checked is on the local domain?

If cPanel is being used for the server, then you have listpopswithdisk which can be used to get a list of emails.

So if it’s on the local server, it’s worth investigating techniques that apply to your server/email manager.

Needs more clarification from op, if the user is requesting name@myownsite.com to be forwarded to name@someothersite.com, then you don’t even need to bother with the mail server. But you still can’t guarantee name@someothersite.com exists.

(or is it about detecting user typos: oopsnotmynametypo@myownsite.com?)

SELECT forward_address FROM forward_address_table WHERE email = $email

If you really need to deal with the mail server then I expect your questions would be more specific. You are registering the user, you store his email address, you can forward it to wherever you want.

<?cp <— that is a custom cpanel hook? as it can only be run in the cpanel environment?

This question is much like many other questions, which, as a fact, does have no relation to PHP.
The PHP part is very simple. As little as 2 functions, system() or fopen().

But at first you ought to know, what exactly you want to do, what action to take! To write to a file, or to a database, or to call some utility. This is merely mailserver related question, not PHP

Yeah, I ahve logged a support question to see if they have some sort of API to hook into.

Thanks Again

K