0

all the emails are sending together to all the recipients showing their emails in "TO", which i don't want.
how to send mails individually instead of sending to all recipients together?
my code is:

function SendMail($msg,$subject,$addresses)
    {
    require "class.phpmailer.php";
    //Fetch from email here
    foreach($addresses as $key=>$val){
             $email = test_input($val);
            if((trim($email)=='') || (!filter_var($email, FILTER_VALIDATE_EMAIL))){
                unset($addresses[$key]);
            }
        }
        $addresses=array_unique($addresses);
    $row = FetchAllsettingsCustomMailchmp();
    //end fetch
    $mail = new PHPMailer();
    $mail->PluginDir = "";
    $mail->Host = "localhost";
    $mail->From = $row['email_from'];
    $mail->FromName = $row['sitename'];
    $mail->Subject =  $subject;
    foreach ($addresses as $address)
        $mail->AddAddress($address);
    $mail->MsgHTML($msg);
    $mail->IsHTML(true);
    $mail->AltBody ="Order";
    $mail->CharSet = 'UTF-8';
    $success = $mail->Send();
    $try = 1;

    while((!$success)&&($try<1)&&($mail->ErrorInfo!="SMTP Error: Data not accepted"))
        {
        sleep(5);
        $success = $mail->Send();
        $try++;
        }

    $mail->ClearAddresses();
    if(!$success)
        return false;
        else
        return true;
    }

function test_input($data) {
   $data = trim($data);
   $data = stripslashes($data);
   $data = htmlspecialchars($data);
   return $data;
}
3
Contributors
3
Replies
16
Views
2 Years
Discussion Span
Last Post by davidbcn
1

Hi,
You just need to loop through every email and send it.
Try executing below code and confirm.

function SendMail($msg,$subject,$addresses)
    {
    require "class.phpmailer.php";
    //Fetch from email here
    foreach($addresses as $key=>$val){
             $email = test_input($val);
            if((trim($email)=='') || (!filter_var($email, FILTER_VALIDATE_EMAIL))){
                unset($addresses[$key]);
            }
        }
        $addresses=array_unique($addresses);
    $row = FetchAllsettingsCustomMailchmp();
    //end fetch
    $mail = new PHPMailer();
    $mail->PluginDir = "";
    $mail->Host = "localhost";
    $mail->From = $row['email_from'];
    $mail->FromName = $row['sitename'];
    $mail->Subject =  $subject;
    foreach ($addresses as $address) {
        $mail->AddAddress($address);
    $mail->MsgHTML($msg);
    $mail->IsHTML(true);
    $mail->AltBody ="Order";
    $mail->CharSet = 'UTF-8';
    $success = $mail->Send();
    $try = 1;
    while((!$success)&&($try<1)&&($mail->ErrorInfo!="SMTP Error: Data not accepted"))
        {
        sleep(5);
        $success = $mail->Send();
        $try++;
        }
    $mail->ClearAddresses();
    }
    if(!$success)
        return false;
        else
        return true;
    }
function test_input($data) {
   $data = trim($data);
   $data = stripslashes($data);
   $data = htmlspecialchars($data);
   return $data;
}
Votes + Comments
Thanks, it worked!!!
1

The above works, but it may get you blocked as a spam sender.

Why can't you just add all your recipients as BCC, and send it to yourself?

I see MailChimp mentioned in your of your functions. Why not use that to send your e-mails instead?

Edited by pritaeas

0

pritaeas, i don't want to use BCC.

Edited by davidbcn

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.