0

I have function in my php code:

foreach ($myarray as $customer) {
     //doing some code
     $this->sendMail($this->attachedfiles,$customer);
}

$this->response($this->success);

This code loop over array and the send email to each one with attachedfiles and response to the client in the end.

the problem with this is that it take a lot of time. so i tried some thing like this:

$customer_email = array();
$customer_attachedfiles = array();

foreach ($myarray as $customer) {
     array_push($customer_email, $customer);
     array_push($customer_attachedfiles, $this->attachedfiles);
}

$this->response($this->success);

$indextmp = 0; 
foreach ($customer_email as $customer2) {
     $attachedfiles_tmp = $customer_attachedfiles($indextmp);
     $this->sendMail($attachedfiles_tmp,$customer2);
     $indextmp++;
}

And in this format the mail are not sent, Any idea what can be the problem?

1
  • 2
    nonetheless, sending emails takes time since your message, of certain size + attachments need to be transported over the network. You could simply send links to attachments instead of sending the attachments into email, this way will be def. faster. Also, if your customers base is large, consider background jobs and queues. Commented Aug 4, 2014 at 19:51

1 Answer 1

1

You can use Swift Mailer or PHPMailer. With this libraries you can easily send mails to many e-mails with one action. http://swiftmailer.org/docs/introduction.html

Sign up to request clarification or add additional context in comments.

2 Comments

the sendMail use PHPMailer
with PHPMailer you can add many recipients, like this: $mail->addAddress('[email protected]'); $mail->addAddress('[email protected]'); etc...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.