Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending Mail To A Large Number of People

Tags:

php

phpmailer

I have read lots of questions and answers about this issue on StackOverflow, but none of the ones I've read answered my question specifically.

I do not want to have a mailing list. People tick a box if they want to receive the bulk email. There are no wrong emails because accounts are activated using emails. So no bounce checking. However, I already use PHPMailer (so no issues with headers and such) and add every address to the 'to' field of the email. This means everyone can view all the emails (by reading the email source or hitting "reply to all" in their email client), which will not be desirable by other users. The question is:

1) should I send each email individually, or put all addresses in the 'bcc' field? 2) Won't this make some mailservers mark the email as "spam", no matter how well-structured it is? If so, is there a way to further prevent this (apart from adding the address to some whitelists or setting up domain keys or Unix cron jobs)?

Thanks!

All of the things mentioned here require the user to "subscribe" using a form, and then confirm their email address (like in PHPList). However, I already ask for confirmation when people register, so no sense in asking them again and again. My existing code checks the database; if their "receive-movie-mail" bit is set to 1 (these are gathered using an sql query), an email is sent to them when a new movie is added to the database. So, if you still believe this to be a mailing list (which I think it kind of is, but maybe my definition defies existing software features), I'd like it to have, 1) some way of subscribing users to the list with PHP code (E.G. if the "I want to receive an email every time a movie is uploaded to the database" checkbox is checked, in my form processing code I'll subscribe them), and 2) a way to mail people with PHP (I.E. a function like send_mail_to_list($content) that sends the email to the people I have subscribed, when the "Add Movie" form is submitted). Is there such a mailing list management software?

like image 562
Parham Doustdar Avatar asked Aug 12 '11 20:08

Parham Doustdar


2 Answers

You should loop over the list of emails and send an individual email for each address:

$mail = new PHPMailer();
$mail->IsSMTP();           // set mailer to use SMTP
$mail->Host = "mail.{domain_name}.com";    // specify main and backup server
$mail->SMTPAuth = true;           // turn on SMTP authentication
$mail->Username = "{username}";   // SMTP username
$mail->Password = "{password}";      // SMTP password

$emailFrom  = '{email_address}';

$mail->From = $emailFrom;
$mail->IsHTML(true);    // set email format to HTML if needed

$emailSubject = '{your subject}';
$emailBody  = "Whatever content you are sending.";

$mail->Subject = $emailSubject;
$mail->Body    = $emailBody;

foreach($emails => $email) {

    $emailTo = $email['email'];
    $emailToName = $email['name'];

// send an email to customer
    $mail->AddAddress($emailTo, $emailToName);

    if(!$mail->Send())
    {
        echo 'failed';
    }

    $mail->ClearAddresses();
}
like image 87
Adam Culp Avatar answered Oct 23 '22 09:10

Adam Culp


1) should I send each email individually, or put all addresses in the 'bcc' field?

Definitely Individually. Bcc will have your email seen as spam.

2) Won't this make some mailservers mark the email as "spam", no matter how well-structured it is? If so, is there a way to further prevent this (apart from adding the address to some whitelists or setting up domain keys or Unix cron jobs)?

using an SPF record might help. Make sure the reverse-dns to your server is not blacklisted, especially if it's a shared hosting.

like image 38
pixeline Avatar answered Oct 23 '22 10:10

pixeline