I have a local development server (centos) which I develop a number of websites on. Occasionally I need to test email sending scripts.
I want to avoid the development server from sending emails to anyone who doesn't have an email address with a particular domain (ie: [email protected], [email protected], etc). So, I would like to create a white list or rule on the server which prevents emails being sent to any email address that doesn't match mydomain.com.
I'm currently using PHP's built-in mail() function. But I imagine this is something more on the server level and I would like something that will manage ANY emails sent out from the server from any program/app/script/etc.
I can confirm that PHP is using /usr/sbin/sendmail.sendmail
here is how I managed to do it. In Sendmail, you need to modify the mailertable. Add the following:
This will essentially send any emails to @alloweddomainname.com and error for anything else.
PHP
mail()
function sends messages according to MTA set assendmail_path
value inphp.ini
, by default, it's set to following:on some systems it's a symlink to the binary of MTA, in my case it's sendmail-compatible binary of postfix MTA package, in other case it might be sendmail or qmail or whatever you use:
So, according to this you can:
A. change
sendmail_path
to your custom script, write parser and filter messages accordingly. This will affect only outgoing messages sent via PHPmail()
wheresendmail_path
was changed.B. change configuration of mail server - this will affect all messages sent via MTA of your server, to do this you must check what is your server and configure it accordingly
In case of postfix:
add following to the /etc/postfix/main.cf:
transport_maps = hash:/etc/postfix/transport_maps
create file
/etc/postfix/transport_maps
with following content:hash: run
postmap /etc/postfix/transport_maps
restart postfix