简体   繁体   中英

Sending many dynamically-generated emails with php

I have a script: invoice.php?id=12 that generates an invoice in pdf and emails it to a customer with id = $_GET['id'] .

Now, after sales are closed, Id like to send an email to all customers at once and I have no idea how to do that.

Generating one pdf and sending it by email takes about 3-4 seconds and there will be hundreds or even thousands of customers.

I'm using SwiftMailer PHP library, if that's relevant.

Any idea how I could do it? Is there a way to loop through ajax requests for several hours? Or is there a simpler solution?

Thanks!

If I understand your question correctly, you are initiating an AJAX request for every email you would like to send. It would be a lot more efficient to send 1 email addressed to a lot of people, by specifying multiple receivers in the mail header as follows:

$email_to = "first@email.com,some@other.com,yet@another.net";

For SwiftMailer try this:

$message = Swift_Message::newInstance('Wonderful Subject')
    ->setFrom(array('your@mail.com' => 'John Doe'))
    ->setTo(array('receiver@domain.org', 'other@domain.org' => 'Name'))
    ->setBody('Here is the message itself')
;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM