Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

fortytwoeleven

macrumors newbie
Original poster
Aug 24, 2012
20
1
Hi,
Hope this is in the right section.. I thought I would ask here because I can't regt much of a response from other forums.

I'm looking for a way that I can send an email to a default address. and once that adress receives the email it triggers it to mail it out to a mailing list of emails.

Is there something out there already like this?
Also I am hoping to do it so the mailing list is 0 maintenance, such as it pulls the email addresses from WHM / Cpanel / WHMCS do I don't have to keep adding and removing emails.

Any advice would be great! thank you :)
 

SrWebDeveloper

macrumors 68000
Dec 7, 2007
1,871
3
Alexandria, VA, USA
Hi,
Hope this is in the right section.. I thought I would ask here because I can't regt much of a response from other forums.

I'm looking for a way that I can send an email to a default address. and once that adress receives the email it triggers it to mail it out to a mailing list of emails.

Is there something out there already like this?
Also I am hoping to do it so the mailing list is 0 maintenance, such as it pulls the email addresses from WHM / Cpanel / WHMCS do I don't have to keep adding and removing emails.

Any advice would be great! thank you :)

For the pre-built solution via cPanel: http://docs.cpanel.net/twiki/bin/view/AllDocumentation/CpanelDocs/MailingLists

If you wish to customize your own solution (i.e. DIY from scratch, no cPanel dependencies):

This is a web development forum so the responses here might be skewed towards LAMP based solutions, i.e. PHP scripts. My response is that way and focuses on cPanel which is very common.

1) Setup an email account with forwarding in cPanel
2) In the forwarding pipe it to a custom PHP script, i.e.

|php -q -n /PATH/TO/SCRIPT/parse.php

3) For parse.php:

Make sure the very first line is:

PHP:
#!/usr/local/bin/php

Adjust path to your PHP, if not sure type in "which php" via shell, or check output of phpinfo() in a test script on that server to get PHP information.

Chmod 755 (make sure script is executable permissions wise)

Note that the script, invoked this way, reads email from STDIN. You *must* read in the email contents to avoid bounce back, but since you're using the email content for your mailing list, that works out just fine.

Below is an example script to do just that, edit to suit your needs, don't just copy and paste as this is to demonstrate the concept, of course:

PHP:
function mailRead($i_klimit = "") 
{ 
  // Reads piped mail from STDIN 
  // Optional $i_klimit specifies after how many kilobytes the reading should stop 
  // Default is 1024k. This is very generous for plain or formatted text. 
  // Set to -1 for unlimited (i.e. read entire email) 
  // This will prevent the script running into "out of memory" errors when dealing with large mails. 

  if ($i_klimit == "") { 
    $i_klimit = 1024; 
  } 
         
  $fp = fopen("php://stdin", "r"); 
  $email = ""; 
         
  if ($i_klimit == -1) { 
    while (!feof($fp)) { 
      $email .= fread($fp, 1024); 
    }                     
  } else { 
    while (!feof($fp) && $i_limit < $i_klimit) { 
      $email .= fread($fp, 1024); 
      $i_limit++; 
    }         
  } 
         
  fclose($fp); 
         
  return $email; 
}  

/* Begin parsing the content of the email */

$myemail=mailRead(-1);

/* 

At this point either invoke your external mailer script if you got one which
delivers this email to a list via exec() or system() or add your own PHP code 
here which  does whatever you want, noting $myemail contains the content.
For example I might create a list of addresses in a MySQL database
and process each one here. 

*/

That's the procedure, the rest is up to you of course.
 
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.