Question

I am looking to create one email (example@domain.com) to forward to all email addresses in a database.

People can email to example@domain.com, and then that email would get blasted to a list of predefined email addresses. It would need to include support for attachments.

I realize this is not secure at all and leaves this email address open to anybody to use, but this is what our organization wishes to do.

What would be the best way to do this on a PHP server?

Thanks.

Was it helpful?

Solution 5

While Arthur's answer made sense and most likely would work, I ended up finding that my host had the feature I was looking for buried deep inside it. For those who were wondering, it is called discussion lists.

OTHER TIPS

This can be achieved in PHP Server as you have to go in depth of following things:

  • Email Piping

  • Email Headers

  • MIME Email attachments

  • Mailing List Management

While emailing to a lot of people in the way you mentioned is not a good idea...

You can use PHP's "mail" function:

$to      = "user1@domain.com, user2@domain.com"; //(Comma separated list of emails)
$from    = "noreply@domain.com";
$subject = "Hello";
$message = "Hello there!";

$headers = "From: ".    $from . "\r\n".
           "Reply-To: ".$from . "\r\n";
//send it
mail($to, $subject, $message, $headers);
while($row = mysql_fetch_array($emails))
{
    $addresses[] = $row['address'];
}
$to = implode(", ", $addresses);

And then send mail using mail function ... mail($to, $subject, $message, $headers);

The way you have worded your query is a bit confusing but it seems you have a hosting server that is going to receive emails to a domain email. You then want to have those emails autoforwarded to a list of recipients. It looks like you want to investigate (given you mention sendmail) linux mail services and autoforwarding. You may be looking at postfix and possibly using procmailrc to trap and redirect incoming mail on your server.

I have done this with procmailrc before but it really depends on what service is handling the incoming mail.

There is no problem calling a CLI PHP script as suggested by @George to then read your recipients from the database and do the sending.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top