Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ######### ROUGH STEPS TO PIPING INCOMING MAIL TO PHP SCRIPT #############
- os : centos 6.6 (/w zpanel)
- stmpd : postfix
- # add forward/virtual alias to zpanel_postfix alias table
- [ address ] [ goto ]
- root@mydomain.com php_recv_mail@localhost, root@mydomain.com
- # vi /etc/virtual_redirect
- root@mydomain.com php_recv_mail@localhost
- Rebuild the virtual alias db with postmap
- postmap /etc/virtual_redirect
- # vi /etc/postfix/main.cf
- virtual_alias_maps = blah blah, hash:/etc/virtual_redirect
- virtual_alias_domains = mydomain.com
- # vi /etc/aliases
- php_recv_mail: "|/usr/bin/php -q /etc/postfix/recv_mail.php"
- /********************************************************
- needed to use /etc/postfix directory ... even setting same exact owner/perms as /etc/postfix to my public_html files/dirs didn't work...still need to fix
- don't have the time now
- ********************************************************/
- chmod 755 /etc/postfix/recv_mail.php
- chmod 755 /etc/postfix/co2.php (db conn)
- chmod 777 /etc/postfix/
- newaliases
- postfix reload
- service postfix restart
- # MAKE SURE OPENDMARC DOESN'T BITCH ABOUT INGORING LOCALHOST CONNECTIONS
- vi /etc/opendmarc.conf
- uncomment
- IgnoreHosts /etc/opendmarc/ignore.hosts
- and create and empty ignore.hosts file (If not specified, defaults to "127.0.0.1" only.)
- # vi /etc/opendmarc/ignore.hosts
- # RESTART OPENDMARC
- # service opendmarc restart
- if it fails
- # ps aux | grep opendmarc
- # kill -9 pid
- # service opendmarc start
- ######### send a test email ################
- check for errors
- cat /var/log/maillog | grep localhost
- // success
- postfix/local[5810]: 2A39B40B6B: to=<php_recv_mail@localhost.mydomain.com>, orig_to=<root@mydomain.com>, relay=local, delay=1.1, delays=0.82/0.01/0/0.25, dsn=2.0.0, status=sent (delivered to command: /usr/bin/php -q /etc/postfix/recv_mail.php)
- // messed up (perm errors i still need to fix)
- postfix/local[32184]: 7EEDF40BDB: to=<php_recv_mail@localhost.mydomain.com>, orig_to=<root@mydomain.com>, relay=local, delay=0.36, delays=0.32/0.01/0/0.03, dsn=4.3.0, status=SOFTBOUNCE (Command died with status 1: "/usr/bin/php -q /var/zpanel/hostdata/zadmin/public_html/mydomain_com/pipe/recv_mail.php". Command output: Could not open input file: /var/zpanel/hostdata/zadmin/public_html/mydomain_com/pipe/recv_mail.php
- ######### recv_mail.php ################
- #!/usr/bin/php
- <?php
- // fetch data from stdin
- $incoming_mail = file_get_contents("php://stdin");
- require_once('/etc/postfix/co2.php');
- //$incoming_mail = trim(fgets(STDIN));
- /*
- $fd = fopen("php://stdin", "r");
- $incoming_mail = "";
- while (!feof($fd)) {
- $incoming_mail .= fread($fd, 1024);
- }
- fclose($fd);
- */
- $send_domain = "mydomain.com";
- $myFile = "/etc/postfix/incoming_mails.txt";
- $fh = fopen($myFile, 'a') or die("can't open file");
- fwrite($fh, $incoming_mail."\r\n\r\n\r\n");
- fclose($fh);
- if(preg_match_all('/(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))+/i', $incoming_mail, $matches)) {
- for($z = 0; $z < count($matches[0]); $z++) {
- echo "[".$z."] : ".$matches[0][$z]."\r\n";
- $email = trim($matches[0][$z]);
- if(stripos($email, $send_domain) !== false) {
- continue;
- }
- $result = mysql_query("SELECT emails.id FROM `emails` WHERE emails.email='$email' ORDER BY emails.id ASC");
- $num = mysql_num_rows($result);
- if($num > 0) {
- while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
- $id = $row['id'];
- $result2 = mysql_query("UPDATE emails SET emails.isvalid='3' WHERE emails.id='$id'");
- }
- }
- }
- }
- mysql_close();
- exit();
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement